Computer Science Bin

Code For The Descent

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

/** * The while loop represents the game. * Each iteration represents a turn of the game * where you are given inputs (the heights of the mountains) * and where you have to print an output (the index of the mountain to fire on) * The inputs you are given are automatically updated according to your last actions. **/ class Player {

public static void main(String args[]) { Scanner in = new Scanner(System.in);

int[] mountainHeightArray = new int[8]; int heighestIndex = 0; int temp = 0; // game loop while (true) { for (int i = 0; i < 8; i++) { int mountainH = in.nextInt(); // represents the height of one mountain. mountainHeightArray[i] = mountainH; }

for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (mountainHeightArray[i] > mountainHeightArray[j]) { if (mountainHeightArray[i] > mountainHeightArray[temp]) { temp = i; } } else if (mountainHeightArray[i] < mountainHeightArray[j]) { if (mountainHeightArray[j] > mountainHeightArray[temp]) { temp = j; } } } }

// Write an action using System.out.println() // To debug: System.err.println(“Debug messages...”);

System.out.println(temp); // The index of the mountain to fire on. } } }

Factory, Factory Method, & Abstract Factory in Java

https://www.baeldung.com/cs/factory-method-vs-factory-vs-abstract-factory