Write necessary number of Java classes to implement the foll

Write necessary number of Java classes to implement the following functionalities and test it.

Steps:

Create a Java package with a name Quiz1

Create a Java class with the name Account with necessary data members and methods as given below:

A private int data field named id for the account (default 0).

A private double data field named balance for the account (default 0).

A private double data field named annualInterestRate that stores the current interest rate (default 0).

A private double data field named monthlyInterestRate default value 0

A no-arg constructor that creates a default account.

A parameterized constructor that creates an account with the specified id ,initial balance and annualInterestRate (in %)

Overridden toString method to return the Account object fields as a string

Get methods(getBalance(), getAnnualInterestRate() to return balance and annualInterestRate)

Set method(setMonthlyInterestRate()) to set the monthlyInterestRate

Create two Java classes with the names Server and Client respectively

In Server class, add a main method to perform following task

Register Service on a port (1-65535)

Wait and Accept Connection

Get the input stream associated with the socket and assign it to the ObjectInput Stream

Read the Account object

Compute the monthlyInterestRate.

monthlyInterestRate = balance *((annualInterestRate/100)/12).

Get the output stream associated with the socket and assign it to the ObjectOutputStream.

Close the opened Streams and Sockets.

In Client class, add main method to perform following task

Open your connection to a server, at specified port in Server

Create an Account object by invoking parameterized constructor with necessary values.

Get an output file handle from the socket and write the ObjectOutputStream

Get an input file handle from the socket and read the ObjectInputStream

Display the Account Object content with the monthlyInterestRate

Close the opened Streams and Sockets.

Note:

Add “implements java.io.Serializable” while creating Server class and Account class.

SincereadObject and writeObject methods return Object type , typecast it with Account Class to invoke getBalance() and getAnnualIntrestRate() and setMonthlyInterestRate.

Ex: ObjectInputStream fromServer =new ObjectInputStream(socket.getInputStream());

                Account acc = (Account)fromServer.readObject();

Solution

Server class

public class serverAccount
{

private double blnce;
private double annualInterestRate;
private double mnthlyIntrstRta;
private double ttlDpsts;
private double ttlWthdrw;
private double ttlIntrst;

public serverAccount(double startBalance, double annual_Interest_Rate)
{
blnce = startBalance;
annualInterestRate = annual_Interest_Rate;
}


public void setAnnualInterestRate(double annual_Interest_Rate)
{
mnthlyIntrstRta = annualInterestRate / 12;
}


public void setDeposit(double amount)
{
blnce += amount;
ttlDpsts += amount;
}


public void setWithdraw(double amount)
{
blnce -= amount;
ttlWthdrw += amount;
}


public void calculateMonthlyInterest()
{
ttlIntrst = ttlIntrst + blnce * mnthlyIntrstRta;
blnce = blnce + blnce * mnthlyIntrstRta;
}


public double getBalance()
{
return blnce;
}

public double getAnnualInterestRate()
{
return annualInterestRate;
}

public double getMonthlyInterestRate()
{
return mnthlyIntrstRta;
}

public double getTotalDeposits()
{
return ttlDpsts;
}

public double getTotalWithdraws()
{
return ttlWthdrw;
}

public double getTotalnterest()
{
return ttlIntrst;
}


public void displayData()
{
blnce = Math.round(blnce * 100.0) / 100.0;
ttlIntrst = Math.round(ttlIntrst * 100.0) / 100.0;
System.out.println();
System.out.println(\"The ending blnce is: $\" + blnce);
System.out.println(\"Total amount of deposits: $\" + ttlDpsts);
System.out.println(\"Total amount of withdraws: $\" + ttlWthdrw);
System.out.println(\"Total interest earned: $\" + ttlIntrst);
}

}

Write necessary number of Java classes to implement the following functionalities and test it. Steps: Create a Java package with a name Quiz1 Create a Java clas
Write necessary number of Java classes to implement the following functionalities and test it. Steps: Create a Java package with a name Quiz1 Create a Java clas
Write necessary number of Java classes to implement the following functionalities and test it. Steps: Create a Java package with a name Quiz1 Create a Java clas

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site