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

46 lines
1.4 KiB
Java
Raw Normal View History

2021-12-03 02:27:00 +00:00
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class part2{
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;
int aim = 0;
do{
String inputLine = fileIn.nextLine();
System.out.println(inputLine);
String[] operations = inputLine.split(" ");
switch(operations[0]){
case "forward":
movement += Integer.parseInt(operations[1]);
depth += aim * Integer.parseInt(operations[1]);
break;
case "up":
aim -= Integer.parseInt(operations[1]);
break;
case "down":
aim += Integer.parseInt(operations[1]);
break;
default:
break;
}
} while(fileIn.hasNextLine());
fileIn.close();
System.out.printf("Depth: %d | Movement: %d | Value: %d", depth, movement, (depth * movement));
} catch(FileNotFoundException e){
e.printStackTrace();
}
}
}