Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class named Person with fields for holding a person\'s name, address, a

ID: 3654805 • Letter: D

Question

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 inherits from 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. You should implement the following constructors and methods in Person: public Person() public Person(String n, String a, String p) public void setName(String n) public void setAddress(String a) public void setPhone(String p) public String getName() public String getAddress() public String getPhone() You should also implement the following in Customer: public Customer() public Customer(String n, String a, String p, public void setCustomerNumber(String c) public void setMailingList(boolean m) public String getCustomerNumber() public boolean getMailingList()

Explanation / Answer

Thank you and here is what I have so far: public class Person { private String name; private String address; private double phonenumber; public Person(String name, String address, double phonenumber) { this.name = name; this.address = address; this.phonenumber = phonenumber; } public void setName(String name) { this.name = name; } public void setAddress(String address) { this.address = address; } public void setNumber(int phonenumber) { this.phonenumber = phonenumber; } public String getName() { return name; } public String getAddress() { return address; } public double getNumber() { return phonenumber; } } the customer class public class Customer extends Person { private int idnumber; private boolean onlist = true; public Customer(int idnumber, boolean onlist, String name, double phonenumber, String address) { super(name, address, phonenumber); this.idnumber = idnumber; this.onlist = onlist; } public void setIdNumber(int idnumber) { this.idnumber = idnumber; } public void setToBeOnList(boolean onlist) { if(onlist) { System.out.println("The customer wants to be on the mailing list."); } } public int getIdNumber() { return idnumber; } public boolean getToBeOnList() { return onlist; } } the customer demo class import java.util.Scanner; public class CustomerDemo { public static void main(String[] args) { String name; String address; double phonenumber; int idnumber; boolean onlist = false; String letter; Scanner kb = new Scanner(System.in); System.out.println("Name: "); name = kb.nextLine(); System.out.println("Address: "); address = kb.nextLine(); System.out.println("Phonenumber: "); phonenumber = kb.nextDouble(); System.out.println("IdNumber: "); idnumber = kb.nextInt(); System.out.println("Would you like to be on the mailing list? y/n: "); letter = kb.nextLine(); if(letter.equalsIgnoreCase("Y")) { onlist = true; } else { onlist = false; } Customer cm = new Customer(idnumber, onlist, name, phonenumber, address); System.out.println("Here is some information about the customer."); System.out.println("Name: " + cm.getName()); System.out.println("Address: " + cm.getAddress()); System.out.println("Phone Number: " + cm.getNumber()); System.out.println("IdNumber: " + cm.getIdNumber()); System.out.println("Would you like to be on the mailing list: " + cm.getToBeOnList()); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote