Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a MAIN PROGRAM IN JAVA that test the features of Client and ClientList classes according to program given below Client: import java.util.*; import java.lang.*;

Create a MAIN PROGRAM IN JAVA that test the features of Client and ClientList classes according to program given below

Client:

import java.util.*;

import java.lang.*;

import java.io.*;

public class Client implements Serializable{

private static final long serialVersionUID = 1L;

public static final String CLIENT_STRING = "C";

private String Client_name;

private String Client_id;

private String Client_phone;

private String Client_address;

private Double Client_billing;

private List waitlistedProducts = new LinkedList();

public Client(String Name, String phone, String address, Double billing)

{

this.Client_name = Name;

this.Client_phone = phone;

this.Client_address = address;

this.Client_billing = billing;

Client_id = CLIENT_STRING + (ClientIDServer.instance()).getID();//generates id through the client id server

}

public String getName()

{

return Client_name;

}

public String getAddress()

{

return Client_address;

}

public String getPhone()

{

return Client_phone;

}

public Double getBilling()

{

return Client_billing;

}

public Double updateBalance(Double orderPrice)

{

this.Client_billing = Client_billing - orderPrice;

return Client_billing;

}

public String getID()

{

return Client_id;

}

public ClientOrder newOrder()

{

ClientOrder order = new ClientOrder();

return order;

}

public boolean addProductToWaitlist(Waitlist w){

return waitlistedProducts.add(w);

}

public boolean removeWaitlistedProduct(Waitlist w)

{

return waitlistedProducts.remove(w);

}

public Iterator getWaitlistedProducts()

{

return waitlistedProducts.iterator();

}

public Waitlist searchWaitListOnProduct(Product p)

{

Iterator iterator = waitlistedProducts.iterator();

Waitlist w;

while (iterator.hasNext())

{

w = iterator.next();

if (w.getProduct() == p)

{

return w;

}

}

return null;

}

public String toString()

{

return "Client: " + getName() + ". Phone: " + getPhone()+ ". ID: "+ getID()+". Address: "+getAddress() + " Balance: $" + getBilling();

}

}

ClientList:

import java.util.*;

import java.io.*;

public class ClientList implements Serializable{

private static final long serialVersionUID = 1L;

private List clients = new LinkedList();

private List Orders = new LinkedList();

private static ClientList clientList;

private ClientList(){

}

public static ClientList instance()

{

if (clientList == null)

{

return (clientList = new ClientList());

}

else

{

return clientList;

}

}

public boolean insertClient(Client Clients)

{

clients.add(Clients);

return true;

}

public Iterator getClients()

{

return clients.iterator();

}

public Client search(String clientID) {

for (Iterator iterator = clients.iterator(); iterator.hasNext(); ) {

Client client = (Client) iterator.next();

if (client.getID().equals(clientID)) {

return client;

}

}

return null;

}

private void writeObject(java.io.ObjectOutputStream output)

{

try{

output.defaultWriteObject();

output.writeObject(clientList);

}catch(IOException ioe){

ioe.printStackTrace();

}

}

private void readObject(java.io.ObjectInputStream input)

{

try{

if(clientList != null)

{

return;

}

else

{

input.defaultReadObject();

if(clientList == null)

{

clientList = (ClientList) input.readObject();

}

else

{

input.readObject();

}

}

}catch(IOException ioe){

ioe.printStackTrace();

}catch(ClassNotFoundException cnfe){

cnfe.printStackTrace();

}

}

public String toString()

{

return clients.toString();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions