Question

This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description:...

This is for Java Programming

Please use comments

Customer and Employee data (15 pts)

Problem Description:

Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism.

Console

Welcome to the Person Tester application

Create customer or employee? (c/e): c

Enter first name: Frank

Enter last name: Jones

Enter email address: frank44@ hot mail. com

Customer number: M10293

You entered:

Name: Frank Jones

Email: frank44@hot mail . com

Customer number: M10293

Continue? (y/n): y

Create customer or employee? (c/e): e

Enter first name: Anne

Enter last name: Prince

Enter email address: anneP@ g m ail . com

Social security number: 111-11-1111

You entered:

Name: Anne Prince

Email: anneP@ g mail . com

Social security number: 111-11-1111

Continue? (y/n): n

Operation

The application prompts the user to enter a customer or an employee.

If the user selects customer, the application asks for name, email, and customer number.

If the user selects employee, the application asks for name, email, and social security number.

When the user finishes entering data for a customer or employee, the application displays the data that the user entered.

Specifications

Create a Person class that stores first name, last name, and email address. This class should provide a no-argument constructor, get and set methods for each piece of data, and it should override the toString method so it returns the first name, last name, and email fields in this format:

Name: Frank Jones
Email: frank44@ hot mail . com

In addition, it should contain an abstract method named getDisplayText that returns a string.

Create a class named Customer that inherits the Person class. This class should store a customer number, it should provide get and set methods for the customer number, it should provide a no-argument constructor, and it should override the toString method of the Person class. The toString method should return a string that consists of the string returned by the toString method of the Person class appended with the Customer number like this:

Name: Frank Jones
Email: frank44@ hot mail . com
Customer number: M10293

Create a class named Employee that inherits the Person class. This class should store a social security number, it should provide get and set methods for the social security number, it should provide a no-argument constructor, and it should override the toString method of the Person class. The toString method should return a string that consists of the string returned by the toString method of the Person class appended with the Employees social security number like this:

Name: Anne Prince
Email: anneP@ g mail . com
Social security number: 111-11-1111

Create a class named PersonApp that prompts the user as shown in the console output. This class should create the necessary Customer and Employee objects from the data entered by the user, and it should use these objects to display the data to the user. To print the data for an object to the console, this program should use a static method named print – defined in this class - with the following header (polymorphism):

               public static void print (Person p)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/***************************************Person.java*************************/


public abstract class Person {

   private String firstnName;
   private String lastName;
   private String email;

   public Person(String firstnName, String lastName, String email) {
       super();
       this.firstnName = firstnName;
       this.lastName = lastName;
       this.email = email;
   }

   public String getFirstnName() {
       return firstnName;
   }

   public void setFirstnName(String firstnName) {
       this.firstnName = firstnName;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   public String getEmail() {
       return email;
   }

   public void setEmail(String email) {
       this.email = email;
   }

   public abstract String getDisplayText();

   @Override
   public String toString() {
       return "Name: " + firstnName + " " + lastName + "\n" + "Email: " + email;
   }

}
/****************************************Customer.java***********************/


public class Customer extends Person {

   private String customerNumber;

   public Customer(String firstnName, String lastName, String email, String customerNumber) {
       super(firstnName, lastName, email);
       this.customerNumber = customerNumber;
   }

   public String getCustomerNumber() {
       return customerNumber;
   }

   public void setCustomerNumber(String customerNumber) {
       this.customerNumber = customerNumber;
   }

   @Override
   public String toString() {
       return super.toString()+"\n"
               + "Customer Number: "+customerNumber;
   }

   @Override
   public String getDisplayText() {
      
       return toString();
   }
  
  
}
/************************************Employee.java***************************/


public class Employee extends Person {

   private String ssn;

   public Employee(String firstnName, String lastName, String email, String ssn) {
       super(firstnName, lastName, email);
       this.ssn = ssn;
   }

   public String getSsn() {
       return ssn;
   }

   public void setSsn(String ssn) {
       this.ssn = ssn;
   }

   @Override
   public String toString() {
       return super.toString() + "\n" + "Social Security Number: " + ssn;
   }

   @Override
   public String getDisplayText() {
      
       return toString();
   }

}
/*********************************PersonApp.java*******************************/

import java.util.Scanner;

public class PersonApp {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);
       char quit = ' ';
       Person p;
       System.out.println("Welcome to the Person Tester application");
       do {
           System.out.print("Create customer or employee? (c/e): ");
           char option = scan.nextLine().toLowerCase().charAt(0);
           System.out.print("Enter first name: ");
           String firstName = scan.nextLine();
           System.out.print("Enter last name: ");
           String lastName = scan.nextLine();
           System.out.print("Enter email address: ");
           String email = scan.nextLine();
           String customerNumber = "";
           String ssn;
           if (option == 'c') {

               System.out.print("Customer Number: ");
               customerNumber = scan.nextLine();
               System.out.println("You entered: ");
               p = new Customer(firstName, lastName, email, customerNumber);
               System.out.println(p.getDisplayText());
           } else if (option == 'e') {

               System.out.print("Social security number: ");
               ssn = scan.nextLine();
               System.out.println("You entered: ");
               p = new Employee(firstName, lastName, email, ssn);

               System.out.println(p.getDisplayText());

           }

           System.out.print("Continue? (y/n): ");
           quit = scan.nextLine().toLowerCase().charAt(0);

       } while (quit != 'n');
       scan.close();
   }
}
/*******************output***********************/

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ASAP Please. Python Program Description Create an object-oriented program that allows you to enter data for...

    ASAP Please. Python Program Description Create an object-oriented program that allows you to enter data for employees. Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class...

  • Java Programming Design a class named Person and its two subclasses named Student and Employee. A...

    Java Programming Design a class named Person and its two subclasses named Student and Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, date hired. Define a class named MyDate that contains the fields year, month, and day. Override the toString method in each class to display the class name and the person's name....

  • java Practice Program 2: Create a project named Student that will cont ain two classes: Student...

    java Practice Program 2: Create a project named Student that will cont ain two classes: Student and StudentClient Student class Instance variables . Name Social security number Gpa Methods: Constructor that accepts all three instance variables Getters for all three instance variables .Setters for name and social security number .Setter for gpa should only set the value if the value is between 0 and 4.0. toString-Outputs the values of the instance variables in this format: name: Smith; SSN: 333-99-4444 GPA:...

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • I'm struggling to figure out how to do this problem in Java, any help would be...

    I'm struggling to figure out how to do this problem in Java, any help would be appreciated: Create an application that uses a class to store and display contact information. Console: Welcome to the Contact List application Enter first name: Mike Enter last name: Murach Enter email:      [email protected] Enter phone:      800-221-5528 -------------------------------------------- ---- Current Contact ----------------------- -------------------------------------------- Name:           Mike Murach Email Address: [email protected] Phone Number:   800-221-5528 -------------------------------------------- Continue? (y/n): n Specifications Use a class named Contact to store the data...

  • a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

    a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

    Design a class named Person with fields for holding a person's name, address, and telephone number (all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes...

  • Please provide the code for the last part(client side program). yes i have all the class...

    Please provide the code for the last part(client side program). yes i have all the class implementations. ``` person.h #ifndef PERSON_H #define PERSON_H #include <string> using namespace std; class person { public: person(); string getname() const; string getadd() const; string getemail() const; string getphno() const; string toString() const; private: string name; string add; string email; string phno; }; ```person.cpp #include "person.h" person::person() { name = "XYZ"; add="IIT "; email="%%%%"; phno="!!!!!"; } string person::getname() const { return name; } string person::getadd()...

  • Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so...

    Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT