/* solution to week 4 lab - lots of loops! */ import java.util.Scanner; import java.io.*; public class week04 { public static void main(String[] args)throws IOException { Scanner kb = new Scanner(System.in); String nextLine = null; Scanner readLine; int transaction = -1; char first, last; // for letters operation int rows, cols; // for rectangle operation char ch; // for rectangle operation int value; // for graph operation do { System.out.println("\n"); System.out.println("Please choose an operation: "); System.out.println("0) quit"); System.out.println("1) letters"); System.out.println("2) rectangle"); System.out.println("3) graph"); System.out.print("choice -> "); transaction = kb.nextInt(); System.out.println(); switch (transaction) { case 0: System.out.println("BYE!"); break; case 1: // System.out.println("print letters transaction"); System.out.print("enter two letters: "); first = kb.next().toUpperCase().charAt(0); last = kb.next().toUpperCase().charAt(0); if (first > last) // switch them { char temp = first; first = last; last = temp; } for (char c = first; c <= last; c++) System.out.print(c + " "); System.out.println(); break; // end letters case case 2: // System.out.println("rectangle transaction"); System.out.print("enter height, width & display character: "); rows = kb.nextInt(); cols = kb.nextInt(); ch = kb.next().charAt(0); for (int r=0; r < rows; r++) { for (int c=0; c < cols; c++) System.out.print(ch); System.out.println(); } break; // end rectangle case case 3: // System.out.println("bar graph transaction"); System.out.print("enter all the numbers to process on one line: "); kb.nextLine(); // skip end of line character after menu choice nextLine = kb.nextLine(); readLine = new Scanner(nextLine); while (readLine.hasNext()) { value = readLine.nextInt(); for (int i=0; i