Math and Scanner practice

posted by: Ms. Martin 19 October 2010 No Comment

Get checked off for at least three of these!

  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. If you ever find yourself buying a house, you’ll want to know what your monthly payment for the loan is going to be. Write a method that asks the user for information about a loan and prints the monthly payment.The formula for computing monthly mortgage payments involves the loan amount, the total number of months involved (a value we call n) and the monthly interest rate (a value we call c). The payment formula is given by the following equation:An example run of your program might produce the following output (user input is underlined):
    This program computes monthly loan payments.
    Loan amount? 275000
    Number of years? 30
    Interest rate? 6.75
    Your payment is $1783

    Note that the numbers being read as input don’t match the way they should be used in the formula. The term of the loan is read as years instead of months. The interest rate percentage is being read in as a yearly rate instead of a monthly rate and as a whole number rather than a true percentage, so the value 6.75 should actually become 0.005625 by dividing it by 12 and by 100. You will have to make these conversions as part of your program.

    Make sure the final printed results is in whole dollars, without any decimals!

  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:
1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 2.43 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>