Question

In: Computer Science

language is Java Design a super class Person with the fields for holding a person's name,...

language is Java

Design a super class Person with the fields for holding a person's name, address, and phone number. Code at least two overloaded constructors and the appropriate mutator and accessor methods. Next, design a subclass Customer that inherits from the Person class. In addition to inherit all data and methods from its super class, the Customer class should have a field for a customer ID and a boolean field indicating whether or not the customer whishes to be on a mailing list. Code appropriate constructors, mutator and accessor methods for added fields in Customer class.

Then code a driver class InheritanceApp to test the classes by creating at least one object for Person class and at least one object for Customer class to display all field information using overridden toString(), respectively. You my do hard- coded data in test.

Must code Person and Customer classes as your operation classes with the inheritance relationship and then InheritanceApp as the driver. Run and test your code to meet the requirements.

Must understand the purpose of using inheritance in coding and how well you perform the code-reuseability.

Must create at least one object for each class (Person and Customer).

Must use required/meaningful names for fields, methods and doc each of your source codes.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Make sure you copy below two classes into separate files as mentioned. Do not copy everything to a single file.

//Person.java

public class Person {

      // attributes

      private String name;

      private String address;

      private String phoneNumber;

      // default constructor

      public Person() {

            name = "";

            address = "";

            phoneNumber = "";

      }

      // constructor taking values for all fields

      public Person(String name, String address, String phoneNumber) {

            this.name = name;

            this.address = address;

            this.phoneNumber = phoneNumber;

      }

      // getters and setters for all fields

      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 getPhoneNumber() {

            return phoneNumber;

      }

      public void setPhoneNumber(String phoneNumber) {

            this.phoneNumber = phoneNumber;

      }

      // returns a String containing all details of the person

      @Override

      public String toString() {

            return "Name: " + name + ", Address: " + address + ", Phone: "

                        + phoneNumber;

      }

}

//Customer.java

public class Customer extends Person {

      private int customerID;

      private boolean onMailingList;

      // default constructor

      public Customer() {

            super(); // invoking super class default constructor

            customerID = 0;

            onMailingList = false;

      }

      // constructor taking all values

      public Customer(String name, String address, String phoneNumber,

                  int customerID, boolean onMailingList) {

            // passing name, address and phone to super class

            super(name, address, phoneNumber);

            this.customerID = customerID;

            this.onMailingList = onMailingList;

      }

      // getters and setters

      public int getCustomerID() {

            return customerID;

      }

      public void setCustomerID(int customerID) {

            this.customerID = customerID;

      }

      public boolean isOnMailingList() {

            return onMailingList;

      }

      public void setOnMailingList(boolean onMailingList) {

            this.onMailingList = onMailingList;

      }

      @Override

      public String toString() {

            // appendinga additional attributes values to the string returned by

            // super class toString.

            return super.toString() + ", CustomerID: " + customerID

                        + ", OnMailingList: " + onMailingList;

      }

}

//InheritanceApp.java

public class InheritanceApp {

      public static void main(String[] args) {

            // creating a Person and a Customer object

            Person person = new Person("Alice", "12th ABC", "12345678");

            Customer customer = new Customer("Bob", "Bob Mansion", "123-777-092",

                        1129, true);

            // displaying both using toString method

            System.out.println(person);

            System.out.println(customer);

      }

}

/*OUTPUT*/

Name: Alice, Address: 12th ABC, Phone: 12345678

Name: Bob, Address: Bob Mansion, Phone: 123-777-092, CustomerID: 1129, OnMailingList: true


Related Solutions

Design a class named Person with fields for holding a person's name, address, and telephone number(all...
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 these...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
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 these...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(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 and...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's name • idNumber: an int representing the employee's ID number • rate: a double containing the employee's hourly pay rate • hours: an int representing the number of hours this employee has worked The class should also have the following methods: • Constructor: takes the employee's name and ID number as arguments • Accessors: allow access to all of the fields of the Payroll...
In C# thanks please, Design a class named Person with properties for holding a person’s name,...
In C# thanks please, Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates the spentAmount. All...
Java program Test Scores? Design a TestScore class that has three integer fields, each holding a...
Java program Test Scores? Design a TestScore class that has three integer fields, each holding a test score. The class should have accessor and mutator methods for the test score fields and a method that returns the average of the test scores as a double. Test the TestScore class by writing a separate program that creates an instance of the class. The program should ask the user to enter three test scores, which should be stored in the TestScore object....
Write a Java class called Person. The class should have the following fields: A field for...
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called basic_stats that takes as a parameter a list of Person objects and returns a tuple containing the mean, median, and mode of all the ages. To do this,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT