Вы находитесь на странице: 1из 2

1.

For each of the following, decide whether a void method or a nonvoid method is the most
appropriate implementation.

Computing a sales commission, given the sales amount and the commission rate
Printing the calendar for a month
Computing a square root
Testing whether a number is even, and returning true if it is
Printing a message a specified number of times
Computing the monthly payment, given the loan amount, number of years and annual interest rate

2. What is the result of the following method call:


public class Main
{
public static void main(String[] args)
{
int max = 0;
max(1, 2, max);
System.out.println(max);
}
public static void max(int value1, int value2, int max)
{
if(value1 > value 2)
{
max = value1;
}
else
{
max = value2;
}
}
}

3. What is the result of the following method call:


public class Main
{
public static void main(String[] args)
{
int max = max(1, 2);
System.out.println(max);
}
public static int max(int value1, int value2)
{
int max = 0;
if(value1 > value2)
{
max = value1;
}
else
{
max = value2;
}
return max;
}
}
4. Write a method that converts Celsius to Fahrenheit using the following declaration
public static double celsToFahr(double cels)

The formula for the conversion is as follows:


Fahrenheit = (9.0/5) * Celsius + 32;

Write a program that use a for loop and calls the celsToFahr method in order to produce the
following output:

Cels. Temp Fahr. Temp


40 104.0
39 102.2
38 100.40
… …
33 91.40
32 89.60
31 87.80

5. Rewrite the Mortgage project, create a method named calculateMonthlyPayment(), given the loan
amount, number of years and annual interest rate, then return the monthly payment. Call
calcualteMonthlyPayment() in your main() method.

The signature of your method should be the following:


public static double calculateMonthlyPayment(double loanAmout, double
annualInterestRate, int years)

6. Rewrite MortgageTable project to let the user enter the loan amount and loan period in number of
years and display the monthly and total payments for each interest rate starting from 5% to 8%, with an
increment of 1/8. Suppose you enter the loan amount 10000 for 5 years, display the table as follows:

Loan Amount: 10000


Number of Years: 5
Interest Rate Monthly Payment Total Payment
5% 188.71 11322.74
5.125% 189.28 11357.13
5.25% 189.85 11391.59

7.75% 201.56 12094.17
7.875% 202.16 12129.97
8.0% 202.76 12165.83

Please write 2 methods with the following signatures


public static double calculateMonthlyPayment(double loanAmout, double
annualInterestRate, int years)
public static double calculateTotalPayment(double monthlyPayment, int years)

Вам также может понравиться