09-14 Class Notes CS 107

09-14 Class Notes CS 107 - MenuDisplay instance = new...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
How far along are you on your program? A - What program? B - just a bit C - at least half D - almost done E - Done! Program #2 is due tomorrow evening at 11:59 pm. Note that sample code has been updated online. - Use the debugger to help you figure out your program, as I illustrated last time. - Next week we have lab as usual. The week after (week 6) you will have the in-lab midterm - Announcements: Questions? if , while Last Time: Loop example for primitive "graphics": Animate.java break and continue example, while loop vs. for loop Today: Display menu & keep looping to get input until it is valid using continue a. Break out of a loop when 'x' to exit is chosen b. Example small program ( MenuDisplay.java ) using break and continue 1. public class MenuDisplay // The variables declared here are shared throughout the program Scanner keyboard = new Scanner( System.in); // Have main chain off to another method to avoid static errors public static void main(String[] args)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MenuDisplay instance = new MenuDisplay(); instance.mainLoop(); { { 09-14 Class Notes CS 107 Wednesday, September 14, 2011 2:23 PM CS 107 Fall 2011 Page 1 1. Loops: while loop compared to for loop. Consider the program that counts from 0 to 4: int counter = 0; System.out.println( counter); counter++; while( counter < 5) { } System.out.println( counter); for( int counter = 0; counter <5; counter++) { } 1. "Loop the loop": putting a loop inside a loop Consider the MultiplicationTable.java program used to print out a 2-d multiplication table: MenuDisplay instance = new MenuDisplay(); instance.mainLoop(); { } void mainLoop() String userInput = ""; // display menu and get user input. Keep looping until valid input given. // Next add a "hidden" menu option that breaks out of the loop. System.out.println("Done."); { }//end main() CS 107 Fall 2011 Page 2...
View Full Document

Page1 / 2

09-14 Class Notes CS 107 - MenuDisplay instance = new...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online