You are on page 1of 5

MITS4002

OBJECT-ORIENTED SOFTWARE
DEVELOPMENT

Activity 07
Due: Monday Lesson 09

50% deduction for Late Submission within one week


0 mark for Late Submission more than one week
0 mark for duplicated Submission or Shared Work

You will be marked based on your submitted zipped file on Moodle. You are
most welcome to check your file with your lab tutor before your submission.
No excuse will be accepted due to file corruption, absence from lecture or lab
classes where details of lab requirements may be given.
Please make sure that you attend Lecture EVERY WEEK as low
attendance may result in academic penalty or failure of this unit.

Student ID: 42662

Student full name: Madan Lal Gaire

Total Points (20 pts):

Date: 05/16/2019
MITS4002 Activity 07

Project: Comparing Loans


Problem Description:

Write a program that lets the user enter the loan amount and loan period in number of
years and displays the monthly and total payments for each interest rate starting from 5%
to 8%, with an increment of 1/8. Here is a sample run:

<Output>
Loan Amount: 10000

Number of Years: 5

Interest Rate Monthly Payment Total Payment


5.000% 188.71 11322.74
5.125% 189.28 11357.13
5.250% 189.85 11391.59
...
7.875% 202.17 12129.97
8.000% 202.76 12165.83

<End output>

Use the formulas below to compute monthly payment and total payment.

loanAmount∗mont h lyInterestRate
mont h lyPayment =
1
1− ¿
¿¿

totalPayment =mont h lyPayment∗12∗numberOfYears

Analysis: (Describe the problem including input and output in your own words.)
1
MITS4002 Activity 07

A program is required that prompts the user to enter the loan amount and the loan period
in number of years to display the output in monthly and total payments according to the
certain interest rate.

Design: (Describe the major steps for solving the problem.)

First, you need to import the scanner so that you can get the numbers from the user, then

- Create a public class called CompareLoan


- Declare variables of type double for Loan amount, type integer for number of
years and type double for annual Interest rate.
- Prompt users to enter the details.
- Set annual interest rate to 5.0.
- Obtain monthly interest rate to calculate the monthly and total payment using the
provided formula.
- Display interest rates, monthly payment and total payment.

Coding: (Copy and Paste Source Code here. Format your code using Courier 10pts)
package compareloan;

/**

* @author madan

*/

import java.util.Scanner;

public class CompareLoan {

public static void main(String[] args) {

// Create a Scanner

Scanner input = new Scanner(System.in);

// Prompt user to enter the loan amount

System.out.print("Please enter the loan amount:");

double loanAmount = input.nextDouble();

// Prompt user to enter the loan period in number of years

System.out.print("Please enter the number of years: ");


2
MITS4002 Activity 07

int numberOfYears = input.nextInt();

// Display table header

System.out.println("Interest Rate Monthly Payment Total


Payment");

// Enter yearly interest rate start value

double annualInterestRate = 5.0;

while (annualInterestRate <= 8.0) {

// Obtain monthly interest rate

double monthlyInterestRate = annualInterestRate / 1200;

// Calculate the payment

double monthlyPayment = loanAmount

* monthlyInterestRate

/ (1 - 1 / Math.pow(1 + monthlyInterestRate,

12 * numberOfYears));

double totalPayment = monthlyPayment * 12 * numberOfYears;

// Display results

System.out.printf("%-18.3f%-18.2f%-18.2f\n",
annualInterestRate,

monthlyPayment, totalPayment);

annualInterestRate = annualInterestRate + 1.0 / 8;

Output screenshot: (Paste your output screenshot here)


3
MITS4002 Activity 07

Testing: (Describe how you test this program).

I used the input values given in the sample provided for loan amount and number of years
to run the program to see if it displays the same monthly and total payment as the sample.

Submit the following items:

1. This Word document and Submit to Moodle (you must submit the program regardless
whether it complete or incomplete, correct or incorrect)

Hint:

1. Can you get the first four rows manually? This will help you understand
how to compute the numbers mathematically.
2. Can you write a program to produce the first four rows? This will help you
see the pattern.
3. Can you generalize it in a loop to produce all the rows?
4. Finally, format the output correctly.

You might also like