Question

In: Computer Science

You will write several classes for this program in Java. The name of all classes for...

You will write several classes for this program in Java. The name of all classes for this program will start with y2y3.

Concepts to be applied :

Classes and objects, inheritance, polymorphism

Assignment:

An electronic store, named carrefoure, services many customers. The customers’ orders for electronics are delivered. Carrefoure bills their customers once each month. At the end of each month, the regional store manager requests a report of all customers. In this program, you will develop the inheritance hierarchy for the program. The set of classes developed for the program will be used for future assignments.

            The superclass for this assignment will represent a Customer of Carrefoure.

            Some of the Customers will be tax exempt customers (will not pay taxes on the) but others will be non tax exempt customers (will pay tax on the bill balance at a given percent).

            The fields are the instance variables of the classes in the hierarchy:

  • Customer name (String)
  • Customer ID (numeric integer)

o            phone number (numeric integer)

o            Amount paid (numeric)

o            Reason for tax exemption (only for tax-exempt-customers) – String, for example: education, non-profit, etc

o            Tax percent (only for non-tax-exempt customers) – decimal, for example: .08 for 8%, .075 for 7.5%

The customers served by careffoure are of two types: tax-exempt or non-tax-exempt. The tax-exempt customer will have an instance field to store the reason for the tax exemptions: education, non-profit, government, other (String). The non-tax exempt customers, will have an instance field to store the percent of tax that the customer will pay (numeric) on the bill balance.

From the information provided, write a solution that includes the following:

A suitable inheritance hierarchy which represents the customers serviced by the office supply company. There should be 3 classes for this program. I suggest a Customer class and two suitable subclasses. The tax percent field only applies for a non-tax exempt customer. The reason for tax exemption only applies to a tax exempt customer.  

            For all classes include the following:

o            Instance variables

o            Constructors

o            Accessor and mutator methods

o            Suitable toString() methods

Write a class y2y3 which does the following in the main method:

            Create two objects for customers who are tax exempt and create two objects for customers who are non-tax exempt.

            Print all the information about the objects as shown below:

Output:

Non tax exempt customers:

1 PWC   $750   18002500830     0.08%   $60

2 E&Y   $970    18003409845     0.08%   $77.6

Tax exempt customers:

3 AHS   $255.50     19734508345             Non-profit

4 PIO      $500        18002708855           Non-profit

Solutions

Expert Solution

Here this question is very simple but there is one thing that i didn't get is in the output of non tax exempt customers like for first customer $750*0.08% = $0.6 not $60. Also what i understand is the only main class needs to be named as y2y3 not all class needs to prepend this one.

Now coming to the solution, since we are not going to create instance of customer class directly we can make that class as abstract class and all the fields are instance one hence every time we create object of inherited class value of those common fields in parent class will hold different value.

Below is the Customer class :

public abstract class Customer {
    private String custName;
    private int custId;
    private long custPhoneNum;
    private double amountPaid;

    public Customer(String custName, int custId, long custPhoneNum, double amountPaid) {
        this.custName = custName;
        this.custId = custId;
        this.custPhoneNum = custPhoneNum;
        this.amountPaid = amountPaid;
    }

    public String getCustName() {
        return custName;
    }

    public void setCustName(String custName) {
        this.custName = custName;
    }

    public int getCustId() {
        return custId;
    }

    public void setCustId(int custId) {
        this.custId = custId;
    }

    public long getCustPhoneNum() {
        return custPhoneNum;
    }

    public void setCustPhoneNum(long custPhoneNum) {
        this.custPhoneNum = custPhoneNum;
    }

    public double getAmountPaid() {
        return amountPaid;
    }

    public void setAmountPaid(double amountPaid) {
        this.amountPaid = amountPaid;
    }

    @Override
    public String toString() {
        return custId+" " +custName +" $"+amountPaid+" "+custPhoneNum;
    }
}

class for taxExemptCustomer :

public class TaxExemptCustomer extends Customer{
    private String reason;

    public TaxExemptCustomer(String custName, int custId, long custPhoneNum, double amountPaid, String reason) {
        super(custName, custId, custPhoneNum, amountPaid);
        this.reason = reason;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    @Override
    public String toString() {
        return super.toString()+ " "+reason;
    }
}

class for NonTaxExemptCustomer :

public class NonTaxExemptCustomer  extends Customer{
    private double taxPer;

    public NonTaxExemptCustomer(String custName, int custId, long custPhoneNum, double amountPaid, double taxPer) {
        super(custName, custId, custPhoneNum, amountPaid);
        this.taxPer = taxPer;
    }

    public double getTaxPer() {
        return taxPer;
    }

    public void setTaxPer(double taxPer) {
        this.taxPer = taxPer;
    }

    @Override
    public String toString() {
        double taxPaid = (getAmountPaid()*taxPer)/100;
        String res = String.format("%.2f", taxPaid);
        return super.toString()+" " + taxPer+" $"+res;
    }
}

main class Y2Y3 :

public class Y2Y3 {

    public static void main(String args[]) {
        Customer taxExempt1 = new TaxExemptCustomer("AHS", 3, 19734508345L, 255.50, "Non-profit");
        Customer taxExempt2 = new TaxExemptCustomer("PIO", 4, 18002708855L, 500, "Non-profit");
        Customer nonTaxExempt1 = new NonTaxExemptCustomer("PWC", 1, 18002500830L, 750, 0.08d);
        Customer nonTaxExempt2 = new NonTaxExemptCustomer("E&Y", 2, 18003409845L, 970, 0.08);
        System.out.println("Non tax exempt customers:");
        System.out.println(nonTaxExempt1);
        System.out.println(nonTaxExempt2);
        System.out.println("Tax exempt customers:");
        System.out.println(taxExempt1);
        System.out.println(taxExempt2);
    }
}

Related Solutions

Write a program in Java Swing that can Display all the name list then will generate...
Write a program in Java Swing that can Display all the name list then will generate and display the longest name out of a list of names. Thank you...
Write a Java program to do the following with your name. This can all be done...
Write a Java program to do the following with your name. This can all be done in the main() method. 1. Create a String variable called myName and assign your personal name to it. Use proper capitalization for a legal name. I.e. String myName = "Billy Bob"; 2. Load myName with the upper case version of itself and display the result. 3. Load myName with the lower case version of itself and display the result. 4. Capitalize the first letter...
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
Write a program in java that asks the name of the buyer and the number of...
Write a program in java that asks the name of the buyer and the number of shares bought. Your program must then calculate and display the following. sold stock/shares to the general public at the rate of $24.89 per share. Theres a 2 percent (2%) commission for the transaction. Outputs need Amount paid for buying the stock ($) Amount paid for the commission ($) Total amount ($)
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write a Java Program using the concept of objects and classes. Make sure you have two...
Write a Java Program using the concept of objects and classes. Make sure you have two files Employee.java and EmployeeRunner.java. Use the template below for ease. (Please provide detailed explanation) Class Employee Class Variables: Name Work hour per week Hourly payment Class Methods: - Get/Sets - generateAnnualSalary(int:Duration of employment)               annual salary = Hourly payment * Work hours per week * 50 If the employee is working for more than 5 years, 10% added bonus             -void displayAnnualSalary ( )...
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel....
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel. A dog consists of the following information: • An integer age. • A string name. If the given name contains non-alphabetic characters, initialize to Wolfy. • A string bark representing the vocalization the dog makes when they ‘speak’. • A boolean representing hair length; true indicates short hair. • A float weight representing the dog’s weight (in pounds). • An enumeration representing the type...
Write a complete Java program to print out the name bob
Write a complete Java program to print out the name bob
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT