§ In BlueJ, create “New Project” named LASTNAME-company Use good programming style and Javadoc documentation standards |
Create a “New Class…” named Company to store the employee mappings of employee names (Key) to employee ids (Value) Declare and initialize class constants MIN and MAX to appropriate values Declare and instantiate a Random randomGenerator field object Declare a String field named name for the company’s name Declare a HashMap<String, String> field named employees Add a constructor with only 1 parameter named name and: Assign name field to name parameter after trim, uppercase & replaceAll (1 or more ANY white space regular expression with just 1 single space) Initialize employees field by creating an instance of that object Add accessors getName( ) and getEmployees( ) Add accessor getTotalNumberEmployees( ) to return the total number of mappings in the collection of the employees field Add formatString(String origString) to return a formatted origString after trim, uppercase, and replaceAll in between white spaces (with single space) MUST first check if origString is null (which just returns an empty String) Add method String generateId(String name) to return the employee id generated by taking the first letter of each word in name parameter AND adding a random 3-digit integer between 100-999 (inclusive of both ends) MUST .split the parameter name into a String[ ] nameArray with regex taking into account multiple white spaces in between words in name MUST use a for loop to get the first letter in each word in nameArray MUST use class constants MIN & MAX (NO hard-code) to generate (using .nextInt) the random number used for the id in the range [MIN – MAX] Add addEmployee(String inputName) & removeEmployee(String inputName) both with void returns and: Check if (trimmed) inputName is empty or null, print “Name is INVALID” MUST use formatString for inputName (remember Strings are immutable) MUST use .containsKey to see if inputName key exists in employees and:Print “Existing: <name>” (if name already exists for addEmployee) OR …“Non-existing: <name>” (if non-existing for removeEmployee) MUST use generateId (for addEmployee) to generate employee id to .put MUST print heading with name & id, if employee add/delete is successful Add void removeIds(String id) to remove ALL mappings in employees where the value matches the id search parameter and: MUST use a local variable to keep track if a match was found MUST also have check if id parameter is null or empty MUST use formatString to format the id input parameter MUST use a for loop, .keySet and .iterator to iterate thru all employees Check if each employee id value is equal (ignoring case) to the search id MUST use the Iterator.remove to remove id matching mappings MUST print heading with name & id for EACH removed employee Only after the entire search is completed (THUS … outside of loop), check if no matches found and print “NO employees with id: <id>” Add void listEmployees() to print ALL employee names (Key) & ids (Value): MUST always print the heading “Employees for <name>:” MUST use getTotalNumberEmployees or .isEmpty to check if NO entries in employees exist and prints“NO employees” MUST use a for-each loop and .keySet to iterate thru all employees MUST print employee in format “ <name> : <id>” (w/ leading spaces) |
Please find below the java program with comments:
import java.util.Scanner; //import section
import java.util.Set;
import java.util.Map;
import java.util.TreeSet;
import java.util.Iterator;
import java.util.TreeMap;
public class Company {
//public
class company declared
public static void main(String[] args) {
TreeMap<String, Employee> firstAndLast =
new TreeMap<String, Employee>();
TreeMap<Integer, Employee> idNumber =
new TreeMap<Integer, Employee>();
TreeMap<Employee, Integer> performanceScale =
new TreeMap<Employee, Integer>();
TreeSet<Integer> sort = new TreeSet<Integer>();
Scanner keyboardInput = new Scanner(System.in);
//Keyboard input accepted here
boolean exit = false;
int choice;
while (exit != true) {
System.out.println("//-----MENU-----//"); //Print Section to
printout all options
System.out.println("1. Add an Employee ");
System.out.println("2. Remove an Employee ");
System.out.println("3. Modify performance scale ");
System.out.println("4. Print all the performance scale ");
System.out.println("5. Sort first and last name based on ID
");
System.out.println("6. Exit the program.");
System.out.print("Enter choice: ");
choice = keyboardInput.nextInt();
switch (choice) { //switch cases
case 1:
//Case 1
addEmployee(firstAndLast, idNumber, performanceScale);
break;
case 2:
//Case 2
removeEmployee(firstAndLast, idNumber, performanceScale);
break;
case 3:
//Case 3
modifyPerformanceScale(idNumber, performanceScale);
break;
case 4:
//Case 4
printAllperfScale(performanceScale);
break;
case 5:
//Case 5
printLastNameAscending(firstAndLast, idNumber);
break;
case 6:
//Case 6
exit = true;
System.out.println("Exiting program..."); /Program will exit
break;
default:
System.out
.println("Please choose a number from 1 - 5 from the menu.");
//Print Section
}
}// end while
} // end main
public static void addEmployee(TreeMap<String, Employee>
firstAndLastMap, //addemployee() finction
TreeMap<Integer, Employee> idNumberMap,
TreeMap<Employee, Integer> performanceScale) {
Scanner keyboardInput = new Scanner(System.in);
String firstName;
String lastName;
int id;
int perfScale;
System.out.print("Enter first name for the Employee: "); //Enter
the first name here
firstName = keyboardInput.nextLine();
System.out.print("Enter last name for the Employeer: ");
lastName = keyboardInput.nextLine();
System.out.print("Enter ID number of the Employee: ");
id = keyboardInput.nextInt();
System.out.print("Enter Performance Scale rating between 1 to 5:
");
perfScale = keyboardInput.nextInt();
Employee addEmployee = new Employee(lastName, firstName, id,
perfScale); //Add the employees here
firstAndLastMap.put(lastName + ", " + firstName,
addEmployee);
idNumberMap.put(id, addEmployee);
//changed - Added(addEmployee,perfScale) from put(perfScale)
performanceScale.put(addEmployee, perfScale);
}
public static void removeEmployee(TreeMap<String, Employee>
firstAndLastMap,
TreeMap<Integer, Employee> idNumberMap,
TreeMap<Employee, Integer> performanceScale) {
Scanner keyboardInput = new Scanner(System.in);
String firstName;
String lastName;
int id;
System.out.print("Enter First name of Employee you want to remove:
");
firstName = keyboardInput.nextLine();
System.out.print("Enter last name of Employee you want to remove:
");
lastName = keyboardInput.nextLine();
System.out.print("Enter ID number of Employee you want to remove:
");
id = keyboardInput.nextInt();
//System.out.println();
// Print section
firstAndLastMap.remove(lastName + ", " + firstName);
idNumberMap.remove(id);
//This should be remove(perfScale)
}
//To change TreeMap<String, emp...to <Integer, emp
public static void modifyPerformanceScale(TreeMap<Integer,
Employee> idNumber,
TreeMap<Employee, Integer> performanceScale) {
//modifyPerformanceScale()
declared
System.out.print("Enter ID: ");
Scanner keyboardInput = new Scanner(System.in);
//input through the
keyboard
int idNumber1;
int modScale;
idNumber1 = keyboardInput.nextInt();
System.out.print("Enter the number you want to change to: ");
modScale = keyboardInput.nextInt();
//input through the
keyboard
Employee employee = idNumber.get(idNumber1);
//employee details
performanceScale.put(employee, modScale);
}
public static void
printAllperfScale(TreeMap<Employee,Integer> performanceScale)
{ //printAllperfScale() declared
here
Set Employee1 = performanceScale.entrySet();
Iterator itr1 = Employee1.iterator();
while (itr1.hasNext()) {
Map.Entry me = (Map.Entry) itr1.next();
System.out.println(me.getValue());
}
}
public static void printLastNameAscending(TreeMap<String,
Employee> LastName,
TreeMap<Integer, Employee>idNumber) {
//printLastNameAscending()
method declared
Set Employee1 = LastName.entrySet();
//set employee details
here
Set Employee2 = idNumber.entrySet();
Iterator itr1 = Employee1.iterator();
Iterator itr2 = Employee2.iterator();
while (itr1.hasNext() && itr2.hasNext()) {
Map.Entry me = (Map.Entry) itr1.next();
Map.Entry be = (Map.Entry) itr2.next();
System.out.print(me.getValue()+ " ID: ");
System.out.println(be.getValue());
}
}
}
§ In BlueJ, create “New Project” named LASTNAME-company Use good programming style and Javadoc documentation standards...
Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File Explorer onto the BlueJ project window.) Otherwise, use the instructor's App class: Create a new class using the "New Class..." button and name it App. Open the App class to edit the source code. Select and delete all the source code so that the file is...
Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...
Open BlueJ and create a new project (Project->New Project...). Create a new class named ListsDemo. Open the source code and delete all the boilerplate code. Type in the code to type (code to type with bigger font) exactly as shown, filling in your name and the date in the places indicated. The code is provided as an image because you should type it in rather than copy-paste. If you need the code as text for accessibility, such as using a...
Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...
In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...
PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...
I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...
Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...
Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....
Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it...