Please help,Im confused. Thanks so much! Call two methods to perform the followi
ID: 3562632 • Letter: P
Question
Please help,Im confused. Thanks so much!
Call two methods to perform the following two jobs, respectively:
You will need to use Scanner to obtain input from the keyboard. You should declare a class constant of type Scanner named CONSOLE at the beginning of your class. You should store new Scanner(System.in) in CONSOLE.
When you take out a loan, you are charged interest monthly based on an annual interest rate. If the annual rate is r, the monthly rate is r/12. The annual rate is usually represented as a fraction, a number between 0 and 1, but the interest rate will be entered as a percentage. If the interest rate is 15%, 15 will be entered, and the rate will be 15/100 = .15.
If the balance at the beginning of the month is b, the balance at the end of the month before a payment is made is b + b*r/12. After the payment is made, the balance is reduced by the payment.
Use the double data type for the balance, interest rate, and monthly payment. Use CONSOLE.nextDouble() to read these in. Use the int data type for the number of months and read it in using CONSOLE.nextInt().
Explanation / Answer
import java.util.Scanner;
public class LoadPayment
{
static final Scanner CONSOLE = new Scanner(System.in);
public static void main(String[] args)
{
payment1();
System.out.println();
payment2();
}
public static void payment1()
{
System.out.println("First payment method.");
System.out.print("Enter the annual interest rate(percent): ");
double rate = CONSOLE.nextDouble();
double mrate = (rate / 100) / 12; // month rate
double balance = 1000;
System.out.println("Month No Remaining Balance");
for (int i = 1; i <= 12; i++)
{
System.out.printf("%4d", i);
balance = balance + balance * mrate - 50;
System.out.printf("%20.2f ", balance);
}
}
public static void payment2()
{
System.out.println("Second payment method.");
System.out.print("Enter the initial loan balance: ");
double balance = CONSOLE.nextDouble();
System.out.print("Enter the monthly payment: ");
double payment = CONSOLE.nextDouble();
System.out.print("Enter the annual interest rate(percent): ");
double rate = CONSOLE.nextDouble();
System.out.print("Enter the number of months: ");
int months = CONSOLE.nextInt();
double mrate = (rate / 100) / 12; // month rate
System.out.println("Month No Balance Monthly Payment Remaining Balance");
for (int i = 1; i <= months; i++)
{
System.out.printf("%4d", i);
balance = balance + balance * mrate;
System.out.printf("%15.2f", balance);
System.out.printf("%14.2f", payment);
balance = balance - payment;
System.out.printf("%20.2f ", balance);
}
}
}