I just want you to do the second part only using java class, but i have attached the answer for assignment 1.  Assignment 1 question Loan Account Class:  Create class LoanAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable principal indicating the amount the person is borrowing. Provide method: public double calculateMonthlyPayment(int numberOfPayments) to calculate the monthly payment by using the following formula: double monthlyPayment = principal * ( monthlyInterest / (1 - Math.pow(1 + monthlyInterest, -numberOfPayments))); where monthly interest = annualInterestRate/12. Provide a static method setAnnualInterestRate that sets the annualInterestRate to a new value.  Set the initial loan amount (Principal) for a new loan through the constructor. Write a program to test class LoanAccount. Instantiate two LoanAccount objects, loan1 and loan2, with principal loan amounts of $5000.00 and $31000.00, respectively. Set annualInterestRate to 1%, then calculate the monthly payment for each loan for 36 months, 60 months, and 72 months and print the monthly payment amounts for both loans. Next, set the annualInterestRate to 5%, and output the same information again.  Make sure your dollar amounts are displayed to two decimal places. Second Part Create Loan Account Hierarchy consisting of the following classes: LoanAccount, CarLoan, PrimaryMortgage , UnsecuredLoan, and Address. Each class should be in it's own .java file. The LoanAccount class consists of the following properties: principal- the original amount of the loan. annualInterestRate - the annual interest rate for the loan. It is not static as each loan can have it's own interest rate. months - the number of months in the term of the loan, i.e. the length of the loan. and the following methods

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 20PE: When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making...
icon
Related questions
Question

I just want you to do the second part only using java class, but i have attached the answer for assignment 1. 

Assignment 1 question

Loan Account Class: 

Create class LoanAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable principal indicating the amount the person is borrowing. Provide method: public double calculateMonthlyPayment(int numberOfPayments) to calculate the monthly payment by using the following formula:

double monthlyPayment = principal * ( monthlyInterest / (1 - Math.pow(1 + monthlyInterest, -numberOfPayments)));

where

monthly interest = annualInterestRate/12.

Provide a static method setAnnualInterestRate that sets the annualInterestRate to a new value.  Set the initial loan amount (Principal) for a new loan through the constructor.

Write a program to test class LoanAccount. Instantiate two LoanAccount objects, loan1 and loan2, with principal loan amounts of $5000.00 and $31000.00, respectively. Set annualInterestRate to 1%, then calculate the monthly payment for each loan for 36 months, 60 months, and 72 months and print the monthly payment amounts for both loans. Next, set the annualInterestRate to 5%, and output the same information again.  Make sure your dollar amounts are displayed to two decimal places.

Second Part

Create Loan Account Hierarchy consisting of the following classes: LoanAccount, CarLoan, PrimaryMortgage , UnsecuredLoan, and Address. Each class should be in it's own .java file.

The LoanAccount class consists of the following properties:

  • principal- the original amount of the loan.
  • annualInterestRate - the annual interest rate for the loan. It is not static as each loan can have it's own interest rate.
  • months - the number of months in the term of the loan, i.e. the length of the loan.

and the following methods:

  • a constructor that takes the three properties as parameters.
  • calculateMonthlyPayment() - takes no parameters and calculates the monthly payment using the same formula as Assignment 1.
  • getters for the three property variables.
  • toString() - displays the information about the principle, annualInterestRate, and months as shown in the example output below.

 

The CarLoan class which is a subclass of the LoanAccount class and consists of the following property:

  • vehicleVIN - the VIN number of the car, as a string.

and the following methods:

  • constructor that accepts the three parameters of the LoanAccount class and the vehicleVIN.
  • toString() - displays the information about the VIN number as shown in the example output below.

 

The PrimaryMortgage class which is a subclass of LoanAccount and consists of the following properties:

  • PMIMonthlyAmount - the amount of the Primary Mortgage Insurance which is required for all mortgages where the down payment is not at least 20% of the home value.
  • Address - the address of the real estate and is an object of the Address class.

and the following methods:

  • constructor that accepts the three parameters of the LoanAccount class, the PMIMonthlyAmount, and the Address object containing the address.
  • toString() - displays the information about the PMIMonthlyAmount and Address as shown in the example output below.

 

The UnsecuredLoan class which is a subclass of LoanAccount and has no additional properties and has the following methods:

  • constructor that accepts the three parameters of the LoanAccount class.
  • toString() - displays the information that it is an Unsecured Loan as shown in the example output below.

 

The Address class which consists of the following properties:

  • street - the house number and street part of the address.
  • city - the city where it is located.
  • state - the state.
  • zipcode - and the zipcode.

and the following methods:

  • constructor which accepts the values for the four properties as parameters.
  • getters for each property.
  • toString() - display the address information as shown in the example below.

 

Your code in the subclasses should call methods in the super classes whenever possible to reduce the amount of code in the subclasses and utilize the code already developed in the super classes. 

Use the following code in your main function to test your classes, just copy and paste it into your main method:

        // Create three different loan objects, one of each type.
        CarLoan carLoan = new CarLoan(25000.00, 4.25, 72, "IRQ3458977");
        
        Address propertyAddress = new Address("321 Main Street", "State College", "PA", "16801");
        PrimaryMortgage propertyLoan = new PrimaryMortgage(250000.00, 3.1, 360, 35.12, propertyAddress);
        
        UnsecuredLoan unsecuredLoan = new UnsecuredLoan(5000.00, 10.75, 48);
        
        //Print out the load information for each loan using the toString() method.
        System.out.format("%n%s%s%s%n", carLoan, propertyLoan, unsecuredLoan);
public class LoanAccount !
// properties
// private instance variable principal
private double principal;
// static variable "annualInterestRate"
private static double annualInterestRate:
// constructor
public LoanAccount double Principle) {
principal Principle:
}
// method called calculateMonthly Payment
public double calculateMonthlyPayment(int numberOfFavmenta) {
double monthlvinterest = annualIntexestRate / 12:
double monthlyPayment principal
(monthlvinterest / (1 -
Math Bowl + monthlvintexeat, -numberofRaymEnRR) ) );
return monthlyFavment
onthlyPayment:
}
// a static method getAnnualInterestRate
public static void setAnnualInterestRate/double AnnualIntexestRate)
{
annualInterestRate = AnnualInterestRate:
}
public static void main(String[] args) {
// principal loan amounts of $5000.00 and $31000.00
double principlelAmount = 5000, principle2Amount = 31000:
// Instantiate two loan objects
LoanAccount loan1 = new LoanAccount (principlelAmount:
LoanAccount loan2 = new LoanAccount (principle2Amount);
// display results.
Skatem:QUE Brint("Monthly payments for loanl of $%.2f and loan2
$%.2f for 3, 5, and 6 year loans at 1 §§ intexeståe",
principlelAmount, principle2Amount);
// Set annualIntexestRate to 1%,
setAnnualIntereatBate(0.01);
Skatem.out.println("Loan 3 years 5 years 6 years");
Z
// calculate the monthly payment for each loan for 36 months, 60
months, and 72 months and print the monthly payment amounts for both
loans.
Svatem.out.printf("Loan.2f $.2f $.2f%n",
loanl.calculateMonthlyPayment (312),
loanl.calculateMonthlyPayment (5 * 12),
loanl.calculateMonthlyPayment (6 * 12)
Svatem.out.printf("Loan2.2f $.2f $.2f\n",
loan2.calculateMonthlyPayment (3 * 12),
loan2.calculateMonthlyPayment (5 * 12),
loan2.calculateMonthlyPayment (6 * 12))
Svatem. Que printf("%ņMonthly payments for loanl of $%.2f and loan2
$%.2f for 3, 5, and 6 year loans at 5 ## interestin",
principlelAmount, principle2Amount);
// set the annual InterestRate to 5%
setannualInterestRate (0.05);
Skatem.out.println("Loan 3 years 5 years 6 years":
Svatem.out.printf("Loan1 .2f
$.2f $.2f%n",
loanl.calculateMonthlyPayment (312),
loanl.calculateMonthlyPayment (5 * 12),
loanl.calculateMonthlyPayment (6 * 12));
Skatem.out.printf("Loan2 .2f $.2f $.2f%n",
loan2.calculateMonthlyPayment (312),
loan2.calculateMonthlyPayment (5 * 12),
loan2.calculateMonthlyPayment (612)
(Ctrl)
Transcribed Image Text:public class LoanAccount ! // properties // private instance variable principal private double principal; // static variable "annualInterestRate" private static double annualInterestRate: // constructor public LoanAccount double Principle) { principal Principle: } // method called calculateMonthly Payment public double calculateMonthlyPayment(int numberOfFavmenta) { double monthlvinterest = annualIntexestRate / 12: double monthlyPayment principal (monthlvinterest / (1 - Math Bowl + monthlvintexeat, -numberofRaymEnRR) ) ); return monthlyFavment onthlyPayment: } // a static method getAnnualInterestRate public static void setAnnualInterestRate/double AnnualIntexestRate) { annualInterestRate = AnnualInterestRate: } public static void main(String[] args) { // principal loan amounts of $5000.00 and $31000.00 double principlelAmount = 5000, principle2Amount = 31000: // Instantiate two loan objects LoanAccount loan1 = new LoanAccount (principlelAmount: LoanAccount loan2 = new LoanAccount (principle2Amount); // display results. Skatem:QUE Brint("Monthly payments for loanl of $%.2f and loan2 $%.2f for 3, 5, and 6 year loans at 1 §§ intexeståe", principlelAmount, principle2Amount); // Set annualIntexestRate to 1%, setAnnualIntereatBate(0.01); Skatem.out.println("Loan 3 years 5 years 6 years"); Z // calculate the monthly payment for each loan for 36 months, 60 months, and 72 months and print the monthly payment amounts for both loans. Svatem.out.printf("Loan.2f $.2f $.2f%n", loanl.calculateMonthlyPayment (312), loanl.calculateMonthlyPayment (5 * 12), loanl.calculateMonthlyPayment (6 * 12) Svatem.out.printf("Loan2.2f $.2f $.2f\n", loan2.calculateMonthlyPayment (3 * 12), loan2.calculateMonthlyPayment (5 * 12), loan2.calculateMonthlyPayment (6 * 12)) Svatem. Que printf("%ņMonthly payments for loanl of $%.2f and loan2 $%.2f for 3, 5, and 6 year loans at 5 ## interestin", principlelAmount, principle2Amount); // set the annual InterestRate to 5% setannualInterestRate (0.05); Skatem.out.println("Loan 3 years 5 years 6 years": Svatem.out.printf("Loan1 .2f $.2f $.2f%n", loanl.calculateMonthlyPayment (312), loanl.calculateMonthlyPayment (5 * 12), loanl.calculateMonthlyPayment (6 * 12)); Skatem.out.printf("Loan2 .2f $.2f $.2f%n", loan2.calculateMonthlyPayment (312), loan2.calculateMonthlyPayment (5 * 12), loan2.calculateMonthlyPayment (612) (Ctrl)
The output from your program should look like the following:
run:
Car Loan with:
Principal: $25000.00
Annual Interest Rate: 4.25%
Term of Loan in Months: 72
Monthly Payment: $393.98
Vehicle VIN: IRQ3458977
Primary Mortgage Loan with:
Principal: $250000.00
Annual Interest Rate: 3.10%
Term of Loan in Months: 360
Monthly Payment: $1067.54
PMI Monthly Amount: $35.12
Property Address:
321 Main Street
State College, PA 16801
Unsecured Loan with:
Principal: $5000.00
Annual Interest Rate: 10.75%
Term of Loan in Months: 48
Monthly Payment: $128.62
Transcribed Image Text:The output from your program should look like the following: run: Car Loan with: Principal: $25000.00 Annual Interest Rate: 4.25% Term of Loan in Months: 72 Monthly Payment: $393.98 Vehicle VIN: IRQ3458977 Primary Mortgage Loan with: Principal: $250000.00 Annual Interest Rate: 3.10% Term of Loan in Months: 360 Monthly Payment: $1067.54 PMI Monthly Amount: $35.12 Property Address: 321 Main Street State College, PA 16801 Unsecured Loan with: Principal: $5000.00 Annual Interest Rate: 10.75% Term of Loan in Months: 48 Monthly Payment: $128.62
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps with 2 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning