/* Lesley Hogan * July 24th 2003 * ForLab.java * For loops... -.-;; * Homework from: * http://teachertech.rice.edu/Participants/marilynt/Lessons/Exeter/Programming/ForLoopLab.html */ package net.bunnie.dos; import java.text.DecimalFormat; import net.bunnie.*; public class ForLab { public static void main (String[] args) { // squares variables int startInt; int endInt; int transInt; // dive variables String diveName; double score; double high = 0; double low = 10; double total = 0; double average; // conc variables String spaces = ""; // general variables KeyboardReader r = new KeyboardReader(); DecimalFormat dec = new DecimalFormat("#.#"); boolean loop = false; boolean fullLoop = true; int switchInt = 0; // array of options String[] optionList = new String[5]; String optionString = ""; int options = optionList.length - 1; optionList[0] = "0: View this menu"; optionList[1] = "1: Squares and Cubes"; optionList[2] = "2: Dive Scores"; optionList[3] = "3: Concatenate numbers"; optionList[options] = "" + options + ": Press " + options + " to escape"; int b = 0; do { optionString += optionList[b]; optionString += "\n"; b++; } while (b < optionList.length); // welcome message System.out.print("-----------------------------------\n"); System.out.print(" F O R L A B \n"); System.out.print(" L . H O G A N \n"); System.out.print(" _______ \n"); System.out.print(" | | | | \n"); System.out.print(" | | | | \n"); System.out.print(" |____| | | \n"); System.out.print(" | | | | \n"); System.out.print(" | | | \n"); System.out.print(" | | ___|___ + \n\n"); System.out.print("-----------------------------------\n\n\n"); // print out list of options and let user choose // what they want to do in the program do { switch(switchInt) { case 0: // show menu System.out.print("What would you like to do today?\n"); System.out.print(optionString + "\n"); switchInt = r.readInt(); break; case 1: // squares and cubes System.out.print("Enter starting value: "); startInt = r.readInt(); System.out.print("Enter ending value: "); endInt = r.readInt(); if (startInt > endInt) { transInt = startInt; startInt = endInt; endInt = transInt; } System.out.print("\n\nx\tx^2\tx^3\n"); for (int i = startInt; i <= endInt; i++) { System.out.print(i + "\t" + (i * i) + "\t" + (i * i * i) + "\n"); } System.out.println(); switchInt = 0; break; case 2: System.out.print("Diver's name: "); diveName = r.readLine(); for (int i = i = 1; i <= 7; i++) { System.out.print("Enter score number " + i + ": "); score = r.readDouble(); if (score > high) { high = score; } if (score < low) { low = score; } total += score; } total = total - high - low; average = total / 5; System.out.print("\nDiver's name: " + diveName + "\nScore: " + dec.format(average) + "\n\n"); switchInt = 0; break; case 3: System.out.println(); for (int i = 1; i < 11; i++) { spaces += " "; System.out.println(spaces + i); } System.out.println(); switchInt = 0; break; default: // exit program fullLoop = false; break; } } while (fullLoop == true); } }