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

need help java prg Person and Customer Classes Design a class named Person with

ID: 3765249 • Letter: N

Question

need help java prg

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 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 cus-tomer 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.

Explanation / Answer

Person class with constructor.

public class Person
{
   private String name;
   private String address;
   private String telephonenumber;
  
   public Person(String name, String address, String telephonenumber)
   {
       this.name = name;
       this.address = address;
       this.telephonenumber = telephonenumber;
   }
   public void setName(String name)
   {
       this.name = name;
   }
   public void setAddress(String address)
   {
       this.address = address;
   }
   public void setNumber(int telephonenumber)
   {
       this.telephonenumber = telephonenumber;
   }
   public String getName()
   {
       return name;
   }
   public String getAddress()
   {
       return address;
   }
   public String getNumber()
   {
       return telephonenumber;
   }
}

Customer Class extending person class. I have created boolena variable onlist for the same.

public class Customer extends Person
{
   private int idnumber;
   private boolean>   
   public Customer(int idnumber, boolean onlist, String name, String telephonenumber, String address)
   {
       super(name, address, telephonenumber);
       this.idnumber = idnumber;
       this.onlist = onlist;
   }
  
   public void setIdNumber(int idnumber)
   {
       this.idnumber = idnumber;
   }
   public void setToBeOnList(boolean onlist)
   {
       if(onlist)
       {
           System.out.println("Customer requesting to be on mailing list.");
       }
   }
   public int getIdNumber()
   {
       return idnumber;
   }
   public boolean getToBeOnList()
   {
       return onlist;
   }
}

Main class to test the existing classes. I have created an object named cust1 which for customer class.

import java.util.Scanner;
public class CustomerDemo
{
   public static void main(String[] args)
   {
       String name;
       String address;
       String telephonenumber;
       int idnumber;
       boolean>        String letter;
      
       Scanner sc = new Scanner(System.in);
      
       System.out.println("Name: ");
       name = sc.nextLine();
      
       System.out.println("Address: ");
       address = sc.nextLine();
      
       System.out.println("Telephonenumber: ");
       telephonenumber = sc.nextDouble();
      
       System.out.println("IdNumber: ");
       idnumber = sc.nextInt();
      
       System.out.println("Would you like to be on the mailing list? y/n: ");
       letter = sc.nextLine();
      
       if(letter.equalsIgnoreCase("Y"))
       {
          >        }
       else
       {
          >        }      
      
       Customer cust1 = new Customer(idnumber, onlist, name, telephonenumber, address);
      
       System.out.println("Here is some information about the customer.");
      
       System.out.println("Name: " + cust1.getName());
       System.out.println("Address: " + cust1.getAddress());
       System.out.println("Phone Number: " + cust1.getNumber());
       System.out.println("IdNumber: " + cust1.getIdNumber());
       System.out.println("Would you like to be on the mailing list: " + cust1.getToBeOnList());
   }
}