Answer:
Step-by-step explanation:
The following code is written in Java. It creates the three classes as requested with the correct constructors, and getter/setter methods. Then the test class asks the user for all the information and creates the customer object, finally printing out that information from the object getter methods.
import java.util.Scanner;
class Person {
String name, address, telephone;
private void Person (String name, String address, String telephone) {
this.name = name;
this.address = address;
this.telephone = telephone;
}
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 getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
}
class Customer extends Person {
String customerNumber;
Boolean mailingList;
public Customer(String s, Boolean mail) {
super();
this.customerNumber = customerNumber;
this.mailingList = mailingList;
}
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
public Boolean getMailingList() {
return mailingList;
}
public void setMailingList(Boolean mailingList) {
this.mailingList = mailingList;
}
}
class Test {
public static void main(final String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter Customer Name: ");
String name = in.nextLine();
System.out.println("Enter Customer Address: ");
String address = in.nextLine();
System.out.println("Enter Customer Telephone: ");
String telephone = in.nextLine();
System.out.println("Would you like to receive mail? y/n ");
Boolean mail;
if(in.nextLine() == "y") {
mail = true;
} else {
mail = false;
}
Customer customer = new Customer("1", mail);
customer.setName(name);
customer.setAddress(address);
customer.setTelephone(telephone);
System.out.println("Name: " + customer.getName());
System.out.println("Address: " + customer.getAddress());
System.out.println("Telephone: " + customer.getTelephone());
System.out.println("Wants to receive mail: " + String.valueOf(customer.getMailingList()));
}
}