Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Assignment Create an Employee class that stores an employees ID number and name. Then create an EmployeeMap class that allows you to add Employee

Java Assignment

Create an Employee class that stores an employees ID number and name. Then create an EmployeeMap class that allows you to add Employee objects and look them up by their ID numbers. The EmployeeMap class should use a Mapobject to map ID numbers to Employee objects. Create an application to demonstrate the classes.

You MUST use the Outline/Help files that follows.

File 1

/** Employee Class */ public class Employee { // Fields // ID number // Employee name /** Constructor @param idNumber The employee's ID number. @param empName The employee's name. */ public Employee(String idNumber, String empName) { } /** getIdNumber method @return The employee's ID number. */ public String getIdNumber() {

} /** getName method @return The employee's name. */ public String getName() { } /** toString method @return A string with the employee's ID number and name. */ public String toString() { } }

File 2

import java.util.Map; import java.util.HashMap; /** EmployeeMap Class */ public class EmployeeMap {

/**create a private Map objectVarName

/** Constructor */ public EmployeeMap() { // Instantiate map. Using new keyword HashMap() } /** The add method creates a mapping in the map. An employee ID number is mapped to an Employee object. @param e The Employee object to create the mapping with. */ public void add(Employee e) //Use put keyword(e.getIdNum(),e { } /** The get method retrieves the Employee object that is associated with a specific ID number. @param idNumber An employee ID number. @return The Employee object associated with the specified ID number. Returns null if no mapping exists for the ID number. */ public Employee get(String idNumber)//return employeeMap.get(idNum) { return empMap.get(idNumber); } }

File 3

/*Describe the assignment*/

public class EmployeeMapDemo { public static void main(String[] args) { // Create an instance of EmployeeMap. // Create an array of employees for example Employee nameofArray[] = { new Employee("123", "Jack Shepard"),

}; // Add the employees to EmployeeMap using a loop and add methods

// Search for the mappings that we just added. searchEmployee(objectVar, "123"); // Now search for a mapping that does not exist. searchEmployee(objectVar, "999"); } public static void searchEmployee(EmployeeMap objectVar, String id) { // Get the Employee object associated with id. // If an Employee was returned, display it. } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions