Lecture 11, CS 302-7 and 8, February 15
i. Due Oct 24
1. Partner registration – Feb 17
ii. Piazza
iii. Backups – by submitting
i. While
ii. For
i. Doesn’t check condition before first iteration
ii. Post-test instead of pre-test
do
{
}
while(<condition>);
i. When we know that we have to do something at least once
ii. You then want to keep going while you haven’t met some condition
iii. Balance.java
i. Import scanner
ii. Declare/initialize scanner object
iii. Prompt user for input
iv. Store input
i. Before we store, we have to validate that input is ‘good’. What could go wrong?
1. Type
a. Eg If we want an int, but they put in a string
2. Range
a. Eg if we want 1-4, but they put in 5
i. We can use loops for this behavior – stick our input code in a loop
i. Real life example – period at the end of a sentence
ii. Computer example – in a menu, quit
i. while(value!=some number)
ii. while(!done)
iii. while(in.hasNextDouble()/in.hasNextInt())