Browse Source

(feat) add small menu asking user which section to run

main
Rob Hallam 1 year ago
parent
commit
d73a16576d
1 changed files with 47 additions and 17 deletions
  1. +47
    -17
      week1.java

+ 47
- 17
week1.java View File

@@ -5,10 +5,40 @@ import java.util.concurrent.ThreadLocalRandom;


class runLabs { class runLabs {
public static void main(String[] args) { 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 { class Lab5 extends Lab {
public Lab5() { public Lab5() {
super(5); super(5);
// new five1();
// new five5();
// new five6();
//new five1();
new five5();
new five6();
new five7(); new five7();
} }


@@ -308,7 +338,7 @@ class Lab5 extends Lab {
double radius = kbIn.nextDouble(); double radius = kbIn.nextDouble();
kbIn.nextLine(); kbIn.nextLine();
summariseCircle(radius); summariseCircle(radius);
kbIn.close();
// kbIn.close();
} }


public void summariseCircle(double radius) { 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", System.out.println(String.format("Your name is %s and your age is %d",
userName, userAge)); userName, userAge));
kbIn.close();
// kbIn.close();
inputOps.close(); inputOps.close();
} }
} }
@@ -396,7 +426,7 @@ class Lab5 extends Lab {
userDOB.getTime(), userDOB.getTime(),
Lab4.yearsOld(today, userDOB))); Lab4.yearsOld(today, userDOB)));


userInput.close();
// userInput.close();
processInput.close(); processInput.close();


} }
@@ -416,7 +446,7 @@ class Lab6 extends Lab {
new six7(); new six7();
new six8(); new six8();
new six9(); new six9();
// new six5();
new six5();
} }


/** /**
@@ -484,7 +514,7 @@ class Lab6 extends Lab {
if (guess == chosenNumber) { if (guess == chosenNumber) {
System.out.println(String.format("\nYou guessed right after %d %s! It was indeed %d", System.out.println(String.format("\nYou guessed right after %d %s! It was indeed %d",
i+1, guesses, chosenNumber)); i+1, guesses, chosenNumber));
userInput.close();
// userInput.close();
return; return;
} }
guesses = "guesses"; // didn't get it on the first try 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)); 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)) { if ((choiceNumber < 0) || (choiceNumber > 2)) {
continue; continue;
} else { } else {
userInput.close();
// userInput.close();
Throw[] throwsArray = Throw.values(); Throw[] throwsArray = Throw.values();
return throwsArray[choiceNumber]; return throwsArray[choiceNumber];
} }
@@ -669,13 +699,13 @@ class Lab6 extends Lab {
switch (choiceString.toLowerCase()) { switch (choiceString.toLowerCase()) {
case "rock": case "rock":
case "stone": case "stone":
userInput.close();
// userInput.close();
return Throw.ROCK; return Throw.ROCK;
case "paper": case "paper":
userInput.close();
// userInput.close();
return Throw.PAPER; return Throw.PAPER;
case "scissors": case "scissors":
userInput.close();
// userInput.close();
return Throw.SCISSORS; return Throw.SCISSORS;
case "q": case "q":
case "quit": case "quit":


Loading…
Cancel
Save