In Java Without any errors and the assignment class should n

In Java:-

Without any errors and the assignment class should not be changed and the customer class should be made depending on it only.

assignment class -

Part 2: 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), total cost (double), number of customers and total tickets (integer). The total tickets and total number of customers variables are used for the class to keep track of total number of tickets sold and total number of customers who ordered tickets, which means they are declared using the static modifier. Each matinee ticket costs $5.00 and each normal ticket costs $7.50. The total cost is computed based on the number of matinee tickets and normal tickets.

Topics:

Every student must work

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

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.

Constructs a Customer object given the last name, first name, customer id. The number of matinee ticket and normal tickets are assigned to zero.

Constructs a Customer object given the last name, first name, customer id, number of matinee ticket and number of normal tickets. You have to update total number of tickets too

Returns the first name.

Returns the last name.

Return the customer ID.

Returns the number of matinee tickets

Returns the number of normal tickets.

Returns the total cost.

Sets the first name.

Sets the last name.

Sets the id.

Sets the number of matinee tickets. You need to add the matinee tickets to your total tickets too.

Sets the number of normal tickets. You need to add the normal tickets to your total tickets.

Returns the total number of tickets sold so far (matinee and normal)

Returns the total number of customers so far

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

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.

Compares the total number of tickets for 2 customers and returns the Customer who has more tickets. If the total tickets are same, the first customer is returned.

Returns a String with information on each Customer using the following format:

First name: Grace
Last name: Hopper
Customer ID: 888777888 Number of Matinee Ticket(s): 10 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. Use Assignment6.java class posted on Blackboard under homework 6, which has the main method to create new Customer objects and to test your class.

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 (Assignment6.java) that is provided. You should never change the test driver program if the test driver is provided but instead make changes to your class to make it work.

A sample output is shown below.

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

Sample Output:

******** 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

******** Customer\'s info: ********** First Name: Grace
Last Name: Hopper
Customer ID: 12345

Number of Matinee Ticket(s): 0 Number of Normal Ticket(s): 30 Total Cost: $225.00

******** Customer\'s info: ********** First Name: Smith
Last Name: Megan
Customer ID: 555666777

Number of Matinee Ticket(s): 0 Number of Normal Ticket(s): 0 Total Cost: $0.00

Enter customer\'s info:
First Name: Ginni
Last Name: Rometty
ID #: 345543
Number of Matinee Tickets: 12 Number of Normal Tickets: 13

******** Customer\'s info using get methods:********

First name: Ginni Last name: Rometty Customer ID: 345543 Matinee ticket(s): 12 Normal ticket(s): 13 Total cost: 157.5

******** Customer\'s info: ********** First Name: Ginni
Last Name: Rometty
Customer ID: 345543

Number of Matinee Ticket(s): 12

Number of Normal Ticket(s): 13 Total Cost: $157.50

*******Customer who has more tickets:***** First Name: Grace
Last Name: Hopper
Customer ID: 12345

Number of Matinee Ticket(s): 0 Number of Normal Ticket(s): 30 Total Cost: $225.00

********First comparison****** customer2 and customer3 are different.

********Second comparison******
customer2 and customer3 are the same customer.

**************
Total number of customers: 3 Total number of tickets: 80

Press any key to continue . . .

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)  

Constructs a Customer object given the last name, first name, customer id. The number of matinee ticket and normal tickets are assigned to zero.

  public Customer (String lname,  String fname, int id, int  initMatinee, int initNormal )  

Constructs a Customer object given the last name, first name, customer id, number of matinee ticket and number of normal tickets. You have to update total number of tickets too

  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. You need to add the matinee tickets to your total tickets too.

  public void setNormalTickets(int  normalNum)  

Sets the number of normal tickets. You need to add the normal tickets to your total tickets.

  public static int getTickets()  

Returns the total number of tickets sold so far (matinee and normal)

  public static int getNumCustomers()  

Returns the total number of customers so far

  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 number of tickets for 2 customers and returns the Customer who has more tickets. If the total tickets are same, the first customer is returned.

  public String toString( )  

Returns a String with information on each Customer using the following format:

First name: Grace
Last name: Hopper
Customer ID: 888777888 Number of Matinee Ticket(s): 10 Number of Normal Ticket(s): 50 Total cost: $375.00

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

Solution

/********************************************************************
// Title: Customer.java
// Author: CSE110 instructor
// Description: a program for class Customer
// Class Time & Lab Letter:
// Time spent:
// Date:
//********************************************************************/
class Customer
{
    //instance variables
    String first_name;
    String last_name;
    int id;
    int no_matineeTickets;
    int no_normalTickets;
    double total_cost;
    static int no_customers;
    static int total_tickets;
    final double cost_matinee=5;
    final double cost_normal=7.50;
  
    //default contructor
    public Customer()
    {
        first_name=\"\";
        last_name=\"\";
        id=0;
        no_matineeTickets=0;
        no_normalTickets=0;
        total_cost=0;
        no_customers++;
    }
  
    //parametrized constructor
    public Customer (String lname,String fname, int id)
    {
        first_name=fname;
        last_name=lname;
        this.id=id;
        no_matineeTickets=0;
        no_normalTickets=0;
        no_customers++;
    }
  
    //parametrized constructor
    public Customer (String lname,String fname, int id, int initMatinee, int initNormal )
    {
        first_name=fname;
        last_name=lname;
        this.id=id;
        no_matineeTickets=initMatinee;
        no_normalTickets=initNormal;
        total_tickets+=no_matineeTickets+no_normalTickets;
        computeTotalCost();
        no_customers++;
    }
  
    //get first name
    public String getFirstName( )
    {
        return first_name;
    }
  
    //get last name
    public String getLastName( )
    {
        return last_name;
    }
  
    //get customer id
    public int getCustomerID()
    {
        return id;
    }
  
    //get matines tickets
    public int getMatineeTickets( )
    {
        return no_matineeTickets;
    }
  
    //get normal tickets
    public int getNormalTickets( )
    {
        return no_normalTickets;
    }
  
    //get total cost
    public double getTotalCost()
    {
        return total_cost;
    }
  
    //set first name
    public void setFirstName (String fname)
    {
        first_name=fname;
    }
  
    //sets last name
    public void setLastName (String fname)
    {
        last_name=fname;
    }
  
    //set customer id
    public void setCustomerID(int id)
    {
        this.id=id;
    }
  
    //sets matinee tickets
    public void setMatineeTickets(int matineeNum)
    {
        no_matineeTickets=matineeNum;
        total_tickets=+no_matineeTickets;
        computeTotalCost();
    }
  
    //set normal tikctes
    public void setNormalTickets(int normalNum)
    {
        no_normalTickets=normalNum;
        total_tickets=+no_normalTickets;
        computeTotalCost();
    }
  
    //get no of tikcets
    public static int getTickets()
    {
        return total_tickets;
    }
  
    //get no of customers
    public static int getNumCustomers()
    {
        return no_customers;
    }
  
    //compare customer with other object
    public boolean equals (Customer other)
    {
        if(id==other.id && first_name.equals(other.first_name) && last_name.equals(other.last_name))
        return true;
        else
        return false;
    }
  
    //cal total cost
    private void computeTotalCost( )
    {
        total_cost=no_matineeTickets*cost_matinee + no_normalTickets*cost_normal;
    }
  
    //check whether there are customers
    public Customer hasMore (Customer other)
    {
        if(total_tickets>=other.total_tickets)
        return this;
        else return other;
    }
  
    //display custome details
    public String toString( )
    {
        return \"First name: \"+first_name+\"\ Last name: \"+last_name+\"\ Customer ID: \"+id+\"\ Number of Matinee Ticket(s): \"+no_matineeTickets+\"\ Number of Normal Ticket(s): \"+no_normalTickets+\"\ Total cost: $\"+total_cost;
    }
}

In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part
In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part
In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part
In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part
In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part
In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part
In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part
In Java:- Without any errors and the assignment class should not be changed and the customer class should be made depending on it only. assignment class - Part

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site