1
0
Fork 0
Advent2021/Day 2/Justin/Java/part1.java

44 lines
1.3 KiB
Java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class part1{
public static void main(String[] args){
File input = new File("Day 2/Justin/Java/input.txt");
try{
// Get the file, and start to read it
Scanner fileIn = new Scanner(input);
int depth = 0;
int movement = 0;
do{
String inputLine = fileIn.nextLine();
System.out.println(inputLine);
String[] operations = inputLine.split(" ");
switch(operations[0]){
case "forward":
movement += Integer.parseInt(operations[1]);
break;
case "up":
depth -= Integer.parseInt(operations[1]);
break;
case "down":
depth += Integer.parseInt(operations[1]);
break;
default:
break;
}
} while(fileIn.hasNextLine());
fileIn.close();
System.out.println(depth * movement);
} catch(FileNotFoundException e){
e.printStackTrace();
}
}
}