Question
Write a server for a client. The client sends loan information (annual interest rate, number of years, and loan amount) to the server. The server
Write a server for a client. The client sends loan information (annual interest rate, number of years, and loan amount) to the server. The server computes monthly payment and total payment and sends them back to the client. Name the client ClientChat, and the server ServerChat. Attached the Loan.java class. Format the monthly and total payment to display two decimal places.
Loan.Java
// Implements Seriablizable to support object IO public class Loan implements java.io.Serializable { private static final long serialVersionUID = 1L; private double annualInterestRate; private int numberOfYears; private double loanAmount; private java.util.Date loanDate;
/** Default constructor */ public Loan() { this(2.5, 1, 1000); }
/** Construct a loan with specified annual interest rate, number of years and loan amount * @param annualInterestRate * @param numberOfYears * @param loanAmount */ protected Loan(double annualInterestRate, int numberOfYears, double loanAmount) { this.annualInterestRate = annualInterestRate; this.numberOfYears = numberOfYears; this.loanAmount = loanAmount; loanDate = new java.util.Date(); }
/** Return annualInterestRate * @return */ public double getAnnualInterestRate() { return annualInterestRate; }
/** Set a new annualInterestRate * @param annualInterestRate */ public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; }
/** Return numberOfYears * @return */ public int getNumberOfYears() { return numberOfYears; }
/** Set a new numberOfYears * @param numberOfYears */ public void setNumberOfYears(int numberOfYears) { this.numberOfYears = numberOfYears; }
/** Return loanAmount * @return */ public double getLoanAmount() { return loanAmount; }
/** Set a newloanAmount * @param loanAmount */ public void setLoanAmount(double loanAmount) { this.loanAmount = loanAmount; }
/** Find monthly payment * @return */ public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (Math.pow(1 / (1 + monthlyInterestRate), numberOfYears * 12))); return monthlyPayment; }
/** Find total payment * @return */ public double getTotalPayment() { double totalPayment = getMonthlyPayment() * numberOfYears * 12; return totalPayment; }
/** Return loan date * @return */ public java.util.Date getLoanDate() { return loanDate; } }
ClientLoan nual Interest Rate 3.5 Number Of Years 5 Submit Amount 10000 Annual Interest Rate: 3.5 Number of Years: 5 Loan Amount: 10000.0 monthlyPayment: 181.9174497025608 totalPayment: 10915.046982153648 ServerLoan Server started at Fri Feb 16 10:30:20 EST 2018 Connected to a client at Fri Feb 16 10:30:39 EST 2018 Annual Interest Rate: 3.5 Number of Years: 5 Loan Amount: 10000.0 monthlyPayment: 181.9174497025608 totalPayment: 10915.046982153648 ClientLoan nual Interest Rate 3.5 Number Of Years 5 Submit Amount 10000 Annual Interest Rate: 3.5 Number of Years: 5 Loan Amount: 10000.0 monthlyPayment: 181.9174497025608 totalPayment: 10915.046982153648 ServerLoan Server started at Fri Feb 16 10:30:20 EST 2018 Connected to a client at Fri Feb 16 10:30:39 EST 2018 Annual Interest Rate: 3.5 Number of Years: 5 Loan Amount: 10000.0 monthlyPayment: 181.9174497025608 totalPayment: 10915.046982153648Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started