Guidelines
This assignment is comprised of modifying your program which will calculate a monthly a moritzed amount (e.g. a house mortgage). For this program, you are to add the logic to prompt the user if they wish to enter the data again, then loop if they enter a "y" value; otherwise perform the calculations and the error checking as in the previous program.
Enter loan amount: 100000
Enter rate: 6
Enter number years: 30
The monthly payment is: $599.55
Would you like to calculate again (y/n): y
Enter loan amount: -100000
Enter rate: 6
Enter number years: 30
You must enter positive numeric data!
Would you like to calculate again (y/n): n
__________________________________________________ __________________
package monthypayment2; import java.text.NumberFormat; import java.util.Scanner; public class Monthypayment2 { private static double monthlypay1; private static String choice; private static boolean n; private static String False; private static boolean y; /** * @param args the command line arguments */ public static void main(String[] args) { Scanner in = new Scanner(System.in); //format number and currency NumberFormat NF = NumberFormat.getCurrencyInstance(); NumberFormat NI = NumberFormat.getNumberInstance(); double months = 1; double numyears; double loanamount; double rate; int repeat = 0; //condition for loop do { //prompt loan amount System.out.print("Enter Loan Amount:"); loanamount = in.nextDouble(); //prompt rate System.out.print("Enter Rate:"); rate = in.nextDouble(); //prompt years System.out.print("Enter Number of Years:"); numyears = in.nextDouble(); //calculation monthly monthlypay1 = (loanamount * rate / 12) / (Math.pow(1 + rate, months)) / (Math.pow(1 + rate, months)-1); System.out.println("The Monthly Payment is: $" + monthlypay1); y = true; n = false; if (monthlypay1 < 0) { System.out.print("You need to enter positive numerical data!");} else { System.out.print("Would you like to continue calculations(y/n)?"); choice = in.nextLine(); } } while (choice.equals("y")); while(choice.equals("n")) { break; } } }
Basically when I run the program the Math is still off despite me getting help and doing all suggestions that users gave me on here. I compared it with the formula and it's correct.
When i put in a negative loan amount i get this error
"Exception in thread "main" java.lang.NullPointerException"
at line 65(which would beafter asking if I would like to calculate again.while (choice.equals("y"));
I've restarted a couple times on the project but I keep running into the same problems.
Can anyone help me?
https://scontent-b-iad.xx.fbcdn.net/...95&oe=526636AF <--- formula that I am using.