I have this problem where trying to increase and decrease a value using a hashmap, I am almost certain I am doing it correctly; however, It is still the incorrect solution
yes, this is a homework question, but I've tried everything and I need some pointers in the right direction
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("src/main/java/data.dat"));
HashMap<String, Integer> costs = new HashMap<>();
while (input.hasNextLine()) {
String line = input.nextLine();
String[] split = line.split(": ");
String company = split[0];
String[] details = split[1].split(" ");
String type = details[0];
int amount = Integer.parseInt(details[1]);
int cost = amount;
if (costs.containsKey(company)) {
cost += costs.get(company);
}
if (type.equals("Seat") || type.equals("Meal") || type.equals("Luggage") || type.equals("Fee") || type.equals("Tax")) {
// Add to cost
costs.put(company, cost);
} else if (type.equals("Discount") || type.equals("Rebate")) {
// Subtract from cost
cost = costs.getOrDefault(company, 0) - amount;
costs.put(company, cost);
}
}
int minimumCost = Integer.MAX_VALUE;
for (int cost : costs.values()) {
if (cost < minimumCost) {
minimumCost = cost;
}
}
System.out.println(minimumCost);
}
}
