1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Finger [1]
3 years ago
12

Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructo

rs 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 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.

Computers and Technology
1 answer:
Fittoniya [83]3 years ago
8 0

Answer:

Here is the Person class:

class Person {  //class name

//below are the private data members/fields of Person class

   private String name;   //to hold name

   private String address;  //to hold address

   private String phoneNo;   // contains telephone number

   public Person(String name, String address, String phoneNo){  //constructor of Person class with name, address and phoneNo as parameters

       this.name = name;  

       this.address = address;

       this.phoneNo = phoneNo;     }  

   public String getName(){  //accessor method to get/access the name

       return this.name;     }   //returns the name

   public String getAddress(){  //accessor method to get/access the address

       return this.address;     }  //returns the address

   public String getPhoneNo(){ //accessor method to get/access the phone number

       return this.phoneNo;  } //returns the telephone number    

//mutator methods

   public void setName(String nam){  //mutator method to set the name

       this.name = nam;     }  

   public void setAddress(String addr){  //mutator method to set the address

       this.address = addr;     }  

   public void setPhoneNo(String phNo){   //mutator method to set the telephone number

       this.phoneNo = phNo;      } }

Here is the Customer class which extends the Person class:

class Customer extends Person{  //Customer class that is sub class of Person class

//below are the private data members/fields of Customer class

   private String CustomerNo;  //String type field to hold customer number

   private boolean MailingList;   //boolean field indicating whether the customer wishes to be on a mailing list

   public Customer(String name, String address, String phoneNo, String custNum, boolean mail) {  //constructor of Customer class that has parameters name, address and phoneNo (of Person class) and parameters custNum and mail ( of Customer class)

       super(name, address, phoneNo);  //  super keyword is used to refer to Person objects and to access the Person class constructor

       this.CustomerNo = custNum;  

       this.MailingList = mail;     }  

//accessor methods

   public String getCustomerNo(){  //accessor method to get/access the customer number

       return this.CustomerNo;     }  

   public boolean getMailingList(){ //accessor method to get/access the boolean mailing list to check whether a person wants to be on mailing list

       return this.MailingList;     }

//mutator methods

   public void setCustomerNo(String custNo){ //mutator method to set the customer number

       this.CustomerNo = custNo;     }  

   public void setMailingList(boolean mailing){ //mutator method to set the mailing list  

       this.MailingList = mailing;     } }

       

Explanation:

Here is the demonstration class to demonstrate object of Customer class, calls Person and Customer class methods to display the Customer information  such as name, address, phone number, customer number and if customer wants to receive mail.

import java.util.Scanner;   //used to take input from user

class Demonstration{   //test class

   public static void main(String args[]){   //start of main() function

Scanner input= new Scanner(System.in);   //creates object of Scanner class

       System.out.print("Enter Customer Name: ");  //prompts user to enter name

       String fname = input.nextLine();

       System.out.print("Enter Customer Address: ");  //prompts user to enter address

       String address = input.nextLine();

       System.out.print("Enter Customer Telephone Number: "); //prompts user to enter telephone number

       String phoneNumber = input.nextLine();

       System.out.print("Enter Customer Number: "); //prompts user to enter customer number

       String customerNum = input.nextLine();

       System.out.print("Does Customer wish to be on a mailing list? \nPress 1 for yes, 0 for no: "); //asks user if he wishes to receive mail

       String choice = input.nextLine();  

       boolean mailList = (choice.equals("1"));   //if user enters 1 indicating that he wishes to be on mailing list

       Customer customer = new Customer(fname, address, phoneNumber, customerNum, mailList);   //creates object of Customer class and calls Customer class constructor

       System.out.println("\nCustomer Information: ");

       System.out.println("Name: "+customer.getName());  //calls getName method of Person class using customer object to get the name and displays the name

       System.out.println("Address: "+customer.getAddress()); //calls getAddress method of Person class using customer object to get the name and prints the address

       System.out.println("Telephone Number: "+customer.getPhoneNo()); //calls getPhoneNo method of Person class using customer object to get the telephone number and prints phone number

       System.out.println("Customer Number: "+customer.getCustomerNo());   //calls getCustomerNo method of Customer class using customer object to get the customer number and prints the customer number

       System.out.println("Mailing List?: "+customer.getMailingList());     }} //calls getMailingList method of Customer class using customer object to get the mailing list and prints true of false on the basis of customers choice to be on mailing list.

You might be interested in
What does using indirect quotations allow a writer to do?
Marrrta [24]
Indirect quotations can add information that strengthens your content in many of the same ways as direct quotations so. Essentially, indirect quotes carry the meaning of a speaker or writer's original words without using the exact words.
7 0
3 years ago
Read 2 more answers
What kind of operating system is MS-DOS?
ELEN [110]

MS-DOS is a command-line operating system.

Therefore, the best answer is Command-line.

8 0
3 years ago
Read 2 more answers
Would it be possible to make VR technology in a way that our brain sees imagined experiences using simple impulses (like words)
Ludmilka [50]

Answer:

theoretically yes. we would need to cross and langue gap because our brain signals wouldn't understand words

Explanation:

educated quess

7 0
2 years ago
You trained a binary classifier model which gives very high accuracy on thetraining data, but much lower accuracy on validation
kompoz [17]

Answer:

a. This is an instance of overfitting.

Explanation:

In data modeling and machine learning practice, data modeling begins with model training whereby the training data is used to train and fit a prediction model. When a trained model performs well on training data and has low accuracy on the test data, then we say say the model is overfitting. This means that the model is memorizing rather Than learning and hence, model fits the data too well, hence, making the model unable to perform well on the test or validation set. A model which underfits will fail to perform well on both the training and validation set.

4 0
3 years ago
You need to design a new Access database. The first step is to organize the smallest to largest data, also called a. Alphabetica
Whitepunk [10]

Answer: d) Hierarchy of data

Explanation:

  • Hierarchy of data is defined as arrangement of data in systematic way .The arrangement of files,character,records etc is done in a particular order usually in terms of highest level and lowest level .
  • According to the question ,hierarchy of data should be used for organizing data from smallest stage to highest stage for database designing.
  • Other options are incorrect alphabetical designing is based on alphabetical order. Detail structure is a model made on basis of details and features.
  • Data design is the model or structure that includes data and related factors as building block.Logical order is the organizing elements on basis of particular logic.
  • Thus, the correct option is option(d).  
3 0
3 years ago
Other questions:
  • Para saan po yung points dito?
    15·1 answer
  • _____ refers to displaying information for the user's view.
    14·2 answers
  • A wide variety of apps are available to customize devices, which category of app does word processing software falls into?
    10·1 answer
  • What tasks do most operating systems perform?
    15·1 answer
  • what is the total resistance of a series circuit with four resistors in series of 12 16 20 and 24 ohms​
    14·1 answer
  • What in the LAN for a small office, some user devices connect to the LAN using a cable, while others connect using wireless tech
    14·1 answer
  • Guess The Song:
    9·1 answer
  • Which skill type refers to the ability to interact and communicate effectively with people? skills refer to the ability to inter
    8·2 answers
  • Select the correct answer from each drop-down menu.
    8·1 answer
  • Match the parts of the website address with its correct explanation. http://www.usa.gov/Agencies/federal.shtm/​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!