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

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

ID: 3835778 • Letter: W

Question

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 don’t 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!");

   }
}

Explanation / Answer

Here is the code for Order.java:

class Order
{
    // the sales tax rate for that Order
    double salesTaxRate;
    //the subtotal cost of the Order
    double subtotalCost;
    //the shipping cost for that Order
    double shippingCost;
    //the sales tax for that Order
    double salesTax;
    //the total cost for the Order
    double totalCost;
    //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.
    public Order(double sTaxRate)
    {
       salesTaxRate = sTaxRate;
    }
    //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
    public void setCost(double cost)
    {
       subtotalCost = cost;
       salesTax = salesTaxRate * subtotalCost;
       if(cost >= 0.0 && cost <= 50)
           shippingCost = 0.08 * cost;
       else
           shippingCost = 0.0;  
       totalCost = subtotalCost + salesTax + shippingCost;
    }
    //d) Include a method named getTotalCost that returns the value of the total cost for the Order.
    public double getTotalCost()
    {
       return totalCost;
    }  
}

And the code for Customer.java:

class Customer
{
    //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.
    String firstName;
    String lastName;
    int customerCode;
    Order[] order;
    //b) Include a constructor which allows the client to initialize a Customer with a
    //specific first and last name and a specific customer code.
    public Customer(String fName, String lName, int code, Order[] od)
    {
       firstName = fName;
       lastName = lName;
       customerCode = code;
       order = new Order[od.length];
       for(int i = 0; i < od.length; i++)
           order[i] = od[i];
    }
    //c) Include one method named toString. It should produce a string that is formatted
    //as shown below (note: I don’t care about font or bolding… just give it this basic
    //structure) : CUSTOMER INFORMATION Name : Id Code :
    public String toString()
    {
       return "CUSTOMER INFORMATION Name : " + firstName + " " + lastName + " Id Code : " + customerCode;
    }
    //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.)
    public double AveragePayment()
    {
       double avg = 0.0;
       for(int i = 0; i < order.length; i++)
           avg += order[i].getTotalCost();
       return avg / order.length;  
    }
}

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