×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Program That Implements Hash Maps Using Java Programming Language Assignment Solution

June 13, 2024
Dr. Seraphina Stormcloud
Dr. Seraphina
🇬🇧 United Kingdom
Java
Dr. Seraphina Stormcloud is a highly accomplished computer scientist who obtained her PhD from the prestigious University of Oxford, followed by post-doctoral research at the University of Cambridge in the UK. With seven years of experience under her belt, Seraphina has completed over 700 Java Homework assignments with exceptional skill and proficiency.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

Instructions

Objective

Write a java assignment program to implement hash maps using programming language.

Requirements and Specifications

Implement-hash-maps-using-Java-programming-language (1)

Source Code

package reports; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.text.MessageFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class ReportsMain { private static final String INPUT_FOLDER = "Resources"; private static final String OUTPUT_FOLDER = "Reports"; private static final String INPUT_FILENAME = "TimeDataMedium"; private static final String CLIENT_OUTPUT_PREFIX = "Client"; private static final String EMPLOYEE_OUTPUT_PREFIX = "Employee"; public static void main(String[] args) { Map employees = new HashMap<>(); Map> clients = new HashMap<>(); try (Scanner scanner = new Scanner(new File(INPUT_FOLDER + "/" + INPUT_FILENAME + ".csv"))) { scanner.nextLine(); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); String[] parts = line.split(","); String employee = parts[0].trim(); String info = parts[1].trim(); String client = parts[3].trim(); if (!client.isEmpty()) { Set singleEmployee = new HashSet<>(); singleEmployee.add(employee); clients.merge(client, singleEmployee, (a, b) -> { a.addAll(b); return a; }); } if (info.equals("Clock In/Out")) { long minutes = getMinutes(parts[4], parts[5], parts[6], parts[7]); employees.merge(employee, minutes, Long::sum); } } } catch (IOException e) { throw new RuntimeException(e); } printClientReport(clients); printEmployeeReport(employees); } private static void printClientReport(Map> clients) { try (PrintWriter writer = new PrintWriter(OUTPUT_FOLDER + "/" + CLIENT_OUTPUT_PREFIX + INPUT_FILENAME + ".txt")) { List clientList = new ArrayList<>(clients.keySet()); Collections.sort(clientList); for (String client : clientList) { List employees = new ArrayList<>(clients.get(client)); Collections.sort(employees); writer.write(MessageFormat.format("CLIENT: {0} --- EMPLOYEES: [{1}]" + System.lineSeparator(), client, String.join(", ", employees))); } } catch (IOException e) { throw new RuntimeException(e); } } private static void printEmployeeReport(Map employees) { try (PrintWriter writer = new PrintWriter(OUTPUT_FOLDER + "/" + EMPLOYEE_OUTPUT_PREFIX + INPUT_FILENAME + ".txt")) { List employeeList = new ArrayList<>(employees.keySet()); Collections.sort(employeeList); for (String employee : employeeList) { Long minutes = employees.get(employee); int hours = (int)(minutes/60); int mins = (int)(minutes%60); String formatted = String.format("%02d:%02d", hours, mins); writer.write(MessageFormat.format("EMPLOYEE: {0} --- TIME: {1}" + System.lineSeparator(), employee, formatted)); } } catch (IOException e) { throw new RuntimeException(e); } } private static long getMinutes(String startTime, String endTime, String startDate, String endDate) { SimpleDateFormat format = new SimpleDateFormat("hh:mm a dd/MM/yyyy"); Date start = null; Date end = null; try { start = format.parse(startTime + " " + startDate); end = format.parse(endTime + " " + endDate); } catch (ParseException e) { e.printStackTrace(); return 0; } long diff = end.getTime() - start.getTime(); return diff / (60 * 1000); } }

Similar Sample

Explore our sample solutions to see the quality of work we deliver. Each example demonstrates our expertise in various programming languages and our problem-solving skills. Discover why students trust us for their programming homework needs and experience our dedication to excellence.