Java loop to the beginning isse

ok, The program runs fine now, but I can't get the program to loop back to the beginning if the person enters 'y'. What am I missing?


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tryingagain;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


//Author 

import java.io.*;
import java.text.*;



public class Main {
  public static void main(String[] args) throws IOException {


   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

   String [] fname = new String[30];
   String [] lname = new String[30];
   double [] loanAmount = new double[30];
   double [] rateYears = new double[30];
   int [] termYears = new int[30];
   boolean yes = true;

      int count =0;

    System.out.println("\t\t\tWelcome to yet another Mortgage Calculator\n");
     
        System.out.println("\tPlease enter your first name:");
        String fname1  = in.readLine();
        while (fname1.equals(""))
        {
            System.out.println("\tName error! Please enter your first name: ");
            fname1 = in.readLine();
        }
              fname[count] = fname1; //into the array it goes
      

        System.out.println("\tPlease enter your last name:");
       String lname1 = in.readLine();
       while (lname1.equals(""))
       {
           System.out.println("\tName error! Please enter your last name: ");
           lname1 = in.readLine();
       }

            lname[count] = lname1; //into the array

    System.out.print("\tPlease enter the loan Amount: $");  //asks for loan amount
    String input = in.readLine(); //user input

    double loanAmount1 = Double.parseDouble(input);

    while (loanAmount1 <=0){
            System.out.println("Invalid Number, please enter the loan Amount: ");
                         }
      loanAmount[count]=loanAmount1; //into the array it goes

    System.out.print( //asks for interest rate
        "\tPlease enter the interest rate:  ");
    String inputa = in.readLine();
    double rateYears1 = Double.parseDouble(inputa);
 while (rateYears1 <=0){
            System.out.println("Invalid Number, please enter the interest rate: ");
 }

  rateYears[count]=rateYears1;

    System.out.print(
        "\tPlease enter the length of mortgage years ");
    String inputb = in.readLine();

   
    int termYears1 = Integer.parseInt(inputb);

   termYears[count]=termYears1; //into the array it goes


    DecimalFormat precision2p = new DecimalFormat("$###,###.00");

    double rateMonthly = (rateYears1 / 12) / 100; // monthly calculation & interest rate
    double termMonths = (termYears1 * 12);        // monthly calculation & interest rate

    //monthlyPayment calculation continued
    double monthlyPayment = (loanAmount1 * rateMonthly) /
        (1 - Math.pow(1 + rateMonthly, -termMonths));


    System.out.println("\tThe mortgage payment will be: " +
                       precision2p.format(monthlyPayment));

 {
System.out.print("Would you want to enter another person? (y/n): ");
String inputc = in.readLine();
yes = inputc.equalsIgnoreCase("y");

      }

            

      

      }
    }

Open in new window

marchbabyAsked:
Who is Participating?
 
CEHJCommented:
You need to loop the whole program more orless:
import java.io.*;

import java.text.*;


public class main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String[] fname = new String[30];
        String[] lname = new String[30];
        double[] loanAmount = new double[30];
        double[] rateYears = new double[30];
        int[] termYears = new int[30];
        boolean yes = true;

        int count = 0;

        System.out.println("\t\t\tWelcome to yet another Mortgage Calculator\n");

        while (yes) {
            System.out.println("\tPlease enter your first name:");

            String fname1 = in.readLine();

            while (fname1.equals("")) {
                System.out.println(
                    "\tName error! Please enter your first name: ");
                fname1 = in.readLine();
            }

            fname[count] = fname1; //into the array it goes

            System.out.println("\tPlease enter your last name:");

            String lname1 = in.readLine();

            while (lname1.equals("")) {
                System.out.println(
                    "\tName error! Please enter your last name: ");
                lname1 = in.readLine();
            }

            lname[count] = lname1; //into the array

            System.out.print("\tPlease enter the loan Amount: $"); //asks for loan amount

            String input = in.readLine(); //user input

            double loanAmount1 = Double.parseDouble(input);

            while (loanAmount1 <= 0) {
                System.out.println(
                    "Invalid Number, please enter the loan Amount: ");
            }

            loanAmount[count] = loanAmount1; //into the array it goes

            System.out.print( //asks for interest rate
                "\tPlease enter the interest rate:  ");

            String inputa = in.readLine();
            double rateYears1 = Double.parseDouble(inputa);

            while (rateYears1 <= 0) {
                System.out.println(
                    "Invalid Number, please enter the interest rate: ");
            }

            rateYears[count] = rateYears1;

            System.out.print("\tPlease enter the length of mortgage years ");

            String inputb = in.readLine();

            int termYears1 = Integer.parseInt(inputb);

            termYears[count] = termYears1; //into the array it goes

            DecimalFormat precision2p = new DecimalFormat("$###,###.00");

            double rateMonthly = (rateYears1 / 12) / 100; // monthly calculation & interest rate
            double termMonths = (termYears1 * 12); // monthly calculation & interest rate

            //monthlyPayment calculation continued
            double monthlyPayment = (loanAmount1 * rateMonthly) / (1 -
                Math.pow(1 + rateMonthly, -termMonths));

            System.out.println("\tThe mortgage payment will be: " +
                precision2p.format(monthlyPayment));

            {
                System.out.print(
                    "Would you want to enter another person? (y/n): ");

                String inputc = in.readLine();
                yes = inputc.equalsIgnoreCase("y");
            }
        }
    }
}

Open in new window

0
 
CEHJCommented:
Sorry - class should be 'Main' not 'main'
0
 
marchbabyAuthor Commented:
Thank you so much!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.