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

JAVA PROGRAMMING Gui application with background class/classes. Know how to use

ID: 3827320 • Letter: J

Question

JAVA PROGRAMMING


Gui application with background class/classes. Know how to use Buttons, TextFields, TextAreas, Labels, various panels, Scene and stagge to carry out calculations. Layout is your choice. Know how to design and implement classes for given UMLs. Know how to handle Events. Exception handling: In case a user enters a wrong inputs, apply proper Exception handling. Design and implement Loan class, then use it to write a GUI application to calcu;ate monthly pay and total interest for a mortgage.


Loan

principle : double . //principle borrowed

- rate : double //annual interest rate in percentage

-years : int //number of years of t e Mortgage (Loan)

//two constructors

+ Loan (double princp, double rate, int years);

+LoanO{this(0, 3.75, 30);}


//get methods, one for each member variable

- getPrinciple() : double

+ getRate0: double

+getYears(): int

//set methods, one for each member variable •

+setPrinciple(double newPrinciple) : void

+ setRate(double r): void

+setYears(int y): void

+ monthlyPay() //returns monthly payment

//returns overall pay mcnt by the end of the Loan period

+totalPayment(): doubile •

+totalinterest() : double //returns overall interest by the end of the loan period

+ toString0 : string

Explanation / Answer

//all the backend class Loan you needed.

package com.chegg.me;

import java.lang.Math;

public class Loan {

   private double principle;
   private double rate;
   private int years;
   private double monthlyPayment;
   private double totalPayment;
   private double totalInterest;

   Loan(double principle, double rate, int years) {
       this.principle = principle;
       this.rate = rate;
       this.years = years;
   }

   Loan() {
       this.principle = 0;
       this.rate = 3.75;
       this.years = 30;
   }

   public double monthlyPayment() {
       double totalMonths = years * 12;
       double monthlyRate = (rate / totalMonths) / 100;
       monthlyPayment = principle
               * ((monthlyRate * Math.pow(1.0d + monthlyRate, totalMonths)) / (Math.pow(1.0d + monthlyRate, totalMonths)
                       - 1));
       return monthlyPayment;

   }

   public double totalPayment() {
       totalPayment = monthlyPayment() * years * 12;
       return totalPayment;

   }

   public double totalInterest() {
       totalInterest = totalPayment() - principle;
       return totalInterest;

   }

   public double getPrinciple() {
       return principle;
   }

   public void setPrinciple(double principle) {
       this.principle = principle;
   }

   public double getRate() {
       return rate;
   }

   public void setRate(double rate) {
       this.rate = rate;
   }

   public int getYears() {
       return years;
   }

   public void setYears(int years) {
       this.years = years;
   }

   public static void main(String[] args) {
       // TODO Auto-generated method stub
//       Loan obj = new Loan();
       Loan obj = new Loan(100,4.0d, 1);
//       obj.setPrinciple(100);
//       obj.setRate(4);
//       obj.setYears(1);
      
       double sd = obj.totalPayment();
       System.out.println(sd);
   }

}