Question

In: Computer Science

(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 accessor methods for the class’s fields. Demonstrate an object of the Customer class in a simple program.

Solutions

Expert Solution


import java.util.Scanner;
class Person {
   private String name;
   private String address;
   private String phoneNumber;

   public Person() {

   }

   public Person(String aName, String aAddress, String aPhoneNumber) {
       super();
       name = aName;
       address = aAddress;
       phoneNumber = aPhoneNumber;
   }

   public String getName() {
       return name;
   }

   public void setName(String aName) {
       name = aName;
   }

   public String getAddress() {
       return address;
   }

   public void setAddress(String aAddress) {
       address = aAddress;
   }

   public String getPhoneNumber() {
       return phoneNumber;
   }

   public void setPhoneNumber(String aPhoneNumber) {
       phoneNumber = aPhoneNumber;
   }

   @Override
   public String toString() {
       return "name : " + name + ", address : " + address + ", phoneNumber : " + phoneNumber;
   }

}

class Customer extends Person {
   private String customerNumber;
   private boolean isInMailingList;

   public Customer(String aName, String aAddress, String aPhoneNumber, String aCustomerNumber,
           boolean aIsInMailingList) {
       super(aName, aAddress, aPhoneNumber);
       customerNumber = aCustomerNumber;
       isInMailingList = aIsInMailingList;
   }

   public String getCustomerNumber() {
       return customerNumber;
   }

   public void setCustomerNumber(String aCustomerNumber) {
       customerNumber = aCustomerNumber;
   }

   public boolean isInMailingList() {
       return isInMailingList;
   }

   public void setInMailingList(boolean aIsInMailingList) {
       isInMailingList = aIsInMailingList;
   }

   @Override
   public String toString() {
       return super.toString() + " CustomerNumber : " + customerNumber + ", customer wishes to be on a mailing list : "
               + isInMailingList;
   }

}

public class TestPerson {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter customer name");
       String name = sc.nextLine();
       System.out.println("Enter customer address");
       String address = sc.nextLine();
       System.out.println("Enter customer Phone ");
       String phoneNumber = sc.nextLine();
       System.out.println("Enter customer number");
       String customerNumber = sc.nextLine();
       System.out.println("do you wishe to be on a mailing list? ");
       boolean s = sc.nextBoolean();
       Customer c = new Customer(name, address, phoneNumber, customerNumber, s);
       System.out.println(c);

   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

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...
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...
In java, create a class named Contacts that has fields for a person’s name, phone number...
In java, create a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contact objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. Include javadoc...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
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...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the Date class to create an object for date hired. A faculty member has office hours and a rank. A...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
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 Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT