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
By default, the pfsense firewall allows unrestricted outbound access from the lan interface. true or false?
Sav [38]

The statement "By default, the pfSense firewall allows unrestricted outbound access from the lan interface" is true.

pfSense is free and open source firewall and router that can be installed on a physical computer or a virtual machine. Teh goal is to make the machine a dedicated firewall/router for a network.

 It features unified threat management, load balancing, multi WAN etc.


8 0
4 years ago
Read 2 more answers
Which of the following is true regarding data acquisition? Because data acquisition is often technical, the research team does n
elixir [45]

Answer:

Data acquisition should follow a detailed collection plan that is set in advance.

Explanation:

The process of collection of data over computer with the help of electronic sensors is called data acquisition. The can be related to voltage, current, temperature etc.

For example

Data collection with the help of sensors to monitor weather conditions is an example of data acquisition. In this process data has been gathered on already planned format. Each column or row of data will be helpful to predict the weather condition such as, rain predictions, earthquake prediction etc.

That's why to collect this type of data, collection plan should be set in advance to gather relevant information with the help of data.

4 0
4 years ago
Read 2 more answers
Which of the following statements is true regarding how Wireshark works? a. Where packets are captured and how they are captured
I am Lyosha [343]

Answer:

b. By running the Wireshark software on the same computer that generates the packets, the capture is specific to that machine.

Explanation:

By running the Wireshark software on the same computer that generates the packets, the capture is specific to that machine. is true regarding how Wireshark works.

4 0
3 years ago
How many instructions are supercomputers capable of processing in a single second?
liq [111]

Answer:

Trillions

Explanation:

A Supercomputer can process trillions of instructions in a second

6 0
3 years ago
Wright a 3 paragraph 5 sentences per graph story bout computers or the internet
boyakko [2]

Ah yes, technology.

Firsly, let's start at the begining. Because we can't have internet without computers. Think of it from the old quote, "Which came first? The chicken or the egg?"

Computers, or the very first programmable one was created by German Konrad Zuse. A man with too much free time, invented a computer in his parents' living room. And yes, it was considered  to be the very first electromechanical binary programmable PC. He called it the "Z1". There's actually no right answer to this to be quite frank, considering the many different classifications you'd call a computer back then.

Why was the computer invented? Why, where would we be without it? Certainly not here (hence brainly and you asking this question). Computers were created for the sole purpose of a repetitive calculation to perform more quick and accurately information.

5 0
3 years ago
Other questions:
  • The ____ problem-solving cycle involves inputting code to an assembler, translating it to machine language, loading it into a Vo
    10·1 answer
  • Whats the 7 internal components found in a computer tower
    11·1 answer
  • What is an example of asynchronous communication
    7·1 answer
  • Hydropower uses moving water to do work, such as grinding grains in a mill. True False
    7·1 answer
  • A user could find the icon for an attached usb flash drive under what heading in the my computer/computer window?
    7·1 answer
  • A typical item in a plan of procedure includes the name of the part of the ______ to
    5·1 answer
  • You have two DCs, each with three Active Directory-integrated zones. You're getting inconsistent DNS lookup results and suspect
    8·1 answer
  • Varied amount of input data Statistics are often calculated with varying amounts of input data. Write a program that takes any n
    8·1 answer
  • Use the drop-down menus to complete the sentences about the Calendar view Arrange command group.
    6·1 answer
  • PLEASE HELP WILL GIVE BRAINLIEST!!!’
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!