Project #45224 - java HW

 

 

Objective:

 

Write a class that represents a person in a simple way

  • First download the LB15 Driver and put it in your project
    • DO NOT ALTER THE DRIVER!
  • Write a class file called SimplePerson that DOES NOT HAVE a main method
  • Some of the attributes of SimplePerson are
    • Name
  • Create the following Constructors
    • Default – sets everything to default values
      • Name = No name yet
    • One that has the parameters
      • Name
  • Accessors and Mutators for each variable
    • MAKE SURE THE MUTATORS CHECK FOR VALID VALUES!
  • Create the following Methods
    • writeOutput – This prints out “Name: “ and the person’s name
    • hasSameName – this takes in another SimplePerson object and then returns a true if their names are the same
    • equals – this should override the base object equals method and should return true if the person’s name is equal.

 

Write another class that represents an employee

  • Write a class called Employee that also DOES NOT HAVE a main method
  • Since an employee IS A person make it so that employee derives from the person
  • Some of the attributes of an Empolyee are
    • Annual Salary (assumed to be a decimal value)
    • Hire date (a string should work)
    • ID number (assumed to be a whole number)
  • Create the following constructors
    • Default – sets everything to default values
      • Name = No name yet
      • Salary = 0
      • Hire date = Not hired
      • ID number = 0
    • One that takes in parameters (in this order)
      • Name
      • Salary
      • Hire Date
      • ID number
  • Accessors and Mutators for each variable
    • MAKE SURE THE MUTATORS CHECK FOR VALID VALUES!
  • Create the following methods
    • equals – this should override the object base equals method and it should test whether another employee has the same name, salary, hire date, and id number
    • writeOutput – Prints out the information about the employee including their nae, salary, hire date, and id number

 

 

Example Dialog:

Welcome to the Company Management Software!

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

1

Enter their name

JJ

Enter their hire date

1/1/2011

Enter thier salary

20000

Enter the employee number

1

Name : JJ

Makes 20000.0

Was hired 1/1/2011

ID number is 1

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

1

Enter their name

Bob

Enter their hire date

1/2/2010

Enter thier salary

25000

Enter the employee number

2

Name : Bob

Makes 25000.0

Was hired 1/2/2010

ID number is 2

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

1

Enter their name

JJ

Enter their hire date

1/1/2011

Enter thier salary

20000

Enter the employee number

1

Name : JJ

Makes 20000.0

Was hired 1/1/2011

ID number is 1

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

3

Enter the two indices corresponding to the employees

0

1

These employees are the different!

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

3

Enter the two indices corresponding to the employees

0

2

These employees are the same!

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

2

Enter the employees id number

2

Name : JJ

Makes 20000.0

Was hired 1/1/2011

ID number is 1

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

2

Enter the index number of the employee

1

Name : Bob

Makes 25000.0

Was hired 1/2/2010

ID number is 2

What would you like to do?

1. Hire a new employee

2. Look up information on an employee

3. Compare two employees

4. Quit

4

Finally:

Upload Person.java file to the dropbox

 

 

 

LB15 DRIVER

 

import java.util.*;
public class Company {

	/**
	 * @param args
	 */
	private Employee[] employees;
	private static final int MAX_EMPLOYEES = 10;
	private int currEmployees;
	static Scanner keyboard = new Scanner(System.in);
	public Company()
	{
		this.employees = new Employee[MAX_EMPLOYEES];
		this.currEmployees = 0;
	}
	/*
	 * Adds a new employee to the array
	 */
	public void Hire()
	{
		//If the company is full then it cannot hire anymore
		if(currEmployees>=MAX_EMPLOYEES)
		{
			System.out.println("The company is no longer hiring");
			return;
		}
		
		//Gets the information about the new employee
		String name;
		String hireDate;
		double salary;
		int idNumber;
		System.out.println("Enter their name ");
		name = keyboard.nextLine();
		System.out.println("Enter their hire date ");
		hireDate = keyboard.nextLine();
		System.out.println("Enter thier salary ");
		salary = keyboard.nextDouble();
		System.out.println("Enter the employee number");
		idNumber = keyboard.nextInt();
		//Creates a new instance of an employee.
		Employee newEmployee = new Employee(name,salary,hireDate,idNumber);
		newEmployee.writeOutput();
		//Adds the new employee to the list
		employees[currEmployees] = newEmployee;
		//Increases the current number of employees
		currEmployees++;
	}
	public void LookUpEmployee(int idNumber)
	{
		if(idNumber<0||idNumber>=MAX_EMPLOYEES)
		{
			System.out.println("Invalid id number!");
		}
		else
		{
			employees[idNumber].writeOutput();
		}
	}
	public void CompareEmployees(int index1, int index2)
	{
		if(employees[index1].equals(employees[index2]))
		{
			System.out.println("These employees are the same!");
		}
		else
		{
			System.out.println("These employees are the different!");
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//Create a new instance of a company
		Company c = new Company();
		//prompt the user
		System.out.println("Welcome to the Company Management Software!");
		boolean quit = false;
		int input = 0;
		while(quit == false)
		{
			//Prompt the user
			System.out.println("What would you like to do?");
			System.out.println("1. Hire a new employee");
			System.out.println("2. Look up information on an employee");
			System.out.println("3. Compare two employees");
			System.out.println("4. Quit");
			//Get the input
			input = keyboard.nextInt();
			keyboard.nextLine();
			switch(input)
			{
			case 1:
				c.Hire();
				break;
			case 2:
				System.out.println("Enter the index number of the employee");
				input = keyboard.nextInt();
				c.LookUpEmployee(input);
				break;
			case 3:
				System.out.println("Enter the two indices corresponding to the employees");
				c.CompareEmployees(keyboard.nextInt(), keyboard.nextInt());
				break;
			case 4:
				quit = true;
				break;
			default:
				System.out.println("Invalid input");
				break;
			}
		}

	}

}

 

 

Subject Computer
Due By (Pacific Time) 10/28/2014 11:30 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy