Page 1 of 1

Could someone do this program for me, could you please at a main class where i will test the program.

Posted: Sun May 15, 2022 11:44 am
by answerhappygod
Could someone do this program for me, could you please at a main
class where i will test the program.
Could Someone Do This Program For Me Could You Please At A Main Class Where I Will Test The Program 1
Could Someone Do This Program For Me Could You Please At A Main Class Where I Will Test The Program 1 (55.29 KiB) Viewed 70 times
1 Objectives Write a class to model a bank loan*Write non-default constructor Override the toString method & Write getter accessors) and setter (mutator) methods & Use loops Use floating $ point computations * Generate meatly formatted table of numbers LOAN 2 Buying on Credit Consumers often buy big ticket items such as houses or cars on credit such as a mortgage or car loan. The monthly payments on the loan are the same every month, and are calculated as follows: monthly interest rate x loan amount monthly payment 1-(1 + monthly interest rate where loan amount monthly interest rate = initial principal, the original amount of money borrowed 1 1200 of the annual interest rate in percentage format = the loan term in months - payment amount per month of which a portion covers interest charges and the remaining portion goes towards reducing the loan balance months monthly payment 2.1 Example The monthly payment on a 6-month $1000 loan with a 9,0% annual interest rate is computed as follows: (9.0/1200) * 10000 monthly payment - $171207 1- (1 + (90/1200) 3 Your Task: Class Loan Implement a Loan class that models a loan 3.1 Attributes of a Loan Object . loan amount a double . annual interest rate expressed as a percentage value, for example, 6.5 for 6.5% • loan's term in months, an int 3.2 Operations of a Loan Object Your Loan class must include the following methods: 3.2.1 Public Constructors Loan (double loan amount, double annual interest, int months) Creates a Loan object initializing the object's loan amount, interest rate, and months Heats Unit Must use the setter methods to set the corresponding attributes To see why, check out the setter methods. 3.2.2 Public Setter (mutator) methods void setLoanAmount (double lam) Sets this Loan object's loan amount If the supplied initial value in lam is negative, then the method must throw an exception of class IllegalArgumentException using an appropriate message. For example: if (lam< 0) throw new IllegalArgumentException ("LoansetLonAmount the loan amount must be non negative": void setAnnualInteretsRate(double air) Sets this object's annual interest rate, The parameter air expects a value expressed in percentage format, for example, the values 6.5 for 6.5% the supplied initial value in air is negative, then the method must throw an exception

void setLoanMonths(int months) Sets this object's months in loan If the supplied initial value in months is negative, then the method must throw an excep- tion of IllegalArgumentException using an appropriate message. For example: if (months < 0) throw new illegal ArgumentException ("Loan setLoan Months: the months in loan must be non-negative): 1 3.2.3 Public Getter accessor) methods String getLoanAmount() Returns this Loan object's amount double get AnnualInteretsRate Returns this object's annual interest rate int getLoanMonths Returns this object's months in loan 3.2.4 A toString Override @Override public String toString Returns string representation of this Loan object. For example, the code segment Loan a loan = new Loan (1000.0, 0.0.6) 77 51000 loan 0.0% annual interest, 6-months torm System.out.println(a.loan); // print loan summary report should produce the following output: Loan Report Loan Amount: $1,000.00 Annual Interest rate: 9.00% Loan's term in months: 6 Monthly payment: $171.07 Total Interest Paid: $26.41 Heads Upl Your toString() method must use the getter methods to access instance variables 3.2.5 Public Facilitator Methods double getMonthlyInteretsRate() Returns this object's annual interest divided by 1200. double getMonthlyPayment() Computes this object's monthly payment using the formula on page 1. double getLoanCosto) Returns the total interest paid at the the end of the loan's term. 3.2.6 A Method to Create Amortization Schedule public String amortize() Returns a string that represents this loan's amortization schedule. For example, the code segment Loan a loan = new Loan (1000.0, 0.0.6) // $1000 loan. 9.0% annual interest6-months term System out.println (loan amortize()); // print amortization schedule

should produce the following output: Amortization Schedule Monthly Payment $171.07 Month Interest paid Principal Paid Loan Balance 10 11 1 2 3 4 5 6 7.50 6.27 5.04 3.79 2.54 1.27 163.57 164.80 166.03 167.28 168.53 169.80 1000.00 836.43 671.64 505.60 338.33 169.80 0.00 Totals 26.41 1000.00 Facilitator method a method that is not a constructor accessor, or mutator and that provides a useful service for the objects it serves Here is the same output again for your convenience Amortization Schedule Monthly Payment $171.07 Month Interest paid Principal Paid Loan Balance 1 2 3 4 5 6 7.50 6.27 5.04 3.79 2.54 1.27 163.57 164.80 166.03 167.28 168.53 169.80 1000.00 836.43 671.64 505.60 338.33 169.80 0.00 11 14 16 1 Totala 26.41 1000.00 The banner part of the output between the top two dashed lines indicates that the monthly payment for each month is fixed at $171.07 The output table shows that each month a portion of the fixed monthly payment pays for the interest on the loan balance, and another portion goes towards reducing the loan balance itself. Specifically, the columns in the output table are calculated as follows: Column 2 The interest portion of the payment = the monthly interest rate the previous balance For example, on line 10, the interest paid 7.50 = (9.0/1200) + 1000.0, and on line 11, the interest paid 6.27 = (9.0/1200) 836.43, and so on. Column 3 The principal portion of the payment payment - interest For example, on line 10, the principal paid 163.57 = 171.07 - 7.50, and on line 11, the principal paid 164.80 = 171.07 - 6.27, and so on. Column 4 Appearing on line 9 by itself, the loan balance is initially set to the original loan amount. The new loan balance previous balance - principal For example, on line 10, the loan balance 836.43 = 1000,0 - 163.57, and on line 11. the principal paid 671.64 836.43 - 164.80, and so on.

4 Sample Driver Program import mutil My Scanner // using our own mutil package public class Loan Amortizer public static void main(String llar) MyScanner my keyboard - new MyScanner(); using our own MyScanner class char answer: 7 stores were respnce to whether loop should rapeat do W Get the loan amount double loan = my keyboard read Double("Enter the loan amount") W Get the annual interest rate double interest Rate = my keyboard.read Double("Enter the annual + "interest rate) int months = my keyboard readint("Enter loan term is months) Create and initial Loan object Loan a loan - nw Loan (loan. Interest Rate, months) System.out.printin (loan): // loan summary report System.out.printinaioan amortize()); // loan amortization report W/ Do another report? System.out.print("Would you like to run another report?" + "Enter Yor y for ye, or any other character for so"). answer = my keyboard read Char()://read char using our readChar() answer = Character to LowerCase (answer); // convert answer to lowercase for the following test } while (answer System.out.println("goodbye!"); 5 A Sample Run of the Driver Program Enter the loan anount: 1000.0 Enter the annual interest rate: 9.0 Enter loan's term in months: 6 Loan Report Loan Anount: $1,000.00 Annual Interest rate: 9.00% Loan's term in tonthe: 6 Monthly payment: $171.07 Total Interest Paid: $26.41 Amortization Schedule Monthly Payment 3171.07 Month Interest Principal paid Paid Loan Balance 1 2 3 4 5 6 7.50 5.27 5.04 3.79 2.54 1.27 163.57 164.80 166.03 167.28 168.53 169.80 1000.00 836,43 671.64 505.60 338.33 169.80 0.00 Totals 26.41 1000.00 Would you like to run another report? Enter Y or y for yes, or any other character for no y Enter the loan anunt: 12000.0 Enter the annual interest rate: 5.0 Enter loan's term in months: 12 Loan Raport

Loan Amount: $12,000.00 Annual Interest rate: 5.00% Loan's term in months: 12 Monthly payment: $1,027.29 Total Interest Paid: $327.48 Amortization Schedule Monthly Payment $1027.29 Month Interest paid Principal Paid Loan Balance WN 5 6 7 8 9 10 11 12 50.00 45.93 41.84 37.73 33.61 29.47 25.31 21.14 16.94 12.73 8.51 4.26 977.29 981.36 985.45 989.56 993.68 997.82 1001.98 1006.15 1010.35 1014.55 1018.78 1023.03 12000.00 11022.71 10041.35 9055.90 8066.34 7072.66 6074.84 5072.86 4066.71 3056.36 2041.81 1023.03 0.00 1 Totala 327.48 12000.00 Would you like to run another report? Enter Yor y for yes, or any other character for non