Conditionals and return practice

posted by: Ms. Martin 26 October 2010 No Comment

Lovely mandatory practice

  1. Modify your circles program 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.

  2. Write a method that accepts a real number for a programmer’s hourly wage and an integer for the number of hours the programmer worked this week, and returns how much money to pay the programmer. For example, the call pay(50.0, 6) should return 300.

    The programmer should receive “overtime” pay of 1 ½ normal wage for any hours above 8. For example, the call pay(35.0, 11) should return 35 * 8 + (35 * 1.5 * 3 or 437.5.
  3. Write a method that accepts a real number for a programmer’s hourly wage and returns a yearly salary assuming 48 weeks of work in a year and 8 hours of work in a day.  Round the result to the nearest dollar. Make sure to use your previous method!  For example, the call salary(35.0) should return 67200.
  4. Put it all together!  Your program should ask for two people’s hourly wage and compare the taxes they will be paying. Your output should be as follows (user input underlined):
    Person 1's hourly wage: 35
    You will make $67200 this year.
    And you will pay $13440 in taxes.
    
    Person 2's hourly wage: 20
    You will make $38400 this year.
    And you will pay $0 in taxes.
    Person 1 is paying more taxes

    People with a yearly salary under $20,000 do not pay taxes. Those making over $100,000 pay 30% in taxes. Those making between the two pay 20%.

Pick some of these

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. Create an account on Practice-It and try to beat the guy from Green River Community College who has solved 882 problems.
1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 2.67 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>