Question

Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 PreferredCustomer Class (need to create Person, Customer classes descri
A6 7. Person and Customer Classes esign a class named Person with fields for holding a persons name, address, and telephone
0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here are the complete code with output sample.

Comments given for all important line of code, let me know in case you need any help or have questions.

===========================================================================

public class Person {

    private String name;
    private String address;
    private String telephone;

    public Person() {
        this.name = "";
        this.address = "";
        this.telephone = "";
    }


    public Person(String name, String address, String telephone) {
        this.name = name;
        this.address = address;
        this.telephone = telephone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
}

===========================================================================

public class Customer extends Person {

    private int customerNumber;
    private boolean inMailingList;

    public Customer(int number) {
        this.customerNumber = number;
        this.inMailingList = true;
    }

    public Customer(int customerNumber, boolean inMailingList) {
        this.customerNumber = customerNumber;
        this.inMailingList = inMailingList;
    }

    public Customer(String name, String address, String telephone, int customerNumber, boolean inMailingList) {
        super(name, address, telephone);
        this.customerNumber = customerNumber;
        this.inMailingList = inMailingList;
    }

    public int getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(int customerNumber) {
        this.customerNumber = customerNumber;
    }

    public boolean isInMailingList() {
        return inMailingList;
    }

    public void setInMailingList(boolean inMailingList) {
        this.inMailingList = inMailingList;
    }
}

===========================================================================

public class PreferredCustomer extends Customer {

    private double purchaseAmount;
    private double discount;

    public PreferredCustomer(int number) {
        super(number);
        purchaseAmount=0;
        discount=getDiscount();
    }

    public PreferredCustomer(int customerNumber, boolean inMailingList) {
        super(customerNumber, inMailingList);
        purchaseAmount=0;
        discount=getDiscount();
    }

    public PreferredCustomer(String name, String address, String telephone, int customerNumber, boolean inMailingList) {
        super(name, address, telephone, customerNumber, inMailingList);
        purchaseAmount=0;
        discount=getDiscount();
    }

    public void setPurchaseAmount(double purchaseAmount) {
        this.purchaseAmount = purchaseAmount;
        discount=getDiscount();
    }
    // logic to determine the discount given to customer
    private double getDiscount(){
        if(purchaseAmount>=2000)return 10;
        if(purchaseAmount>=1500)return 7;
        if(purchaseAmount>=1000)return 6;
        if(purchaseAmount>=500)return 5;
        return 0;
    }
    // amount purchased by customer
    public double getPurchaseAmount() {
        return purchaseAmount;
    }
    // amount charged to customer after discount
    public double getPayableAmount(){
        return (100-getDiscount())*purchaseAmount/100.0;
    }
    // discounted amount
    public double getTotalDiscount(){
        return (getDiscount())*purchaseAmount/100.0;
    }

    // prints the receipt of the customer
    public void printBill(){
        System.out.println("Name                : "+getName());
        System.out.println("Address             : "+getAddress());
        System.out.println("Telephone           : "+getTelephone());
        System.out.println("Total Purchase Amount $"+getPurchaseAmount());
        System.out.println("Discount (%)Availed : "+getDiscount()+"%");
        System.out.println("Total Discount      : $"+getTotalDiscount());
        System.out.println("Total Amount Payable: $"+getPayableAmount());

    }
}

===========================================================================

public class PreferredCustomer extends Customer {

    private double purchaseAmount;
    private double discount;

    public PreferredCustomer(int number) {
        super(number);
        purchaseAmount=0;
        discount=getDiscount();
    }

    public PreferredCustomer(int customerNumber, boolean inMailingList) {
        super(customerNumber, inMailingList);
        purchaseAmount=0;
        discount=getDiscount();
    }

    public PreferredCustomer(String name, String address, String telephone, int customerNumber, boolean inMailingList) {
        super(name, address, telephone, customerNumber, inMailingList);
        purchaseAmount=0;
        discount=getDiscount();
    }

    public void setPurchaseAmount(double purchaseAmount) {
        this.purchaseAmount = purchaseAmount;
        discount=getDiscount();
    }
    // logic to determine the discount given to customer
    private double getDiscount(){
        if(purchaseAmount>=2000)return 10;
        if(purchaseAmount>=1500)return 7;
        if(purchaseAmount>=1000)return 6;
        if(purchaseAmount>=500)return 5;
        return 0;
    }
    // amount purchased by customer
    public double getPurchaseAmount() {
        return purchaseAmount;
    }
    // amount charged to customer after discount
    public double getPayableAmount(){
        return (100-getDiscount())*purchaseAmount/100.0;
    }
    // discounted amount
    public double getTotalDiscount(){
        return (getDiscount())*purchaseAmount/100.0;
    }

    // prints the receipt of the customer
    public void printBill(){
        System.out.println("Name                : "+getName());
        System.out.println("Address             : "+getAddress());
        System.out.println("Telephone           : "+getTelephone());
        System.out.println("Total Purchase Amount $"+getPurchaseAmount());
        System.out.println("Discount (%)Availed : "+getDiscount()+"%");
        System.out.println("Total Discount      : $"+getTotalDiscount());
        System.out.println("Total Amount Payable: $"+getPayableAmount());

    }
}

===========================================================================

thanks a lot !

Add a comment
Know the answer?
Add Answer to:
Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 "PreferredCustomer Class" (need to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is java m. please use netbeans if you can. 7. Person and Customer Classes Design...

    this is java m. please use netbeans if you can. 7. Person and Customer Classes Design a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the cus- tomer wishes to...

  • This must be written in C# with overloaded constructors and member initialization list 4. Person and...

    This must be written in C# with overloaded constructors and member initialization list 4. Person and Customer Classes Design a class named Person with properties for holding a person's name, address, and telephone number. Next, design a class named Customer, which is derived from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether the customer wishes to be on a mailing list. Demonstrate an object of the Customer class...

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

    Design a class named Person with fields for holding a person's name, address, and telephone number (all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes...

  • Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...

    Using JAVA* Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator...

  • JAVA HELP Design a class named Employee. The class should keep the following information in fields:...

    JAVA HELP Design a class named Employee. The class should keep the following information in fields: Employee name Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. Hire date then, Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to...

  • Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing...

    Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the...

  • HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh...

    HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh DESCRIPTION Objectives To write a classes based on sets of specifications To write a main class to be used in a multi-class Java program To use inheritance to extend a class (optional, EC) To override methods in subclasses (optional, EC) Groups You may work with a partner on this assignment. A header comment (In every Java file) should include authors (group members) and collaborators...

  • LO 10-6, 10 10-36 Based on an assessment of audit risk, the auditors are concerned with...

    LO 10-6, 10 10-36 Based on an assessment of audit risk, the auditors are concerned with the following two risks: 1. The risk that that the client might be making duplicate payments to vendors. 2. The risk that the client's accounting clerk might be making unauthorized payments to himself. a. Assuming that the client has a manual accounting system, describe how the auditors can design a test to identify the duplicate payments and unauthorized payments. b. Assuming that the client...

  • And there was a buy-sell arrangement which laid out the conditions under which either shareholder could...

    And there was a buy-sell arrangement which laid out the conditions under which either shareholder could buy out the other. Paul knew that this offer would strengthen his financial picture…but did he really want a partner?It was going to be a long night. read the case study above and answer this question what would you do if you were Paul with regards to financing, and why? ntroductloh Paul McTaggart sat at his desk. Behind him, the computer screen flickered with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT