from book: java control structures through objects, 6th edition Person and Custo
ID: 3812276 • Letter: F
Question
from book: java control structures through objects, 6th edition
Person and Customer classes
Design a class named person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appripriate mutator and accessor methods for the classe's feilds.
Next, design a class named customer, which extends the person class. the customer class should have a field for customer number and a boolean field indicating weather the customer wishes to be on a mailing list. Write one or more constructors and the approprate mutator and accessor ti be on a mailing list. Write one or more constructors and the approrate mutator and accessor methods for the class's fields. Demonstrate an object of the customer class in a simple program. comment on code
also please sperate the clases in cheggs with a line ===================================
Explanation / Answer
CustomerTest.java
public class CustomerTest {
public static void main(String[] args) {
Customer c = new Customer("Suresh");
c.setAddress("hyderabad");
c.setCustomerNo(111);
c.setMailingList(true);
c.setTelephoneNo("999999999");
System.out.println("Customer detaisl are: ");
System.out.println("Customer name: "+c.getName());
System.out.println("Customer No: "+c.getCustomerNo());
System.out.println("Customer Phone No: "+c.getTelephoneNo());
System.out.println("Customer address: "+c.getAddress());
System.out.println("Customer mailing: "+c.isMailingList());
}
}
Customer.java
public class Customer extends Person{
private int customerNo;
private boolean isMailingList;
public Customer(String name){
super(name);
}
public int getCustomerNo() {
return customerNo;
}
public void setCustomerNo(int customerNo) {
this.customerNo = customerNo;
}
public boolean isMailingList() {
return isMailingList;
}
public void setMailingList(boolean isMailingList) {
this.isMailingList = isMailingList;
}
}
Person.java
public class Person {
private String name;
private String address;
private String telephoneNo;
public Person() {
}
public Person(String name){
this.name = name;
}
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 getTelephoneNo() {
return telephoneNo;
}
public void setTelephoneNo(String telephoneNo) {
this.telephoneNo = telephoneNo;
}
}
Output:
Customer detaisl are:
Customer name: Suresh
Customer No: 111
Customer Phone No: 999999999
Customer address: hyderabad
Customer mailing: true
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.