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

700 karma points for this question. ( I posted the same question twice ) please

ID: 3631196 • Letter: 7

Question

700 karma points for this question. ( I  posted the same question twice )

 

please follow the instructions carfully, and make sure that it matches the sample output in the end.

thank you very much.

 

What This Assignment Is About: 

 

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 matinee tickets (integer),  number of normal tickets (integer), and total cost (double). Each matinee ticket costs $5.00 and each normal ticket costs $7.50. You need to compute the total cost based on the number of matinee tickets and normal tickets.

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 matinee tickets, and the number of normal tickets to 0, and the total cost to 0.0.

public Customer (String lname, String fname, int id, int matineeTickets, int normalTickets)

Constructs a Customer object given the last name, first name, customer id, the number of matinee tickets, the number of normal tickets. Its total cost should be updated by calling computeTotalCost( ) method.

public String getFirstName( )

Returns the first name.

public String getLastName()

Returns the last name.

public int getCustomerID()

Return the customer ID.

public int getMatineeTickets( )

Returns the number of matinee tickets

public int getNormalTickets( )

Returns the number of normal tickets.

public double getTotalCost()

Returns the total cost.

public void setFirstName (String fname)

Sets the first name.

public void setLastName (String fname)

Sets the last name.

public void setCustomerID(int id)

Sets the id.

public void setMatineeTickets(int matineeNum)

Sets the number of matinee tickets. Its total cost should be updated by calling computTotalCost( ) method.

public void setNormalTickets(int normalNum)

Sets the number of normal tickets. Its total cost should be updated by calling computeTotalCost( ) method.

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 matinee tickets and normal tickets (Each matinee ticket costs $5.00 and each normal ticket costs $7.50). This method will be called by other methods inside of the class Customer anytime the number of matinee tickets or normal tickets 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) 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 Matinee Ticket(s): 0
Number of Normal Ticket(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:MyJavapplications>java Assignment5 

******** Print the default value of customer's info: **********

 

First name: ???

Last name: ???

Customer ID: 0

Number of Matinee Ticket(s): 0

Number of Normal Ticket(s): 0

Total cost: $0.00

 

 

******** Print the first Customer's info: **********

 

First name: Bill

Last name: Gates

Customer ID: 888777888

Number of Matinee Ticket(s): 0

Number of Normal Ticket(s): 50

Total cost: $375.00

 

Enter customer's info:

First Name:

Steve

Last Name:

Jobs

ID #:

100000000

Number of Matinee Tickets:

234

Number of Normal Tickets:

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 matinee ticket(s): 234

customer2's normal ticket(s): 4

customer2's total cost: 1200.0

 

******** Print the second Customer's info: **********

 

First name: Steve

Last name: Jobs

Customer ID: 100000000

Number of Matinee Ticket(s): 234

Number of Normal Ticket(s): 4

Total cost: $1,200.00

 

 

********Print the customer who has higher total cost:*****

 

First name: Steve

Last name: Jobs

Customer ID: 100000000

Number of Matinee Ticket(s): 234

Number of Normal Ticket(s): 4

Total cost: $1,200.00

 

 

********Customer comparison******

customer1 and customer2 are different.

 

Enter customer's info:

First Name:

Bill

Last Name:

Gates

ID #:

888777888

Number of Matinee Tickets:

0

Number of Normal Tickets:

50

 

******** Print the second Customer's info using get methods:********

 

customer2's first name: Bill

customer2's last name: Gates

customer2's customer ID: 888777888

customer2's matinee ticket(s): 0

customer2's normal ticket(s): 50

customer2's total cost: 375.0

 

******** Print the second Customer's info: **********

 

First name: Bill

Last name: Gates

Customer ID: 888777888

Number of Matinee Ticket(s): 0

Number of Normal Ticket(s): 50

Total cost: $375.00

 

 

********Print the customer who has higher total cost:*****

 

First name: Bill

Last name: Gates

Customer ID: 888777888

Number of Matinee Ticket(s): 0

Number of Normal Ticket(s): 50

Total cost: $375.00

 

 

********Customer comparison******

customer1 and customer2 are the same customer.

 

Enter customer's info:

First Name:

David

Last Name:

Beckham

ID #:

555666777

Number of Matinee Tickets:

6

Number of Normal Tickets:

3

 

******** Print the second Customer's info using get methods:********

 

customer2's first name: David

customer2's last name: Beckham

customer2's customer ID: 555666777

customer2's matinee ticket(s): 6

customer2's normal ticket(s): 3

customer2's total cost: 52.5

 

******** Print the second Customer's info: **********

 

First name: David

Last name: Beckham

Customer ID: 555666777

Number of Matinee Ticket(s): 6

Number of Normal Ticket(s): 3

Total cost: $52.50

 

 

********Print the customer who has higher total cost:*****

 

First name: Bill

Last name: Gates

Customer ID: 888777888

Number of Matinee Ticket(s): 0

Number of Normal Ticket(s): 50

Total cost: $375.00

 

 

********Customer comparison******

customer1 and customer2 are different. 

 

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

Method

Description of the Method

public Customer( )

Default constructor sets the first name and last name to "???", customer ID, the number of matinee tickets, and the number of normal tickets to 0, and the total cost to 0.0.

public Customer (String lname, String fname, int id, int matineeTickets, int normalTickets)

Constructs a Customer object given the last name, first name, customer id, the number of matinee tickets, the number of normal tickets. Its total cost should be updated by calling computeTotalCost( ) method.

public String getFirstName( )

Returns the first name.

public String getLastName()

Returns the last name.

public int getCustomerID()

Return the customer ID.

public int getMatineeTickets( )

Returns the number of matinee tickets

public int getNormalTickets( )

Returns the number of normal tickets.

public double getTotalCost()

Returns the total cost.

public void setFirstName (String fname)

Sets the first name.

public void setLastName (String fname)

Sets the last name.

public void setCustomerID(int id)

Sets the id.

public void setMatineeTickets(int matineeNum)

Sets the number of matinee tickets. Its total cost should be updated by calling computTotalCost( ) method.

public void setNormalTickets(int normalNum)

Sets the number of normal tickets. Its total cost should be updated by calling computeTotalCost( ) method.

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 matinee tickets and normal tickets (Each matinee ticket costs $5.00 and each normal ticket costs $7.50). This method will be called by other methods inside of the class Customer anytime the number of matinee tickets or normal tickets 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) 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 Matinee Ticket(s): 0
Number of Normal Ticket(s): 50
Total cost: $375.00

Make use of the NumberFormat class to format the total cost.

Explanation / Answer

import java.text.DecimalFormat;

public class Customer {
private String firstName;
private String lastName;
private int customerID;
private int matineeTicket;
private int normalTicket;
private double totalCost;
private double MATINEECOST = 5.0;
private double NORMALCOST = 7.5;

public Customer( ){
firstName = "???";
lastName = "???";
customerID = 0;
matineeTicket = 0;
normalTicket = 0;
totalCost = 0.0;
}

public Customer (String lname, String fname, int id, int matineeTickets, int normalTickets){
firstName = fname;
lastName = lname;
customerID = id;
matineeTicket = matineeTickets;
normalTicket = normalTickets;
computeTotalCost();
}

public String getFirstName(){
return firstName;
}

public String getLastName(){
return lastName;
}

public int getCustomerID(){
return customerID;
}

public int getMatineeTickets( ){
return matineeTicket;
}

public int getNormalTickets( ){
return normalTicket;
}
public double getTotalCost(){
return totalCost;
}

public void setFirstName (String fname){
firstName = fname;
}

public void setLastName (String fname){
lastName = fname;
}

public void setCustomerID(int id){
customerID =id;
}

public void setMatineeTickets(int matineeNum){
matineeTicket = matineeNum;
computeTotalCost();
}

public void setNormalTickets(int normalNum){
normalTicket = normalNum;
computeTotalCost();
}

public boolean equals (Customer other){
boolean result=false;
if (customerID == other.customerID) result=true;
String myString = firstName;
if ((myString.equals(other.firstName))&&result) result=true;
myString = lastName;
if ((myString.equals(other.lastName))&&result) result=true;
return result;
}

private void computeTotalCost(){
totalCost = MATINEECOST * matineeTicket + NORMALCOST * normalTicket;
}

public Customer hasMore (Customer other){
Customer current = new Customer(firstName,lastName,customerID,matineeTicket,normalTicket);
if (current.totalCost >= other.totalCost) return current;
return other;
}

@Override
public String toString(){
DecimalFormat formatter = new DecimalFormat("$#,##0.00");
return "First Name: " + firstName + " Last Name: " + lastName + " Customer ID: "
+ customerID + " Number of Matinee Ticket(s): " + matineeTicket + " Number of Normal Ticket(s): " + normalTicket
+" Total Cost: " + formatter.format(totalCost)+" ";
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote