|
|
@@ -5,10 +5,40 @@ import java.util.concurrent.ThreadLocalRandom; |
|
|
|
|
|
|
|
class runLabs { |
|
|
|
public static void main(String[] args) { |
|
|
|
// new Lab4(); |
|
|
|
// new Lab5(); |
|
|
|
new Lab6(); |
|
|
|
// new Lab7(); |
|
|
|
int choice = labChoice(); |
|
|
|
switch (choice) { |
|
|
|
case 4: |
|
|
|
new Lab4(); |
|
|
|
break; |
|
|
|
case 5: |
|
|
|
new Lab5(); |
|
|
|
break; |
|
|
|
case 6: |
|
|
|
new Lab6(); |
|
|
|
break; |
|
|
|
case 7: |
|
|
|
new Lab7(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static int labChoice() { |
|
|
|
Scanner userInput = new Scanner(System.in); |
|
|
|
System.out.println(String.format("Please enter a lab number (4-7) or q/quit to quit")); |
|
|
|
while (true) { |
|
|
|
if (userInput.hasNextInt()) { |
|
|
|
int userChoice = userInput.nextInt(); |
|
|
|
userInput.nextLine(); |
|
|
|
if ((userChoice >= 4) && (userChoice <= 7)) { |
|
|
|
return userChoice; |
|
|
|
} |
|
|
|
} else if (userInput.hasNext()) { |
|
|
|
String userString = userInput.nextLine(); |
|
|
|
if ((userString.equals("q")) || (userString.equals("quit"))) { |
|
|
|
System.exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -261,9 +291,9 @@ class Lab4 extends Lab { |
|
|
|
class Lab5 extends Lab { |
|
|
|
public Lab5() { |
|
|
|
super(5); |
|
|
|
// new five1(); |
|
|
|
// new five5(); |
|
|
|
// new five6(); |
|
|
|
//new five1(); |
|
|
|
new five5(); |
|
|
|
new five6(); |
|
|
|
new five7(); |
|
|
|
} |
|
|
|
|
|
|
@@ -308,7 +338,7 @@ class Lab5 extends Lab { |
|
|
|
double radius = kbIn.nextDouble(); |
|
|
|
kbIn.nextLine(); |
|
|
|
summariseCircle(radius); |
|
|
|
kbIn.close(); |
|
|
|
// kbIn.close(); |
|
|
|
} |
|
|
|
|
|
|
|
public void summariseCircle(double radius) { |
|
|
@@ -356,7 +386,7 @@ class Lab5 extends Lab { |
|
|
|
|
|
|
|
System.out.println(String.format("Your name is %s and your age is %d", |
|
|
|
userName, userAge)); |
|
|
|
kbIn.close(); |
|
|
|
// kbIn.close(); |
|
|
|
inputOps.close(); |
|
|
|
} |
|
|
|
} |
|
|
@@ -396,7 +426,7 @@ class Lab5 extends Lab { |
|
|
|
userDOB.getTime(), |
|
|
|
Lab4.yearsOld(today, userDOB))); |
|
|
|
|
|
|
|
userInput.close(); |
|
|
|
// userInput.close(); |
|
|
|
processInput.close(); |
|
|
|
|
|
|
|
} |
|
|
@@ -416,7 +446,7 @@ class Lab6 extends Lab { |
|
|
|
new six7(); |
|
|
|
new six8(); |
|
|
|
new six9(); |
|
|
|
// new six5(); |
|
|
|
new six5(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -484,7 +514,7 @@ class Lab6 extends Lab { |
|
|
|
if (guess == chosenNumber) { |
|
|
|
System.out.println(String.format("\nYou guessed right after %d %s! It was indeed %d", |
|
|
|
i+1, guesses, chosenNumber)); |
|
|
|
userInput.close(); |
|
|
|
// userInput.close(); |
|
|
|
return; |
|
|
|
} |
|
|
|
guesses = "guesses"; // didn't get it on the first try |
|
|
@@ -509,7 +539,7 @@ class Lab6 extends Lab { |
|
|
|
} |
|
|
|
|
|
|
|
System.out.println(String.format("\nThe answer was: %d. Better luck next time!", chosenNumber)); |
|
|
|
userInput.close(); |
|
|
|
// userInput.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@@ -660,7 +690,7 @@ class Lab6 extends Lab { |
|
|
|
if ((choiceNumber < 0) || (choiceNumber > 2)) { |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
userInput.close(); |
|
|
|
// userInput.close(); |
|
|
|
Throw[] throwsArray = Throw.values(); |
|
|
|
return throwsArray[choiceNumber]; |
|
|
|
} |
|
|
@@ -669,13 +699,13 @@ class Lab6 extends Lab { |
|
|
|
switch (choiceString.toLowerCase()) { |
|
|
|
case "rock": |
|
|
|
case "stone": |
|
|
|
userInput.close(); |
|
|
|
// userInput.close(); |
|
|
|
return Throw.ROCK; |
|
|
|
case "paper": |
|
|
|
userInput.close(); |
|
|
|
// userInput.close(); |
|
|
|
return Throw.PAPER; |
|
|
|
case "scissors": |
|
|
|
userInput.close(); |
|
|
|
// userInput.close(); |
|
|
|
return Throw.SCISSORS; |
|
|
|
case "q": |
|
|
|
case "quit": |
|
|
|