L03

Due by the end of Tuesday, September 26

Starter Files:


SUBMIT / CHECK

Today's Activities

This week we're practicing using if, if-else, and if-else-if controls. We'll be working with numbers and Strings. Things to keep in mind are:

On with the activities!

Activity 1: Downloading a Program
Create a new project named L03, with a main program class l03.MoviePrices. Download MoviePrices.java (linked above) into your CSCI1226/L03/src/l03/ folder. Tell your computer that you would like to replace the one that's there.

That program is the sample code version of one we did in class. It reads the user's age and looks up the price they need to pay based on that age. Run the program a few times, trying different ages.

Activity 2: Checking the User's Input
Try running the program with some "stupid" values for the age: negative numbers, and numbers way over 100. Notice that the program doesn't bat an eye (not that it has eyes to bat).

It's generally a good idea to check any number the user enters to make sure that it makes sense. The first change we'd like you to make to the program is to add code to check that the user's age makes sense. If their age is under zero, the program should say "That can't be right!" and ask them to try again:

How old are you? -5 That can't be right! How old are you, really?
The program should read in the age again (using the same variable), then carry on directly into the code for looking up the price:
How old are you, really? 7 Children's price. That'll be $2.99, please.
Activity 3: More Checking
Next, add code to check whether the first age they entered is 100 or more. The program should express surprise, and ask them if they really are that old:
How old are you? 115 Wow, that's surprising! Are you really 115?
The program should read a word as their answer. If their answer starts with "no" (or "NO" or "No" or "nO") then the program should ask them for their actual age:
Are you really 115? No. So what's your real age, then? 15 Youth's price. That'll be $7.99, please.
If their answer is anything else, the program should proceed using the original number they entered:
Are you really 115? Sure am! Senior's price. That'll be $6.99, please.
Activity 4: Yet More Checking the User's Input
In two cases above, we asked the user to re-enter their age, but then we just accepted their second answer without checking it. The user could have re-entered a "stupid" number:
How old are you, really? -700 Children's price. That'll be $2.99, please.
We'd like to add one last check for their age. Just before we get to the part that looks up their price, add a test to see whether their age is less than 0 or more than 120. If it is, then the program should skip announcing the price and instead print the message "I don't believe that you're (whatever age). Please go away."
How old are you, really? -700 I don't believe that you're -700. Please go away.
Of course, if their age is in the valid range, then the normal lookup should proceed:
Are you really 115? Sure am! Senior's price. That'll be $6.99, please.

Once all the activities are completed you can submit your Java program by one of the SUBMIT links above/below.

Make sure you pass in the correct file and that it has the correct name:

In particular, make sure you submit your modified copy of the .java file. You should find it in your L03/src/l03 folder.

The pass in page will print a little "receipt" for your records. Make sure you read it carefully. Make sure it doesn't have any red text on it at all. Make sure the submitted size is larger than the original size (you should have added quite a bit of code).

Submit this/these files:

You will be graded on the following:

  1. You are identified by both name and A-number as an author of the program,
  2. ... in the same way that Mark Young was (and STILL IS)
  3. Any age less than zero gets a "not right" message ...
  4. ... and gets a new age read in
  5. Any age 100 or over gets a "surprising" message ...
  6. ... and a request for confirmation
  7. ... ... and a new age is read in if (and only if) the user admits the error
  8. Any (possibly revised) age under zero gets the "push off" message
  9. Any (possibly revised) age over 119 or 120 gets the "push off" message
  10. The "push off" message never appears together with an age or price message
  11. Initial ages under zero are not tested to see if they are over 100 (proper use of else if)
  12. Single condition provided for testing the (possibly revised) age (proper use of && / ||)
  13. Code for printing age and price information still in a single block
  14. Code is properly indented, uses white space appropriately, and has no overly-long lines

SUBMIT   /   CHECK