Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class named Order. An Order is described by: the sales tax rate for that Order the subtotal cost of the Order the shipping

Write a class named Order. An Order is described by: the sales tax rate for that Order the subtotal cost of the Order the shipping cost for that Order the sales tax for that Order the total cost for the Order b) Include a constructor method. The constructor should allow the user of the class to set the sales tax rate. Other fields should be set to zero. c) Include a method setCost that defines the value for the subtotal cost of the Order. It then computes the sales tax on that order, computes the shipping costs according to the rule given below and computes the total cost for that Order. Shipping cost is computed by: If you spend: Your shipping charge is $0.00 $ 50 8% of the subtotal order cost Over $50.00 Shipping is free d) Include a method named getTotalCost that returns the value of the total cost for the Order. 2.( 20 pts) Now you will create a Customer class. a) Write a class called Customer that stores two fields, one to store the first name of a person and another to store the last name of a person. It also stores a customer code number for each customer. b) Include a constructor which allows the client to initialize a Customer with a specific first and last name and a specific customer code. c) Include one method named toString. It should produce a string that is formatted as shown below (note: I dont care about font or bolding just give it this basic structure) : CUSTOMER INFORMATION Name : Id Code : 3.Modify the Customer class by adding a list of past Orders. That is, your class should be able to hold a list of the past Orders the Customer has had with your company. The constructor should be modified so the user can initialize this history. Do not worry about memory allocation that will be the responsibility of the user of the class (you can see that Tester.java allocates memory for this list ). 4. Write a method named AveragePayment for the Customer class. This method will produce the average of all the past purchases (ie. the average of all the total costs of all the Orders for that Customer.)

Tester.java

import java.text.NumberFormat; import java.util.Scanner;

public class Tester { public static void main(String[] args) {

double avgPurchase;

Order[] lastYear = new Order[4];

// I bought most stuff in Pennsylvania but.. lastYear[0] = new Order(0.06); lastYear[1] = new Order(0.06); // I did send one thing to my mom in New York City and had to pay their sales tax... lastYear[2] = new Order(0.09); lastYear[3] = new Order(0.06);

lastYear[0].setCost(57.93); lastYear[1].setCost(257.93); lastYear[2].setCost(100.30); lastYear[3].setCost(15.67);

Customer me = new Customer("Kendall" , "Martin" , 12321, lastYear);

// okay! ready to go !

System.out.println( me );

avgPurchase = me.AveragePayment(); NumberFormat fmt = NumberFormat.getCurrencyInstance();

System.out.println( "has spent an average of " + fmt.format(avgPurchase) + " per purchase."); System.out.println (" psst... if you got $115.50 , you must have it! Congratulations!");

} }

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions