Assignment
M5Assignment1.java
import java.util.*;
public class M5Assignment1 {
public static void main(String[] args) {
System.out.println("Module 5 Assignment 1");
// Create new Scanner object (don't delete!)
Scanner in = new Scanner(System.in);
// menu variables
boolean done = false;
String choice;
// do while menu loop
do {
System.out.println("P1 - Problem 1");
System.out.println("P2 - Problem 2");
System.out.println("P3 - Problem 3");
System.out.println("P4 - Problem 4");
System.out.println("P5 - Problem 5");
System.out.println("Q - Quit");
System.out.print("Choice: ");
choice = in.nextLine();
switch (choice) {
case "P1":
System.out.println("Problem 1");
break;
case "P2":
System.out.println("Problem 2");
break;
case "P3":
System.out.println("Problem 3");
break;
case "P4":
System.out.println("Problem 4");
break;
case "P5":
System.out.println("Problem 5");
break;
// quit and default cases
case "Q":
System.out.println("Quit");
done = true;
break;
default:
System.out.println("Invalid Choice");
break;
}
} while (!done);
// close the Scanner (don't delete!)
in.close();
}
// problem1 method
// problem2 method
// problem3 method
}
M5Assignment2.java
import java.util.*;
public class M5Assignment2 {
public static void main(String[] args) {
System.out.println("Module 5 Assignment 2");
// Create new Scanner object (don't delete!)
Scanner in = new Scanner(System.in);
// menu variables
boolean done = false;
String choice;
// do while menu loop
do {
System.out.println("P1 - Problem 1");
System.out.println("P2 - Problem 2");
System.out.println("P3 - Problem 3");
System.out.println("P4 - Problem 4");
System.out.println("P5 - Problem 5");
System.out.println("Q - Quit");
System.out.print("Choice: ");
choice = in.nextLine();
switch (choice) {
case "P1":
System.out.println("Problem 1");
break;
case "P2":
System.out.println("Problem 2");
break;
case "P3":
System.out.println("Problem 3");
break;
case "P4":
System.out.println("Problem 4");
break;
case "P5":
System.out.println("Problem 5");
break;
// quit and default cases
case "Q":
System.out.println("Quit");
done = true;
break;
default:
System.out.println("Invalid Choice");
break;
}
} while (!done);
// close the Scanner (don't delete!)
in.close();
}
// problem1 method
// problem2 method
// problem3 method
}
Last updated