Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: [10 points] Write a java program that performs the following: Create class named Customer that contains the following: Two private non-static data members:

Question 1: [10 points]

Write a java program that performs the following:

Create class named Customer that contains the following:

  • Two private non-static data members:
  1. name: represents the name of the customer and its type is String.
  2. category: represent the category of the customer and its type is integer. There are three categories: 1 for first class customers, 2 for second class customers, and 3 for third class customers.

  • Member methods as follows:
  1. Default constructor: initializes the name to no name and the category to 3.
  2. Parametrized constructor: receives two values for the name and category. Then, it initializes the received values in the name and category data members respectively.
  3. setName method: that receives a string value and sets the received value in the name data member.
  4. setCategory method: that receives an integer and sets the received value in the category data member.
  5. getName method: that returns the name of the customer.
  6. getCategory method: that returns the category of the customer.
  7. getDiscount method: that returns the discount given to customer. 30% discount is given to customers of category 1, 20% discount is given to customers of category 2, and 10% discount is given to customers of category 3.
  8. getStars method: that returns the number of stars given to customer. The number of stars depends on customer category. 3 stars (***) are given to customers of category 1, 2 stars (**) are given to customers of category 2, and 1 star (*) is given to customers of category 3.
  9. toString overridden method: that returns the following data: customer name, customer category, number of stars, and discount value.

Create class named Invoice that contains the following:

  • Three private non-static data members:
  1. invoiceID: represents the id of the invoice and its type is integer. The value of invoiceID is assigned the current value of the autoGeneratedInvoiceID.
  2. customer: represents the customer of the invoice and its type is Customer.
  3. amount: represents the amount of the invoice before discount and its type is double.

  • One private static data member:
  1. autoGeneratedInvoiceID: represents the auto-generated id of the invoice of type integer which is initialized to 0. For each time invoice object is created, autoGeneratedInvoiceID value is incremented automatically by 1 and the result is assigned to invoiceID.

  • Member methods as follows:
  1. Default constructor: initializes the customer with the default constructor of the Customer class and the amount to 0.0.
  2. Parametrized constructor: receives 2 values for customer object and amount. Then, it initializes the customer object using the received object and the received amount value in the amount data member.
  3. setCustomer method: that receives an object of type Customer and sets its value in the customer object.
  4. setAmount method: that receives a double value and sets the received value in the amount data member.
  5. getCustomer method: that returns the customer object of the invoice.
  6. getAmount method: that returns the amount of the invoice.
  7. getAmountAfterDiscount method: that returns the amount of the invoice after discount.
  8. toString overridden method: that returns the data members of the class in the following way:

invoice id, customer name, customer category, number of stars, discount value, amount of the invoice, amount of the invoice after discount. [Please, see sample output at end of page].

Create class named Demo that contains the main method. In the main method do the following:

  1. Create an array of 4 objects of type Customer. Ask the user to enter the values of the customer name and category. Fill the array with this data by using the parametrized constructor.
  2. Create an array of 4 objects of type Invoice. Ask the user to enter the value of the invoice amount. Fill the array with this data by using the parametrized constructor.

Input data:

image text in transcribed

  1. Change the name of the third customer to "Rami".
  2. Change the category of the first customer to 2.
  3. Change the amount value of the last invoice to 400.
  4. Print data of all invoices. I.e., invoice id, customer name, customer category, number of stars, discount value, amount of the invoice, amount of the invoice after discount. [Hint: you need to call toString method of Invoice class]. A sample output may look like this:

Sample Output:

image text in transcribed

System.out.print("Enter customer name: "); String name = input.next(); System.out.print ("Enter amount: "); double amount input.nextDouble(); System.out.print ("Enter customer category: "); int category input.nextInt (); Invoice-Id Customer-Name Category Stars Discount Amount Amount-After-Discount 2 1 1 2 3 4 Hikmat Talal Rami Ali 0.2 0.3 0.2 0.1 100.0 200.0 300.0 400.0 80.0 140.0 240.0 360.0 2 3

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_2

Step: 3

blur-text-image_3

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

Explain the operation of the TCP Sliding window

Answered: 1 week ago