Results 1 to 4 of 4
  1. #1
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default Need help with creating a loop

    Hi. I am trying to create a loop to allow user to enter data and present data or allow user to exit. I created a loop but this goes through the information continuously. I need the user to enter mortgage amount, interest rate, and loan term. The program should calculate and output data. The program should allow the user to enter new amounts or exit. I am sure I am missing something little, but I am not sure. Could someone lead me the right way? Thanks. Here is the code.
    Java Code:
    package mortgage;
    
    /**The Mortgage class implements an application which calculates the mortgage 
     *payment, interest paid, principal paid and loan balance.
     * The application prints interest paid, mortgage payment, and loan balance 
     * to output 
     * @author Lekeisha
     **/
    
    
    import java.util.Scanner;
    
    public class Mortgage 
    /**Creates a new instance of Mortgage**/
    {
             
        public static void main(String[] args) 
        {
                  
            Scanner scan = new Scanner(System.in);
        do{    
        System.out.print("Enter amount of mortgage:  ");
        double amLoanOne = scan.nextDouble();//get amount of mortgage from user
            
        System.out.print("Enter loan term:  ");
            double loanTerm = scan.nextDouble();//get value for loan term from user
        
        
        System.out.print("Enter interest rate:  ");
            double intRates = scan.nextDouble();//get interest rate from user
            
        
        
       
    
        
        
        
         
        
        
       
        
         
              
        double monIntRate = 0.0;//initiates the monthly interest rate
        double monPay = 0;//initiates the mortgage payment 
        
        double intsPaid = 0;//initiates interest paid 
        double princPaid = 0;//initiates principal paid
        monIntRate = intRates/12;//interest rate of 5.35% divided by 12 months equals the monthly interest rate
        double totMons = loanTerm*12;//term of loan multiplied by 12 months equals total months of term
        double amLoanNxt = amLoanOne;//initiates the amount of loan balance after initial amount
        monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
        //calculates the mortgage payment
           intsPaid = amLoanOne*monIntRate; 
        //calculates the interest paid
           princPaid = monPay - intsPaid;
        //calculates the principal paid  
           amLoanNxt = amLoanOne - princPaid;
        //calculates the amount of loan balance after initial amount
          
          
          System.out.println("Interest amount is $" + Math.round(intsPaid)+ ".");
          //calculates the interest paid with interest rate of 5.75%
          System.out.println("Mortgage payment amount is $"  + Math.round(monPay)+ ".");
          //calculates the mortgage payment amount
          System.out.println("Loan balance amount is $" + Math.round(amLoanNxt)+  ".");
          //calculates the loan balance
          
          System.out.println("(press 0 to exit)");
          //asks user input of 'Enter' to display other lines of text
        }
          while (amLoanOne != '0');
             
        }
        }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You ask them to press 0 to exist, but never got the users input.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    Java Code:
    System.out.println("(press 0 to exit)");
          //asks user input of 'Enter' to display other lines of text
        }
          while (amLoanOne != '0');
    Two problems I can see: You prompt user to enter 0 to exit but you when do you actually get the input? You have declared amLoanOne as a double but you compare it to the char '0' not the numerical value 0.

  4. #4
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

Similar Threads

  1. Need Help Creating A Loop!
    By chrisnojen117 in forum New To Java
    Replies: 3
    Last Post: 05-12-2011, 07:30 PM
  2. Creating a loop help !
    By theman279 in forum New To Java
    Replies: 5
    Last Post: 03-10-2011, 10:13 AM
  3. creating variables in a for loop?
    By sehudson in forum New To Java
    Replies: 7
    Last Post: 03-01-2011, 03:37 AM
  4. Help with creating a while loop!
    By BAD in forum New To Java
    Replies: 1
    Last Post: 07-09-2010, 09:00 PM
  5. Creating a Loop
    By SenorJalapeno in forum New To Java
    Replies: 3
    Last Post: 04-02-2010, 10:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •