Question

the coding language is java The start of Polymorphism Assignment Outcome: Student will demonstrate the ability...

the coding language is java

The start of Polymorphism Assignment

Outcome:

  • Student will demonstrate the ability to apply polymorphism in a Java program.

Program Specifications:

Design the following program:

A person has a name, and age.

An Employee is a person.

An Employee has a company and position.

A SoftwareEngineer is an employee and a person.

A SoftwareEngineer has a rank (Junior, Middle, and Senior)

A SoftwareEngineer either C programmer, Jave programmer or both.

A Manager is an Employee and a person.

A Manager has a specialty.

A Manager specialty is either CEO, Division, or Sales.

An Intern is an employee and a person.

An Intern has duty.

A Security is an employee and a person.

A Security has a position (to guard).

An administrator is an employee and a person.

An Administrator has a type HR, recruiter, Secretary, and Legal.

  

All Employee type objects have a method named doThis();

   SoftwareEngineer -> doThis() displays I program web application.

   Manager -> doThis() displays I mange sales.

   Intern -> doThis() displays I test application.

   administrator -> doThis() displays I do the payroll.

Security -> doThis() displays I guard the main entrance.

... in general, all employee have a doThis() method that displays something.

Main()

Create the classes Person, Employee, SoftwareEngineer

Create the classes Manager, Intern, Security, administrator

   Create the doThis() method in each class

In main create the follow reference variables:

    SoftwareEngineer Hank (create this reference variable)

    Manager Terry (create this reference variable)

    Intern Mario (create this reference variable)

    administrator Paula (create this reference variable)

Security Danilo (create this reference variable)

    administrator Barry (create this reference variable)

    SoftwareEngineer Peyton (create this reference variable)

    Security Wayne (create this reference variable)

    Manager Phil (create this reference variable)

SoftwareEngineer Carlos (create this reference variable)

And then...

  Call each Employee doThis method (one at a time) passing each player.

Call the toString methods for each Employee object.

You are to turn in a UML, and CODE.

Submission Requirements:

  • Follow the rules from the prior assignments.

YOU MAY NOT EVER:

  • Use global variables.
  • Use the word goto.
  • Use the break command outside a case statement.

Homework Answers

Answer #1

Person.java

public class Person {
private String name;
private int age;
  
public Person()
{
this.name = "";
this.age = 0;
}

public Person(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
  
@Override
public String toString()
{
return("Name: " + getName() + ", Age: " + getAge() + " years");
}
}

Employee.java

public abstract class Employee extends Person {
private String company, position;
  
public Employee()
{
super();
this.company = this.position = "";
}

public Employee(String name, int age, String company, String position) {
super(name, age);
this.company = company;
this.position = position;
}

public String getCompany() {
return company;
}

public void setCompany(String company) {
this.company = company;
}

public String getPosition() {
return position;
}

public void setPosition(String position) {
this.position = position;
}
  
@Override
public String toString()
{
return(super.toString() + ", Company: " + getCompany() + ", Position: " + getPosition());
}
  
public abstract void doThis();
}

SoftwareEngineer.java

public class SoftwareEngineer extends Employee {
private String rank, type;
  
public SoftwareEngineer()
{
this.rank = "Junior";
this.type = "Both C and Java programmer";
}

public SoftwareEngineer(String name, int age, String company, String position, String rank, String type) {
super(name, age, company, position);
this.rank = rank;
this.type = type;
}

public String getRank() {
return rank;
}

public void setRank(String rank) {
this.rank = rank;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
  
@Override
public String toString()
{
return(super.toString() + ", Rank: " + getRank() + ", Type: " + getType());
}

@Override
public void doThis() {
System.out.println("I program web application.");
}
}

Manager.java

public class Manager extends Employee {
private String speciality;
  
public Manager()
{
super();
this.speciality = "Sales";
}

public Manager(String name, int age, String company, String position, String speciality) {
super(name, age, company, position);
this.speciality = speciality;
}

public String getSpeciality() {
return speciality;
}

public void setSpeciality(String speciality) {
this.speciality = speciality;
}
  
@Override
public String toString()
{
return(super.toString() + ", Speciality: " + getSpeciality());
}

@Override
public void doThis() {
System.out.println("I mange sales.");
}
}

Intern.java

public class Intern extends Employee {
private String duty;
  
public Intern()
{
super();
this.duty = "";
}

public Intern(String name, int age, String company, String position, String duty) {
super(name, age, company, position);
this.duty = duty;
}

public String getDuty() {
return duty;
}

public void setDuty(String duty) {
this.duty = duty;
}
  
@Override
public String toString()
{
return(super.toString() + ", Duty: " + getDuty());
}

@Override
public void doThis() {
System.out.println("I test application.");
}
}

Security.java

public class Security extends Employee {
private String positionToGuard;
  
public Security()
{
super();
this.positionToGuard = "";
}

public Security(String name, int age, String company, String position, String positionToGuard) {
super(name, age, company, position);
this.positionToGuard = positionToGuard;
}

public String getPositionToGuard() {
return positionToGuard;
}

public void setPositionToGuard(String positionToGuard) {
this.positionToGuard = positionToGuard;
}
  
@Override
public String toString()
{
return(super.toString() + ", Position to guard: " + getPositionToGuard());
}

@Override
public void doThis() {
System.out.println("I guard the main entrance.");
}
}

Administrator.java

public class Administrator extends Employee {
private String type;
  
public Administrator()
{
super();
this.type = "HR";
}

public Administrator(String name, int age, String company, String position, String type) {
super(name, age, company, position);
this.type = type;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
  
@Override
public String toString()
{
return(super.toString() + ", Type: " + getType());
}

@Override
public void doThis() {
System.out.println("I do the payroll.");
}
}

Main.java (Main class)

public class Main {
  
public static void main(String[] args) {
SoftwareEngineer Hank = new SoftwareEngineer("Hank", 34, "ABC Company", "Programmer", "Middle", "Java Programmer");
Manager Terry = new Manager("Terry", 44, "DEF Company", "Asst. Senior Manager", "Sales");
Intern Mario = new Intern("Mario", 22, "EFG Company", "Associate C Intern", "Check the import libraries");
Administrator Paula = new Administrator("Paula", 52, "IJK Company", "Senior Administrator", "Secretary");
Security Danilo = new Security("Danilo", 35, "ProGuard Corp", "Security In Charge", "Main Office");
Administrator Barry = new Administrator("Barry", 39, "IJK Company", "Asst. Administrator", "Recruiter");
SoftwareEngineer Peyton = new SoftwareEngineer("Peyton", 36, "ABC Company", "Senior Developer", "Senior", "Both C and Java Programmer");   
Security Wayne = new Security("Wayne", 31, "ProGuard Corp", "Asst. Security In Charge", "Main Entrance");
Manager Phil = new Manager("Phil", 52, "DEF Company", "Asst. Manager", "Division");
SoftwareEngineer Carlos = new SoftwareEngineer("Carlos", 48, "ABC Company", "Senior Programmer", "Senior", "C Programmer");
  
System.out.println("Calling doThis() method for all employee objects..");
Hank.doThis();
Terry.doThis();
Mario.doThis();
Paula.doThis();
Danilo.doThis();
Barry.doThis();
Peyton.doThis();
Wayne.doThis();
Phil.doThis();
Carlos.doThis();
  
System.out.println("\nCalling toString() method for all employee objects..");
System.out.println(Hank);
System.out.println(Terry);
System.out.println(Mario);
System.out.println(Paula);
System.out.println(Danilo);
System.out.println(Barry);
System.out.println(Peyton);
System.out.println(Wayne);
System.out.println(Phil);
System.out.println(Carlos);
}
}

********************************************************* SCREENSHOT *******************************************************

Know the answer?
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
Similar Questions
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and make a java program for your bank. However, there is another type of customer that may not have money in the bank and may not in fact have a back account with this bank at all, but may have a loan here. Make another class in the application you are making called CarLoan. Carloan's should have a name, amount owed, a rate, and a...
Create a student record management system With JAVA using linked list and queue using Java language...
Create a student record management system With JAVA using linked list and queue using Java language and (oracle or any) database to save files and GUI Java swing to create background The program will have the following properties: A. Register students ( assume each students has ID, first name, last name and middle name) B. Register students with courses ( course no ,course title chr ) C. Able to maintain grade on which course they are registered D. Searches students...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
Using JAVA For this assignment, you will analyze code that uses a file input stream and...
Using JAVA For this assignment, you will analyze code that uses a file input stream and a file output stream. Read through the linked Java™ code. In a Microsoft® Word document, answer the following questions: Could this program be run as is? If not, what is it lacking? Does this program modify the contents of an input stream? In what way? What are the results of running this code? ********************************************** CODE TO ANALYZE  ******************************************************** /********************************************************************** *   Program:   Datasort *   Purpose:   ...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT