CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Assignment #4

Calculate the monthly payment on a loan

Due Date: Monday of Week 3
15 points

This project uses static methods that perform the calculation and validate the data of the monthly payment on a loan. Some thought is required as to how to code the required validation routines.

Console

Operation

  • The Data Entry section prompts the user to enter values for the loan amount, yearly interest rate, and number of years. If the user doesn't enter data that's valid, this section displays an appropriate error message and prompts the user again.
  • The Formatted Results section displays a formatted version of the user's entries as well as the formatted result of the calculation.
  • The application prompts the user to continue.

Specifications

  • The formula for calculating monthly payment is:
  • 	double monthlyPayment = loanAmount * monthlyInterestRate/
               (1 - 1/Math.pow(1 + monthlyInterestRate, months));
     	
  • The application should accept decimal entries for the loan amount and interest rate entries.
  • The application should only accept integer values for the years field.
  • The application should only accept integer and decimal values within the following ranges:
  • Greater Than Less Than
    Loan amount: 0 1,000,000
    Yearly interest rate: 0 20
    Years: 0 100
  • The application should only accept a value of "y" or "n" at the Continue prompt.
  • If the user enters invalid data, the application should display an appropriate error message and prompt the user again until the user enters valid data.
  • The code that's used to validate data should be stored in separate methods. For example:
  • public static double getDoubleWithinRange(Scanner sc, String prompt,
        	double min, double max)
    public static int getIntWithinRange(Scanner sc, String prompt,
        	int min, int max)
     	
Include in your program the following comments:
  • Name of program
  • Programmer's name
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

Take a screen capture by hitting simultaneously the keys Alt and Print Screen (Prt Sc) of the output results (console) and paste it in MS Paint. Save it as a gif file.

When you are ready, upload the java program and the gif file by clicking the link below:

Upload Assignment

I cannot grade if I don't get the files and receive your email.