You are on page 1of 4

ITSS 3211 Introduction to Programming

Dr. Nassim Sohaee


Fall 2015

Student name: Stephanie Nguyen


Course Number: 3211
Section Number: 002
Due Date: November 15, 2015
Important notes:
If you work with another student or get help from a tutor, please indicate this on
your assignment.
Pledge:
I understand that the consequences of committing any act of academic dishonesty
can include a failing grade for the assignment, failure in the class as a whole, and
even expulsion from the university. I will not plagiarize or cheat.
Analysis:
A program is needed where user inputs loan amount and loan period in number of
years to display the outputs, monthly and total payments according to certain
interest rate percentage.

Design:
Declare the variables to store users inputs. Prompt user for loan amount and
number of years. Display the interest rate from 5% to 8% in 1/8 increments and
convert the number of years into the number of months. This equation

was used to calculate the total payment. The


results of the total payments are then divided by the number of months to calculate
the monthly payment.

Coding:
//////////////////////////////////////////////////////////////////////////////
/
// ALL STUDENTS COMPLETE THESE SECTIONS
// Title: Project 4
// Files: ComparingLoans.java
// Semester: Fall 2015
//
// Author: Stephanie Nguyen
// Email: sxn146130@utdallas.edu
// CS Login: sxn146130
// Lecturer's Name: Dr. Nassim Sohaee
// Course Section: 002
//
//////////////////// STUDENTS WHO GET HELP FROM OTHER THAN THEIR
PARTNER //////
// fully acknowledge and credit all sources of help,
// other than Instructors and TAs.
//
// Persons: NA
//
// Online sources: http://www.mathwarehouse.com/compound-interest/formulacalculate.php
// Web site used to find the compound interest formula, A = P(1+r/n)^nt
// http://www.bankrate.com/calculators/mortgages/loan-calculator.aspx
// Web site used for loan calculator to calculate monthly payment by entering
in the variables
//
// Dr. Sohaee, I used the formula and calculator from the above sources and
cannot seem to get the same monthly and total payment amount as the sample
provided.
//
//////////////////////////// 80 columns
wide //////////////////////////////////
import java.util.Scanner;
/**
* Reading two inputs from user to compute and display the monthly and total
payment according to each interest rate
*
* <p>Bugs: inputing a letter for a numerical value will result in the program
crashing
*
* @author Stephanie Nguyen
*/
public class ComparingLoans {
/**
* Entry point for Comparing Loans program
*
* @param args is not used
* @return no return value
*/

public static void main(String[] args) {


//Prompts user to enter in loan amount
System.out.print("Loan Amount: ");
Scanner input = new Scanner(System.in);
double LoanAmount;
LoanAmount = input.nextDouble();
//Prompts user to enter in number of years
System.out.print("Number of Years: ");
int NumberOfYears;
NumberOfYears = input.nextInt();
input.close();
//Computing number of months
int NumberOfMonths = NumberOfYears * 12;
//Defining variables
double TotalPayment = 0;
double MonthlyPayment = 0;
//Using specifiers to display variables into columns
System.out.printf("%-20s%-20s%-20s\n", "Interest Rate", "Monthly
Payment", "Total Payment");
//Defining interest rate starting at 5%
double InterestRate = 5;
//Do While interest rate is between 5% to 8% in 1/8 increments
do
{
//Computing Total Payment
TotalPayment = LoanAmount * Math.pow(1 +
(InterestRate/100) / 12,12 * NumberOfYears);
//Computing Monthly Payment
MonthlyPayment = TotalPayment / NumberOfMonths;
//Using specifiers to display results under columns
System.out.printf("%-20.2f%-20.2f%-20.2f\n",
InterestRate,MonthlyPayment,TotalPayment);
//Incrementing by 1/8
InterestRate += .125;
//Make interest rate less than or equal to 8 to stop incrementing
} while (InterestRate <=8);
}
}

Testing:
I used the input values given in the sample 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.

You might also like