We help IT Professionals succeed at work.

Java loop to the beginning isse

marchbaby
marchbaby asked
on
Medium Priority
236 Views
Last Modified: 2012-05-11
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

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
Sorry - class should be 'Main' not 'main'

Author

Commented:
Thank you so much!!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.