Question

In: Computer Science

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 a field for the Customer ID (String) and a Boolean field indicating whether the customer wishes to be on a mailing list.

–Write a constructor that takes the name of the customer, id, address, phone number and the Boolean. Use super to call the appropriate constructor in Person

–Write a constructor that takes the name of the customer and id only and uses this to call the first constructor you wrote. It should set the Boolean to false.

–Implement the accessor and mutator methods for the customer id and Boolean.

–Override the toString() method using @override and use super to call Person’s toString()

•Write a main method that asks the user for the info of two customers, the first asking only for name and id, and the second asking for all the information. It creates 2 Customers and prints them out.

Solutions

Expert Solution

Explanation: I have implemented the code and have written Student and Customer class.I have written all the methods and have made accessors and mutators final.I have used Scanner to take inputs and have created the Customer objects and printed both the information. I have also shown the output of the program,please find the image attached with the answer.

//Person class


public class Person {
   private String name;
   private String address;
   private String phoneNumber;

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

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

   public final String getName() {
       return name;
   }
   public final void setName(String name) {
       this.name = name;
   }
   public final String getAddress() {
       return address;
   }
   public final void setAddress(String address) {
       this.address = address;
   }
   public final String getPhoneNumber() {
       return phoneNumber;
   }
   public final void setPhoneNumber(String phoneNumber) {
       this.phoneNumber = phoneNumber;
   }

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

}

//Customer class

import java.util.Scanner;

public class Customer extends Person {
   private String customerId;
   private boolean mailingList;

   public Customer(String name, String customerId, String address,
           String phoneNumber, boolean mailingList) {
       super(name, address, phoneNumber);
       this.customerId = customerId;
       this.mailingList = mailingList;
   }

   public Customer(String name, String customerId) {
       super(name);
       this.mailingList = false;
       this.customerId = customerId;
   }

   public String getCustomerId() {
       return customerId;
   }

   public void setCustomerId(String customerId) {
       this.customerId = customerId;
   }

   public boolean isMailingList() {
       return mailingList;
   }

   public void setMailingList(boolean mailingList) {
       this.mailingList = mailingList;
   }

   @Override
   public String toString() {
       return "Customer [customerId=" + customerId + ", mailingList="
               + mailingList + ", " + super.toString() + "]";
   }

   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       System.out.print("Enter the id of the customer1:");
       String id = input.next();
       System.out.print("Enter the name of the customer1:");
       String name = input.next();
       Customer customer1 = new Customer(name, id);
       System.out.print("Enter the id of the customer2:");
       id = input.next();
       System.out.print("Enter the name of the customer2:");
       name = input.next();
       System.out.print("Enter the address of the customer2:");
       String address = input.next();
       System.out.print("Enter the phone number of the customer2:");
       String phoneNumber = input.next();
       System.out.print(
               "Enter the mailing list (true or false) of the customer2:");
       boolean mailingList = input.nextBoolean();
       Customer customer2 = new Customer(name, id, address, phoneNumber,
               mailingList);
       System.out.println("Customer 1: ");
       System.out.println(customer1.toString());
       System.out.println("Customer 2: ");
       System.out.println(customer2.toString());
       input.close();
   }

}

Output:


Related Solutions

(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...
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...
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...
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....
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
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
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT