Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anybody help me finsh this java work? To help me create Assignment5.java and Customer.java? Thank you! What This Assignment Is About: Implementing classes Understanding

Can anybody help me finsh this java work? To help me create Assignment5.java and Customer.java? Thank you!

What This Assignment Is About:

Implementing classes

Understanding and accessing instance variables

Implementing methods

Object construction

Constructors

Encapsulation

Use the following Coding Guidelines:

Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).

User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.

Use white space to make your program more readable.

Part 2: (There is no part 1 in this assignment) Programming (20 points)

Your assignment is to create a file called Customer.java containing a class Customer (there is no main method in this class). A Customer has a first name (a String), last name (String), ID number (integer), number of larger drinks (integer), number of small drinks (integer), and total cost (double). Each large drink costs $8.50 and each small drink costs $4.50. You need to compute the total cost based on the number of large drinks and small drinks.

The class Customer must include the following constructors and methods. (If your class does not contain any of the following methods, points will be deducted.)

Method

Description of the Method

public Customer( )

Default constructor sets the first name and last name to "???", customer ID, the number of large drinks, and the number of small drinks to 0, and the total cost to 0.0.

public Customer (String lname, String fname, int id, int largeDrinks, intsmallDrinks)

Constructs a Customer object given the last name, first name, customer id, the number of large drinks, the number of small drinks.

public String getFirstName( )

Returns the first name.

public String getLastName()

Returns the last name.

public int getCustomerID()

Return the customer ID.

public int getLargeDrinks( )

Returns the number of large drinks

public int getSmallDrinks( )

Returns the number of small drinks.

public double getTotalCost()

Returns the total cost.

public void setFirstName (String fname)

Sets the first name.

public void setLastName (String lname)

Sets the last name.

public void setCustomerID(int id)

Sets the id.

public void setLargeDrinks(intlargeNum)

Sets the number of large drinks. It should also call computeTotalCost() method to update its total cost.

public void setSmallDrinks(intsmallNum)

Sets the number of small drinks. It should also call computeTotalCost() method to update its total cost.

public boolean equals (Customer other)

Returns true if the ids and names are the same, return false otherwise.

private void computeTotalCost( )

This is a helper (service) method that computes the total cost based on the number of large drinks and small drinks (Each large drink costs $8.50 and each small drink costs $4.50). This method will be called by other methods inside of the class Customer anytime the number of large drinks or small drinks is updated.

public Customer hasMore (Customer other)

Compares the total costs of two customers and returns the Customer who has a higher total cost. If the total costs are same, the first customer (itself, i.e., thisreference) is returned.

public String toString( )

Returns a String with information on each Customer using the following format: First name: Bill Last name: Gates Customer ID: 888777888 Number of Large Drink(s): 0 Number of Small Drink(s): 50 Total cost: $375.00 Make use of the NumberFormat class to format the total cost.

Save the Customer class in a file called Customer.java and use the following program stored in Assignment5.java, which has the main method to create new Customer objects and to test your class. A sample output is shown below.

Important Notes: Your class should have exactly the method headers that are described or otherwise your class will not work with the test driver program (Assignment5.java) that is provided. You should never change the test driver program if the test driver is provided but instead make changes to Customer class to make it work.

Helpful hints for doing this assignment:

work on it in steps. Write one method, test it with a test driver and make sure it works before going on to the next method

always make sure your code compiles before you add another method

your methods should be able to be called in any order

After compiling Customer.java file and Assignment5.java file, you need to execute Assignment5 class.

Sample Output: (the inputs entered by a user are shown in bold)

C:\MyJava\applications>java Assignment5 ******** Print the default value of customer's info: ********** First name: ??? Last name: ??? Customer ID: 0 Number of Large Drink(s): 0 Number of Small Drink(s): 0 Total cost: $0.00 ******** Print the first Customer's info: ********** First name: Bill Last name: Gates Customer ID: 1234567890 Number of Large Drink(s): 50 Number of Small Drink(s): 0 Total cost: $425.00 Enter customer's info: First Name: Steve Last Name: Jobs ID #: 100000000 Number of Large Drinks: 234 Number of Small Drinks: 4 ******** Print the second Customer's info using get methods:******** customer2's First Name: Steve customer2's Last Name: Jobs customer2's Customer ID: 100000000 customer2's Large Drink(s): 234 customer2's Small Drink(s): 4 customer2's Total Cost: 2007.0 ******** Print the second Customer's info: ********** First name: Steve Last name: Jobs Customer ID: 100000000 Number of Large Drink(s): 234 Number of Small Drink(s): 4 Total cost: $2,007.00 ********Print the customer who has higher total cost:***** First name: Steve Last name: Jobs Customer ID: 100000000 Number of Large Drink(s): 234 Number of Small Drink(s): 4 Total cost: $2,007.00 ********Customer comparison****** customer1 and customer2 are different. Enter customer's info: First Name: Bill Last Name: Gates ID #: 1234567890 Number of Large Drinks: 0 Number of Small Drinks: 50 ******** Print the second Customer's info using get methods:******** customer2's First Name: Bill customer2's Last Name: Gates customer2's Customer ID: 1234567890 customer2's Large Drink(s): 0 customer2's Small Drink(s): 50 customer2's Total Cost: 225.0 ******** Print the second Customer's info: ********** First name: Bill Last name: Gates Customer ID: 1234567890 Number of Large Drink(s): 0 Number of Small Drink(s): 50 Total cost: $225.00 ********Print the customer who has higher total cost:***** First name: Bill Last name: Gates Customer ID: 1234567890 Number of Large Drink(s): 50 Number of Small Drink(s): 0 Total cost: $425.00 ********Customer comparison****** customer1 and customer2 are the same customer.

------------------------------------------------------------------------

For this and all subsequent assignments, provide a heading (in comments) including:

The assignment number.

Its author (your name).

Your Lab Letter.

A description of what this program is doing.

Grading Criteria for the part 2:

1 pt : Each file (Customer.java file and Assignment5.java file) contains header information (the assignment number, your name, lab letter, a description of each file.

2 pts: adequate comment to explain every method

1 pt: consistent indentation and spacing

2 pts: it compiles

3 pts total (0.5 pt each): The instance variables are declared correctly (lastName, firstName, customerID, largeDrinks, smallDrinks, totalCost)

1 pt: The Constructor, Customer( ) is correct

1 pt: The Constructor, Customer(String, String, int, int, int) is correct

2.5 pts total (0.5 pt each): The modifier methods (setLastName, setFirstName, setCustomerID, setLargeDrinks, setSmallDrinks) are correct

2.5 pts total (0.5 pt each): The accessor methods (getLastName, getFirstName, getCustomerID, getLargeDrinks, getSmallDrinks) are correct

1 pt: The method computeTotalCost( ) is correct

1 pt: The method equals(Customer) is correct

1 pt: The method hasMore(Customer) is correct

1 pt: The method toString() is correct including the dollar formatting

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions