Question

In: Computer Science

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 values and the appropriate mutator and accessor methods for the class's fields.

Demonstrate the Customer class in a program that prompts the user to enter values for the customer's name, address, phone number, and customer number, and then asks the user whether or not the customer wants to receive mail. Use this information to create a customer object and then print its information.

Put all of your classes in the same file. To do this, do not declare them public.

Instead, simply write:

class Person { ... }
class Customer { ... }

Sample Run
java Driver

Enter·name·of·customer:Julia·Stevens↵
Enter·address·of·customer:77·Massachusetts·Ave·Cambridge,·MA·02139↵
Enter·phone·number·of·customer:617-777-7777↵
Enter·customer·number:928734502↵
Enter·yes/no·--·does·the·customer·want·to·recieve·mail?:no↵

Customer:·↵
Name:·Julia·Stevens↵
Address:·77·Massachusetts·Ave·Cambridge,·MA·02139↵
Phone·Number:·617-777-7777↵
Customer·Number:·928734502↵
Recieve·Mail?:·false↵

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. Thanks

//You can save the file as Driver.java

import java.util.Scanner;

class Person {

      // attributes

      String name;

      String address;

      String phoneNumber;

      // constructor to initialize all fields

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

            this.name = name;

            this.address = address;

            this.phoneNumber = phoneNumber;

      }

      // getters and setters

      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;

      }

}

// Customer class inheriting Person

class Customer extends Person {

      // additional attributes

      String custNumber;

      boolean receiveMail;

      // constructor taking all values

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

                  String custNumber, boolean receiveMail) {

            // passing name, address, phone numbr to super class

            super(name, address, phoneNumber);

            this.custNumber = custNumber;

            this.receiveMail = receiveMail;

      }

      // getters and setters

      public String getCustNumber() {

            return custNumber;

      }

      public void setCustNumber(String custNumber) {

            this.custNumber = custNumber;

      }

      public boolean wantsToReceiveMail() {

            return receiveMail;

      }

      public void setReceiveMail(boolean receiveMail) {

            this.receiveMail = receiveMail;

      }

}

// Driver class

class Driver {

      public static void main(String[] args) {

            // scanner for reading input and output

            Scanner scanner = new Scanner(System.in);

            // asking and receiving inputs

            System.out.print("Enter name of customer:");

            String name = scanner.nextLine();

            System.out.print("Enter address of customer:");

            String address = scanner.nextLine();

            System.out.print("Enter phone number of customer:");

            String phone = scanner.nextLine();

            System.out.print("Enter customer number:");

            String custNumber = scanner.nextLine();

            System.out

                        .print("Enter yes/no -- does the customer want to recieve mail?:");

            boolean receiveMail = scanner.nextLine().equalsIgnoreCase("yes");

            // creating a Customer object

            Customer customer = new Customer(name, address, phone, custNumber,

                        receiveMail);

            // displaying customer details

            System.out.println("Customer:");

            System.out.println("Name: " + customer.getName());

            System.out.println("Address: " + customer.getAddress());

            System.out.println("Phone Number: " + customer.getPhoneNumber());

            System.out.println("Customer Number: " + customer.getCustNumber());

            System.out.println("Receive Mail?: " + customer.wantsToReceiveMail());

      }

}

/*OUTPUT*/

Enter name of customer:Julia Stevens

Enter address of customer:77 Massachusetts Ave Cambridge, MA 02139

Enter phone number of customer:617-777-7777

Enter customer number:928734502

Enter yes/no -- does the customer want to recieve mail?:no

Customer:

Name: Julia Stevens

Address: 77 Massachusetts Ave Cambridge, MA 02139

Phone Number: 617-777-7777

Customer Number: 928734502

Receive Mail?: false


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...
(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...
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 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....
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...
~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding...
~~~USING C# ONLY~~~ Create a console application 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...
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 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....
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT