Question

(JAVA) I need to write an accessor method for the employeeDatabase field. The method is supposed to be named getEmployeeDatabase() and have a return type of Hashmap<Integer,Employee>. I have also included the test case below that is being used for this code to see if it works properlyprivate HashMap<Integer, Employee> employeeDatabase; public CompanyO f Scanner employeeDatabasepopulateEmployeeDatabase(keyboard) keyboard - new Scanner(System.in); public static void main(String[ args) private HashMap<Integer, Employee> populateEmployeeDatabase(Scanner keyboard) int numobjects -keyboard.nextIntO; String words HashMap <Integer, Employee mapnew HashMap<>); keyboard.nextLine); forCint i< numObjects; ++i) words-keyboard.nextLineO.split(,); map.put(i, new Employee(i, words[0], Double.parseDouble(words[1])); return map;

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.HashMap;
import java.util.Scanner;

public class Company {

    private HashMap<Integer, Employee> employeeDatabase;

    public Company() {
        Scanner keyboard = new Scanner(System.in);
        employeeDatabase = populateEmployeeDatabase(keyboard);
    }

    // accessor method for the employeeDatabase field
    public HashMap<Integer, Employee> getEmployeeDatabase() {
        return employeeDatabase;
    }

    private HashMap<Integer, Employee> populateEmployeeDatabase(Scanner keyboard) {
        int numObjects = keyboard.nextInt();
        String words[];
        HashMap<Integer, Employee> map = new HashMap<>();
        keyboard.nextLine();
        for(int i = 0; i < numObjects; ++i) {
            words = keyboard.nextLine().split(",");
            map.put(i, new Employee(i, words[0], Double.parseDouble(words[1])));
        }
        return map;
    }

}

Hey, Please let me know if you need me to make any changes I would really appreciate an upvote. Thank you!

Add a comment
Know the answer?
Add Answer to:
(JAVA) I need to write an accessor method for the employeeDatabase field. The method is supposed...
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
  • Hello, can get some help with simple pseudocode describing the steps for this program below? THUMBS...

    Hello, can get some help with simple pseudocode describing the steps for this program below? THUMBS UP always left for help! public class TimeDemo {    private static Scanner keyboard; private static String enteredTime; private static Time now; public static void main (String [] args)    {        keyboard = new Scanner(System.in);        char answer = 'Y';        enteredTime = null;        String response;        while (answer== 'Y')        {            System.out.print(                "Enter a military time using the ##:##...

  • JAVA: Rewrite the following code to where the inputs are from a file. The file name...

    JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user scanner. CODE: import java.util.*; public class Q1 { public static int sumOD (int k) { int sumOD = 0; int in = k; while (in != 0) { int digitON = in % 10; sumOD += digitON; in /= 10; } return sumOD; }    public static void main(String[] args) { int n, i, k; System.out.println("Enter...

  • Hey Guys , I need help with this assignment: This component of the final exam will...

    Hey Guys , I need help with this assignment: This component of the final exam will have two data structures. The two data structures will be a stack and the other will be a hashmap. The hashmap object will be added to the stack every time the user picks an answer. The hashmap will have a key and value. The key will be the timestamp (system time when the user selected a choice) and the value will be the choice...

  • I have most of the code for this assignment but need some help getting the rest....

    I have most of the code for this assignment but need some help getting the rest. Go to bottom to see what I have. Please help me figure out the foreach loops and the put() statement. In this assignment, you will be using a new data structure, HashMaps, to repeat Assignment 8.3. Main Method (5 points) Declare and initialize an HashMap with values of type of type Employee, and keys of type integer. In a while loop, keep initializing objects...

  • Write a program that stores a phrase as an array of words, and then prints it...

    Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{    public static void main(String[] args) {    String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • JAVA Modify the code to create a class called box, wherein you find the area. I...

    JAVA Modify the code to create a class called box, wherein you find the area. I have the code in rectangle and needs to change it to box. Here is my code. Rectangle.java public class Rectangle { private int length; private int width;       public void setRectangle(int length, int width) { this.length = length; this.width = width; } public int area() { return this.length * this.width; } } // CONSOLE / MAIN import java.awt.Rectangle; import java.util.Scanner; public class Console...

  • Write in Java Implement the parse method and test it by calling with three different strings...

    Write in Java Implement the parse method and test it by calling with three different strings and by printing the results. The Scanner method can be used to read values from strings, files, or System.in. We need to invoke the useDelimiter method to define what symbols can separate, or terminate, the digits of a Fraction. public static Fraction parse(String input) t Scanner s new Scanner(input) useDelimitercTVMitln"); int num s.nextlnt() int denom s.nextlnt); s.close): return new Fraction(num, denom) class Codechef static...

  • I wrote two java classes. One is main and other one is getter and setter. I...

    I wrote two java classes. One is main and other one is getter and setter. I brought methods from Digit class to Main class to print result. However, for some reason, only welcome print statement got printed and others got ignored. On the output screen, only welcome statement appear. nDigit should be input from user. import java.util.Scanner; public class Main {    public static void main(String[] args)    {        Digit digitGet = new Digit();              ...

  • Write a java programm that calculates the total of a retail sale should ask the user...

    Write a java programm that calculates the total of a retail sale should ask the user for the following: The retail price of the item being purchased The sales tax rate Once these items have been entered, the program should calculate and display the following: The sales tax for the purchase The total of the sale I tried doing it here. but it is not giving me the right answer. kindly help correct the errors. import java.util.Scanner; public class SalesTax...

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