Returns & Conditionals Lab Worksheet

posted by: Mr. Bergquist 28 October 2012 No Comment

For your reference:
Returns & Conditionals (if/else) Presentation / Handout
Advanced If Returns & Cumulative Sum Presentation / Handout

Start with some great Practice It! exercises…
Self-Check 3.12: min : Write a Method that takes three integers as parameters and returns the smallest of the three values (you might be able to use if/else’s for this)
Self-Check 3.17: countQuarters : Add a Return to the Count Quarters method you wrote earlier
if/else Conditionals:
Exercise 4.12: printTriangleType : Print the type of a Triangle based on the lengths of its three sides
Exercise 4.3: season : Returns the season of a date
Cumulative Sum with Conditional & Scanner:
Exercise 4.8: smallestLargest : Print out the smallest & largest number of the value entered in.

Then in JGrasp…

  1. Modify your circles program (1. from Math and Scanner practice) to allow the user to color the circles. Give the user three choices:
    Pick a color: (1) red, (2) blue, (3) magenta.

    Draw a red circle when the user types 1, a blue circle when the user types 2 and a magenta circle when the user types 3. If the user types in an invalid number, print an angry message and draw a black circle.

Pick some of these if you have the time…

Try out: Exercise 4.9: evenSumMax: Prints out the Sum & Max of all Even values entered in.

In a separate class, do as many of these as you can! Alternately, play with what we have learned so far. Can you come up with a clever program to write?

  1. Write a graphics programs that prompts the user for the position and radius of two circles. If the two circles overlap, draw them filled in green. If they don’t, draw them filled in red.
  2. Write a method that counts a number’s factors and determines whether the number is prime. Use user input as follows:
    What is your favorite number? 24
    24 has 8 factors
    24 is not prime
    What is your favorite number? 31
    31 has 2 factors
    31 is prime
  3. Continue working in Practice-It - we will stick to looking at the local Garfield scoreboard.

(Big Thanks to Ms Martin for these excellent sample problems)

1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 3.57 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>