Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write code in java matching assignment description: Mortgage.java class IO.java

ID: 3705624 • Letter: W

Question

Write code in java matching assignment description:

Mortgage.java class

IO.java class

Assignment Description: This project is similar to Project 5 except you will develop an Object Oriented/ Model-View-Controller solution to the previously assigned program. Before beginning, download the Proj7 StarterFiles.zip file, available through Canvas by clicking on the Project 7 assignment. The file contains two starter files used to help complete this project. Implementation Requirements: Your project will contain three classes: Mortgage (Model), IO (View) and MortgageApp (Controller) The Mortgage class has been started for you. You may add to or modify as you wish. This class is just holding and manipulating the data for our application. There is to be no I/O (println or nextLine) in this class. It contains private instance variables for the three values needed to calculate a mortgage, another to hold the monthly payment, and another to hold the total amount paid on the loan. Customer number has been omitted and is not used for this project. The class contains two constructors - a no argument used to initialize the values for a promotional loan and a 3-argument to instantiate a unique loan. It also defines a get/set method for the Monthly and Total Payment:s (For this project, a Promo Loan is a $100,000 loan at 5.5% for 15 years.) The IO class has also been started for you. You may add to or modify as you wish. It will contain only the data validation and Input-Output portion of the program. Although validating data is usually done through the model and controller class, for simplification, this class will include all input data validation using the criteria listed below. In addition, your program must also handle a character being entered for ALL numeric input or a double being entered for any int input using Exception Handling 1) Valid menu choices are 1-3 2) Valid interest rates are between 3%-7%) (inclusive) 3) Valid terms are 10-40 years (inclusive) 4) Valid amounts are $75,000 to 1 million (inclusive)

Explanation / Answer

import java.util.Scanner;

//This is the Model Class for the MVC application

/*

!! Model Class Starts here !!

*/

class Mortgage

{

private double annualInterestRate;

private int numOfYears;

private double loanAmount;

private double monthlyPayment;

private double totalPayment;

public Mortgage() //default constructor

{

loanAmount=100000;

annualInterestRate=5.5;

numOfYears=15;

}

public double getAnnualInterestRate() {

return annualInterestRate;

}

public int getNumOfYears() {

return numOfYears;

}

public double getLoanAmount() {

return loanAmount;

}

public Mortgage(double newInterestRate, int newNumOfYears, double newLoanAmount) //parameterized constructor

{

this.annualInterestRate=newInterestRate;

this.numOfYears=newNumOfYears;

this.loanAmount=newLoanAmount;

}

public void setMonthlyPayment(double monthlyPayment) //setter method for Monthly payment

{

this.monthlyPayment=monthlyPayment;

}

public double getMonthlyPayment() //getter method for monthly payment

{

return monthlyPayment;

}

public void setTotalPayment(double totalPayment) //setter method for total payment

{

this.totalPayment=totalPayment;

}

public double getTotalPayment() //getter method for total payment

{

return totalPayment;

}

}

/*

!! Model Class Ends here !!

*/

//This is the IO Class for input-output (VIEW)

/*

!! IO class starts here !!

*/

class IO{

private Scanner s;

public IO(){

s= new Scanner(System.in);

}

public boolean validChoice(int choice) {

if(choice>0 && choice<4)

return true;

else

return false;

}

public void displayMenu() {

System.out.println("Please choose from the following choices below: ");

System.out.println(" 1)Promotional Loan ($100,000 @ 5..5% for 15 years) ");

System.out.println(" 2)Unique Load (enter in loan values) ");

System.out.println(" 3)Quit (Exit the program) ");

}

public int getMenuChoice() {

int choice;

System.out.println("Please enter your selection (1-3): ");

choice=s.nextInt();

return choice;

}

public double getRate() {

double rte;

rte=s.nextDouble();

return rte;

}

public int getTerm() {

int loanYears;

loanYears=s.nextInt();

return loanYears;

}

public double getAmount() {

double amt;

amt=s.nextDouble();

return amt;

}

}

/*

!! IO class Ends here !!

*/

/*

!! Controller class starts here !!

*/

public class Controller {

public static void main(String args[])

{

IO io=new IO();

Controller control=new Controller();

int choice,loanYears;

double rte, amt;

Scanner sc= new Scanner(System.in);

char a;

do {

io.displayMenu();

choice=io.getMenuChoice();

if(io.validChoice(choice)) {

switch(choice) {

case 1:

Mortgage mort = new Mortgage();

System.out.println("PROMOTIONAL LOAN..... ");

control.totalPayment(mort);

control.monthlyPayment(mort);

System.out.println("The monthly payment is $"+mort.getMonthlyPayment());

System.out.println("The total payment is $"+mort.getTotalPayment());

break;

case 2:

System.out.println("Please enter in the following information...");

System.out.println("Enter yearly interest rate(Ex 6.25):");

rte=io.getRate();

System.out.println("Enter number of years for the loab (10-40):");

loanYears=io.getTerm();

System.out.println("Enter the loan amount without $ or commas (Ex:12000):");

amt=io.getAmount();

Mortgage mort1 = new Mortgage(rte,loanYears,amt);

control.totalPayment(mort1);

control.monthlyPayment(mort1);

System.out.println("The monthly payment is $"+mort1.getMonthlyPayment());

System.out.println("The total payment is $"+mort1.getTotalPayment());

break;

case 3:

break;

}

}

System.out.println(" Do you want to continue (Y/N): ");

a = sc.next().charAt(0);

}while(a=='Y'|| a=='y');

}

public void totalPayment(Mortgage mort) {

double totalPayment;

totalPayment=mort.getLoanAmount()*mort.getAnnualInterestRate()*mort.getNumOfYears();

mort.setTotalPayment(totalPayment);

}

public void monthlyPayment(Mortgage mort) {

double monthlyPayment;

monthlyPayment=(mort.getLoanAmount()*mort.getAnnualInterestRate()*mort.getNumOfYears())/(15*12);

mort.setMonthlyPayment(monthlyPayment);

}

}

/*

!! Controller class Ends here !!

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote