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

Could someone please look at the code bellow and rewrite it with deatiled java /

ID: 3812525 • Letter: C

Question

Could someone please look at the code bellow and rewrite it with deatiled java //comments please?

This will help me understand it better, Thank you!

public class Person {

private String name;
private String address;
private String phoneNumber;

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

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}

====================================================================

public class Customer extends Person {

private int customerNumber;
private boolean onList;

public Customer(String name, String address, String phoneNum, int number, boolean onList) {
super(name, address, phoneNum);
this.customerNumber = number;
this.onList = onList;
}

public int getCustomerNumber() {
return customerNumber;
}

public void setCustomerNumber(int customerNumber) {
this.customerNumber = customerNumber;
}

public boolean isOnList() {
return onList;
}

public void setOnList(boolean onList) {
this.onList = onList;
}
}

=======================================================================

public class CustomerDemo {

public static void main(String[] args) {

Customer customer1 = new Customer("Judy Smith", "123 Maple Lane", "555-305-9876", 1, true);
Customer customer2 = new Customer("Bob White", "456 Oak Road", "555-895-4931", 2, true);
Customer customer3 = new Customer("Garry Goodman", "789 Acorn Avenue", "555-587-2983", 3, false);

System.out.println("Customer 1:");
System.out.println(" Name: " + customer1.getName());
System.out.println(" Address: " + customer1.getAddress());
System.out.println(" Phone Number: " + customer1.getPhoneNumber());
System.out.println(" Customer Number: " + customer1.getCustomerNumber());
System.out.println(" On Mailing List: " + customer1.isOnList());

System.out.println("Customer 2:");
System.out.println(" Name: " + customer2.getName());
System.out.println(" Address: " + customer2.getAddress());
System.out.println(" Phone Number: " + customer2.getPhoneNumber());
System.out.println(" Customer Number: " + customer2.getCustomerNumber());
System.out.println(" On Mailing List: " + customer2.isOnList());

System.out.println("Customer 3:");
System.out.println(" Name: " + customer3.getName());
System.out.println(" Address: " + customer3.getAddress());
System.out.println(" Phone Number: " + customer3.getPhoneNumber());
System.out.println(" Customer Number: " + customer3.getCustomerNumber());
System.out.println(" On Mailing List: " + customer3.isOnList());
}

}

Explanation / Answer


/*
   Creating class Person, represents information such as person name, address and phoneNumber
*/
public class Person {

   // declaring the attributes for a Person
private String name;
private String address;
private String phoneNumber;
  
   // constructor to create a person object
   // this takes the name, address and phoneNumber of the person
   // and creates the person object
public Person(String name, String address, String phoneNumber) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
}
  
   // getter method for address
public String getAddress() {
return address;
}
   // to set the address of person
public void setAddress(String address) {
this.address = address;
}
  
   // to get the name of person
public String getName() {
return name;
}
   // to set the name for person object
public void setName(String name) {
this.name = name;
}
  
   // to get the phone number of the person
public String getPhoneNumber() {
return phoneNumber;
}
   // to set the phonenumber for the person
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
} // end of person class


====================================================================
/*
   Customer class extends the Person class. A Customer is a person, with
   some additional properties such as customerNumber
*/
public class Customer extends Person {
  
   // declaring attributes which are specially for Customer class
private int customerNumber;
private boolean onList;
  
   // create the customer object using details
public Customer(String name, String address, String phoneNum, int number, boolean onList) {
       // super calls the parent class method, i.e. creates Person class
       // remember customer inherits the person class
super(name, address, phoneNum);
      
       // set proprties for customer
this.customerNumber = number;
this.onList = onList;
}
  
   // to get the customerNUmber
public int getCustomerNumber() {
return customerNumber;
}
  
   // set customerNumber for this object
public void setCustomerNumber(int customerNumber) {
this.customerNumber = customerNumber;
}
  
   // check if the customer is in partiular list or not
public boolean isOnList() {
return onList;
}
   // set if customer is in list
public void setOnList(boolean onList) {
this.onList = onList;
}
}
=======================================================================

/*
   This is a driver class, which creates some object of Customer and persons
   and interact with them, tests their methods.
*/  
public class CustomerDemo {

   // main method, execution starts from here
public static void main(String[] args) {
       // create 3 customer objects
Customer customer1 = new Customer("Judy Smith", "123 Maple Lane", "555-305-9876", 1, true);
Customer customer2 = new Customer("Bob White", "456 Oak Road", "555-895-4931", 2, true);
Customer customer3 = new Customer("Garry Goodman", "789 Acorn Avenue", "555-587-2983", 3, false);
      
       // print information for customer1
System.out.println("Customer 1:");
System.out.println(" Name: " + customer1.getName());   // printing name
System.out.println(" Address: " + customer1.getAddress());       // printing address
System.out.println(" Phone Number: " + customer1.getPhoneNumber());       // printing phone number
System.out.println(" Customer Number: " + customer1.getCustomerNumber());
System.out.println(" On Mailing List: " + customer1.isOnList());
      
       // print information for customer2
System.out.println("Customer 2:");
System.out.println(" Name: " + customer2.getName());
System.out.println(" Address: " + customer2.getAddress());
System.out.println(" Phone Number: " + customer2.getPhoneNumber());
System.out.println(" Customer Number: " + customer2.getCustomerNumber());
System.out.println(" On Mailing List: " + customer2.isOnList());
      
       // print information for customer3
System.out.println("Customer 3:");
System.out.println(" Name: " + customer3.getName());
System.out.println(" Address: " + customer3.getAddress());
System.out.println(" Phone Number: " + customer3.getPhoneNumber());
System.out.println(" Customer Number: " + customer3.getCustomerNumber());
System.out.println(" On Mailing List: " + customer3.isOnList());
}
} // end of CustomerDemo class

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