- 10,832
Does anyone here know Java?
I'm writing a simple Java program for a class. It's a mortgage calculator. The program takes two pieces of input from the user: the monthly payment and the mortage balance. The interest rate is a constant set to 7.49. The program is supposed to output the amount of the payment that goes to interest and the amount that goes to principal (actual debt). This seems easy enough. But I can't seem to figure out why the program needs the loan balance. It is not necessary to to calculate the output, I think. If it were, it seems to me the program would have to be more complicated and include at least one function. I know this is not the case, though, because we haven't even started functions yet. So I did the program and it works okay, but I can't help thinking that there must be a reason why it asks for the loan balance. Can anyone think of a way to use it in this program?
/**
This program calculates the principal
and interest paid on a mortgage based
on the term and balance input by the
user.
*/
public class assignment03
{
//Sets constant value for INTEREST
public static final double INTEREST = 7.49/100;
public static void main(String[] args)
{
//variable declaration
double interest = 0, principal = 0, interestPaid = 0,
monthlyPayment = 0, balance = 0;
//User input here
System.out.println ("Please enter your monthly payment.");
monthlyPayment = SavitchIn.readLineInt();
System.out.println ("Please enter you loan balance.");
balance = SavitchIn.readLineInt();
/**calculates interest and principal based on user input
stored in vaiables*/
interestPaid = monthlyPayment * INTEREST;
principal = monthlyPayment - interestPaid;
//outputs principal and interest paid
System.out.println ("The amount of your payment that goes ");
System.out.println ("toward principal is " + principal);
System.out.println ("The amount of your payment that goes ");
System.out.println ("toward interest is " + interestPaid);
//keeps program open
System.out.println("Press enter key to end program.");
String junk;
junk = SavitchIn.readLine();
}
}
I'm writing a simple Java program for a class. It's a mortgage calculator. The program takes two pieces of input from the user: the monthly payment and the mortage balance. The interest rate is a constant set to 7.49. The program is supposed to output the amount of the payment that goes to interest and the amount that goes to principal (actual debt). This seems easy enough. But I can't seem to figure out why the program needs the loan balance. It is not necessary to to calculate the output, I think. If it were, it seems to me the program would have to be more complicated and include at least one function. I know this is not the case, though, because we haven't even started functions yet. So I did the program and it works okay, but I can't help thinking that there must be a reason why it asks for the loan balance. Can anyone think of a way to use it in this program?
/**
This program calculates the principal
and interest paid on a mortgage based
on the term and balance input by the
user.
*/
public class assignment03
{
//Sets constant value for INTEREST
public static final double INTEREST = 7.49/100;
public static void main(String[] args)
{
//variable declaration
double interest = 0, principal = 0, interestPaid = 0,
monthlyPayment = 0, balance = 0;
//User input here
System.out.println ("Please enter your monthly payment.");
monthlyPayment = SavitchIn.readLineInt();
System.out.println ("Please enter you loan balance.");
balance = SavitchIn.readLineInt();
/**calculates interest and principal based on user input
stored in vaiables*/
interestPaid = monthlyPayment * INTEREST;
principal = monthlyPayment - interestPaid;
//outputs principal and interest paid
System.out.println ("The amount of your payment that goes ");
System.out.println ("toward principal is " + principal);
System.out.println ("The amount of your payment that goes ");
System.out.println ("toward interest is " + interestPaid);
//keeps program open
System.out.println("Press enter key to end program.");
String junk;
junk = SavitchIn.readLine();
}
}