CSE 110 Assignment Java programming
//import Scanner class import java.util.*; public class Assignment5 { public static void main (String[] args) { Scanner console = new Scanner (System.in); String choice; char command; // call the method to print the menu printMenu();//print the menu, a static method //instantiate an object of type Geek Geek myGeek = new Geek("Eisenstein"); do { // ask a user to choose a command System.out.println("\nPlease enter a command or type ?"); choice = console.next().toLowerCase(); command = choice.charAt(0); switch (command) { case 'a'://print the name System.out.println(myGeek.getName()); break; case 'b': //print number of questions asked so far System.out.println(myGeek.getNumberOfQuestions()); break; case 'c': //find if the sum of numbers is even or odd System.out.print("Enter two numbers: "); int num1 = console.nextInt(); int num2 = console.nextInt(); if (myGeek.isEven(num1, num2)) System.out.println("Sum is even"); else System.out.println("Sum is not even"); break; case 'd'://find if all are the same numbers System.out.print("Enter 3 integers: "); num1 = console.nextInt(); num2 = console.nextInt(); int num3 = console.nextInt(); if (myGeek.allTheSame(num1, num2, num3)) System.out.println("All the same!"); else System.out.println("All are NOT the same"); break; case 'e': //sum the numbers between two numbers entered by user System.out.print("Enter the first number: "); num1 = console.nextInt(); System.out.print("Enter the second number: "); num2 = console.nextInt(); int total = myGeek.sum(num1, num2); System.out.println("The sum between "+ num1 + " and " +num2 + " is " + total); break; case 'f': //repeat the input string System.out.print("Enter a string: "); String text = console.next(); System.out.print("How many times to repeat: "); int count = console.nextInt(); System.out.println(myGeek.repeat(text, count)); break; case 'g': //number of digits System.out.print("Enter a number: "); num1 = console.nextInt(); System.out.println("The number " + num1 + " has " + myGeek.digits(num1)+ " digits"); break; case 'h'://find out the middle in the input string System.out.print("Enter a string: "); String input = console.next(); System.out.println("The middle of string \"" + input + "\" is " + myGeek.middle(input)); break; case '?'://print the menu printMenu(); break; case 'q'://quit break; default://invalid choice System.out.println("Invalid input"); } } while (command != 'q'); } //end of the main method public static void printMenu() { System.out.print("\nCommand Options\n" + "-----------------------------------\n" + "a: Get name\n" + "b: Num of questions asked\n" + "c: Is it Even\n" + "d: All the same\n" + "e: Sum between two integers\n" + "f: Repeat\n" + "g: Number of Digits\n" + "h: Middle of String\n" + "?: Display\n" + "q: Quit\n\n"); } // end of the printMenu method