Source Code

Session10.java

import java.util.*;
import java.io.*;

public class Session10 {
    public static void main(String[] args) {
        String myName = ""; // add your name
        System.out.println("Session 10" + " - " + myName);

        // Menu
        System.out.println("Menu");
        System.out.println("E1 - Example 1");
        System.out.println("Q  - Quit");

        // setup Scanner
        Scanner in = new Scanner(System.in);
        System.out.print("Choice: ");
        String choice = in.nextLine();

        // switch choices
        switch (choice) {
            case "E1":
                System.out.println("Example 1");
                example1();
                break;
            case "E2":
                System.out.println("Example 2");
                example2();
                break;
            case "E3":
                System.out.println("Example 3");
                example3();
                break;
            case "E4":
                System.out.println("Example 4");
                example4();
                break;
            case "Q":
                System.out.println("Quitting..!");
                break;
        }
    }

    // example1 method
    public static void example1() {
        // declare arrays


        // traverse arrays
 

        // first student name
        
        // first student grade
        

    }

    // example2 method
    public static void example2() {
        // Create and initialize the parallel ArrayLists
        

        // traverse ArrayLists
        

        // add to ArrayLists
        

        // print ArrayLists
        

    }

    // example3 method
    public static void example3() {
        // Create a HashMap
        

        // add elements
        

        // traverse HashMap
        

        // check and remove
        

    }

    // example4 method
    public static void example4() {
        // create HashMap
        HashMap<String, Double> inventory = new HashMap<>();

        // open file
        try {
            File file = new File("newegg.csv");
            Scanner scanner = new Scanner(file);

            // Skip the first line (header)
            if (scanner.hasNextLine()) {
                scanner.nextLine();
            }
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                String[] parts = line.split(",");
                String item = parts[0].trim();
                double price = Double.parseDouble(parts[1].trim());
                inventory.put(item, price);
            }
            scanner.close();
        } catch (FileNotFoundException e) {
            System.out.println("File not found: newegg.csv");
        }

        // Print the loaded inventory
        

    }
}

newegg.csv

Part Name,Price
Intel Core i9-12900K,303.26
AMD Ryzen 7 7800X3D,340.05
Gigabyte Radeon RX 7600 XT 16GB,359.97
Samsung 990 PRO 1TB NVMe SSD,99.99
WD Black SN850X 1TB NVMe SSD,274.37
ASRock Phantom Gaming PG-850G PSU,99.99
64GB DDR5 6000MHz RGB Memory Kit,279.99
IceGiant ProSiphon Titan-TR 360 Cooler,439.99
Coolerguys LGA1700 240W Tower Cooler,59.95
iFixit Thermal Paste,9.95

Last updated