'F' → Fullscreen
import java.util.Scanner;
public class Program{ public static void main(String[] args) { // ANSI Color Codes final String GREEN_TEXT = "\u001B[32m"; final String RED_TEXT = "\u001B[31m"; final String WHITE_TEXT = "\u001B[37m"; Scanner input = new Scanner(System.in);
System.out.println("--- Demo 1 - Multiplication Table ---");
System.out.print("Enter the size of the table: "); int size = input.nextInt();
// Column Headers for (int i = 0; i <= size; i++) { // Omit braces for single-line code blocks // Exclude zero at top left if (i == 0) System.out.print("\t"); else System.out.print(GREEN_TEXT + i + "\t"); }
System.out.println(); // Move to next row
for (int num1 = 1; num1 <= size; num1++) { // Left column System.out.print(GREEN_TEXT + num1 + "\t" + WHITE_TEXT);
// Body for each row for (int num2 = 1; num2 <= size; num2++) { System.out.print(num1 * num2 + "\t"); }
System.out.println(); // Move to next row }
input.nextLine(); // Consume newline System.out.print("Press enter to continue..."); input.nextLine();
// ----------------------------------------------------------------------------- }}import java.util.Scanner;
public class Program{ public static void main(String[] args) {44 collapsed lines
// ANSI Color Codes final String GREEN_TEXT = "\u001B[32m"; final String RED_TEXT = "\u001B[31m"; final String WHITE_TEXT = "\u001B[37m"; Scanner input = new Scanner(System.in);
System.out.println("--- Demo 1 - Multiplication Table ---");
System.out.print("Enter the size of the table: "); int size = input.nextInt();
// Column Headers for (int i = 0; i <= size; i++) { // Omit braces for single-line code blocks // Exclude zero at top left if (i == 0) System.out.print("\t"); else System.out.print(GREEN_TEXT + i + "\t"); }
System.out.println(); // Move to next row
for (int num1 = 1; num1 <= size; num1++) { // Left column System.out.print(GREEN_TEXT + num1 + "\t" + WHITE_TEXT);
// Body for each row for (int num2 = 1; num2 <= size; num2++) { System.out.print(num1 * num2 + "\t"); }
System.out.println(); // Move to next row }
input.nextLine(); // Consume newline System.out.print("Press enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
boolean playing = true; int keys = 0; String choice;
System.out.println("\n--- Demo 2 - Multi-Room Game Demo ---"); System.out.println(RED_TEXT + "Work-in-progress. Expect bugs!" + WHITE_TEXT);
while (playing) { System.out.println(GREEN_TEXT + "-Main Hallway-" + WHITE_TEXT); System.out.println("1) Kitchen"); System.out.println("2) Bathroom"); System.out.println("3) Bedroom"); System.out.println("4) Quit Demo"); System.out.print("-> "); choice = input.nextLine();
if (choice.equals("1")) { while (!choice.equals("2")) { System.out.println(GREEN_TEXT + "-Kitchen-" + WHITE_TEXT); System.out.println("1) Search cupboards"); System.out.println("2) Leave"); System.out.print("-> "); choice = input.nextLine();
if (choice.equals("1")) { System.out.println("Found a key in the cupboard!"); keys++; } else if (choice.equals("2")) { System.out.println("Exiting kitchen."); } else { System.out.println("Invalid input."); } } } else if (choice.equals("2")) { System.out.println(GREEN_TEXT + "-Bathroom-" + WHITE_TEXT); // Demo code omitted } else if (choice.equals("3")) { System.out.println(GREEN_TEXT + "-Bedroom-" + WHITE_TEXT); // Demo code omitted } else if (choice.equals("4")) { playing = false; } else{ System.out.println("Invalid choice."); } } }}Your program output should something similar to the sample output below.
--- Demo 1 - Multiplication Table ---Enter the size of the table: 5 1 2 3 4 51 1 2 3 4 52 2 4 6 8 103 3 6 9 12 154 4 8 12 16 205 5 10 15 20 25Press enter to continue...
--- Demo 2 - Multi-Room Game Demo ---Work-in-progress. Expect bugs!-Main Hallway-1) Kitchen2) Bathroom3) Bedroom4) Quit Demo-> 1-Kitchen-1) Search cupboards2) Leave-> 1Found a key in the cupboard!-Kitchen-1) Search cupboards2) Leave-> 2Exiting kitchen.-Main Hallway-1) Kitchen2) Bathroom3) Bedroom4) Quit Demo-> 4You may write your reflection answers as comments at the bottom of your code.
Submit your activity and reflection answers to the appropriate dropbox.