Practice: returns, Scanner

posted by: Ms. Martin 16 November 2010 No Comment

These problems are for you — I will not be checking them off or asking you to turn them in! Of course, I’m giving you this freedom because I believe that your project and test scores will reflect the amount of effort you put into them…

  1. Write a method placeCircles that has Scanner and Graphics parameters.  Your method should prompt the user for a number of circles to draw then ask for information about each circle:
  2. 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.

  3. Write a method printPowersOfN that accepts a base and an exponent as arguments and prints each power of the base from base^0 (1) up to that maximum power, inclusive.  For example, consider the following calls:
    printPowersOfN(4, 3);
    printPowersOfN(5, 6);
    printPowersOfN(-2, 8);

    These calls should produce the following output:

    1 4 16 64
    1 5 25 125 625 3125 15625
    1 -2 4 -8 16 -32 64 -128 256
  4. Write a program to produce beautiful square spirals! Your program should prompt the user for a window size and the distance between each arm of the spiral. See a sample run of the program:
  5. 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.
  6. 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
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
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>