Changed switch to Enhanced Switch.

This commit is contained in:
Jonathan Turner 2024-02-14 12:47:18 -05:00
parent 5f37a3a97b
commit 00edd1e95d

View File

@ -30,7 +30,7 @@ public class FakeCoin extends Application {
@Override
public void executeOption(int option) {
switch (option) {
case 1:
case 1 -> {
System.out.println("Please enter a number of coins in the pile (including fake coin).");
System.out.print("Coin Count: ");
int numOfCoins = this.getIntegerInput();
@ -41,39 +41,38 @@ public class FakeCoin extends Application {
numOfCoins = this.getIntegerInput();
}
this.pile = new Coin[numOfCoins];
break;
case 2:
}
case 2 -> {
if (this.pile == null) {
System.out.println("Please specify a number of coins before setting the fake location.");
break;
}
System.out.println("Please specify a location for the fake coin. Between 0 and " + (this.pile.length-1));
System.out.println("Please specify a location for the fake coin. Between 0 and " + (this.pile.length - 1));
System.out.print("Location: ");
int location = this.getIntegerInput();
while (location < 0 || location >= this.pile.length) {
System.out.println();
System.out.println("Please enter a valid location: Between 0 and " + (this.pile.length-1));
System.out.println("Please enter a valid location: Between 0 and " + (this.pile.length - 1));
System.out.print("Location: ");
location = this.getIntegerInput();
}
/* Implement the functionality to do both lighter and heavier. */
this.pile[location] = new Fake(location,true);
this.pile[location] = new Fake(location, true);
for (int i = 0; i < this.pile.length; i++) {
if (this.pile[i] == null) {
this.pile[i] = new Coin(i);
}
}
this.setLocation = true;
break;
case 3:
}
case 3 -> {
if (!this.setLocation) {
System.out.println("Please specify the fake coins location.");
break;
}
this.performAlgorithm();
break;
}
}
System.out.println();
}