Hi I need help with the while loop and read from a file to find monthly mortgage payment from the input of Principle, Interest & Term in years. I know I may did something that doesn't make sense here, please take a look and let me know. Thank you in advance. Below is the errors I got when Run it in jgrasp. Tracy
import java.text.*; // format output
import java.util.*; // Scanner class
import java.io.*; // Needed for file classes
public class MortgageLoopC
{
public static void main(String[] args)throws IOException
{
DecimalFormat num=new DecimalFormat("$,###.00"); // Create format for name num
DecimalFormat interest=new DecimalFormat("%,##.00"); // Create format for name interest
// variable names of Mortgage Principle, Interest, Monthly Payment & Term.
double P, // Mortgage Principle
I, // Mortgage Interest
T, // Mortgage Term
MP; // Monthly Mortgage Payment
String holdInput, //to hold user input.
mortgageC, // File name
str; // string file to be read
char repeat; // to 'Y' or 'N'.
// Initialize Scanner to read from DOS window.
Scanner input = new Scanner(System.in);
// Get the file name
System.out.print("Enter the file name: ");
mortgageC=input.nextLine();
// Open the file
FileReader freader=new FileReader("promptC.txt");
BufferedReader inputFile=new BufferedReader(freader);
// Get as many different mortgage payments as user wants
do
{
// Read the first line from the file
//"Calculates the monthly mortgage payment from your input data"
str=inputFile.readLine();
// Read the remaining prompts
while(str!=null)
{
// Display the next prompt
//"Enter the mortgage Principle"
system.out.println(str);
P=input.nextDouble();
// Read the next prompt
str=inputFile.readLine();
}
while(str!=null)
{
// Display the next prompt
//"Enter the mortgage Interest"
system.out.println(str);
I=input.nextDouble();
I = I/100; // format for user type in common bank rate.
// Read the next prompt
str=inputFile.readLine();
}
while(str!=null)
{
// Display the next prompt
//"Enter the mortgage Term in year"
system.out.println(str);
T=input.nextDouble();
// Read the next prompt
str=inputFile.readLine();
}
// Compute the monthly mortgage payment MP.
MP = (P*(I/12))/(1-Math.pow((1/(1+(I/12))),(T*12)));
// Display the monthly mortgage payment on the DOS window.
System.out.println("Monthly Mortgage Payment of "+P+" for "+T+" years at "+interest.format(I)+" is: "+num.format(MP));
System.out.println(); //Prints a blank line.
// Does the user want to input a different data set?
System.out.println("Would you like to calculate"+"another set of Monthly Mortgage?");
System.out.print("Enter Y for Yes or N for No: ");
str=input.next(); // Read next char
repeat=str.charAt(0); // Get the first char.
} while (repeat=='Y' || repeat=='y');
}
}
MortgageLoopC.java:60: package system does not exist
system.out.println(str);
^
MortgageLoopC.java:71: package system does not exist
system.out.println(str);
^
MortgageLoopC.java:83: package system does not exist
system.out.println(str);
^
3 errors