6A
Write a class LoopDeDo
. It has several methods that use loops. These problems aren't especially useful, but they will let you practice writing loops.
public String countUp(int n)
gets a String containing the numbers from 1 to n separated by a space and then the word Go! all on one line. For example, if n is 3, the return value would bepublic String countDown(int n)
gets a String containing the numbers from n to 1 separated by an explanation mark (!) and a space and then the words Blast Off! all on one line. For example, if n is 3, the return string would bepublic String noAlphaOrZed(String words)
gets a version of the string with all the a's and z's removed, both upper and lower case.Provide Javadoc
You will learn later that these methods should be declared static. Don't worry about it now, just put it the back of your mind for a few weeks from now.
For the draft, implement the countUp
method
6B
A life insurance company needs an application to automate the calculation of yearly life insurance premiums for an individual person. Complete the LifeInsurancePolicy
class. The LifeInsurancePolicy
class has a constructor that takes a Person object as a parameter (constructor provided). You are also given the Person
class.
You must use nested if statements
The cost of life insurance is based on age and gender and whether the person lives in a high crime area. Here is a table of premiums based on age and gender of the person. If the person lives in a high crime area, there is a surcharge of 10%. The company will not insure a person 80 years old or older
< 21 | 21 to 60 (exclusive) | 60 to 80 (exclusive) | |
---|---|---|---|
Male | $20 per year of life | $50 per year of life | $110 per year of life |
Female | $18.50 per year of life | $45 per year of life | $100 per year of life |
For example: The premium for a 30 year old male living in a low crime area would be 30 X 50 and in a high crime area it would be 30 X 50 + (30 X 50) *.1
Implement these methods
public int policyHolderAge()
gets the age of the insured Person (from the Person object)public String policyHolderGender()
gets the gender of the insured Person (from the Person object) public void incrementAge()
the person had a birthday. Increment their age.public double premium()
gets the yearly premium for this Person
or -1 if the age is greater than or equal to 80. If the gender is not "m", assume it is "f" Only have the code to add the surcharge (if needed) in one placeProvide Javadoc.
For the draft, implement policyHolderAge, policyHoldeGender, and incrementAge. Provide the Javadoc.
You will need to look at the documentation of the Person class to see how to use the Person class' methods. You can either look at the Javadoc in the source code for the Person class or you can toggle the drop down menu on the right from Source Code to Documentation to get documentation in the familiar Java API format.
Do not have instance variables of age and gender in the LifeInsurancePolicy
class.
6C
Complete the TenCircles class to draw ten circles that have radius of 10, 20, ..., 100. They touch the line x = 0 at the left and the line y = 200 at the bottom. (are tangent to the line) Draw the smallest circle first. (updated Mar 12)
Here is an image.
You must use a loop in your solution for the final. You will receive no credit for a solution that draws ten separate circles even if it passes Codecheck.
For the draft: just draw the circle with radius 10. No need to use a loop
(updated 3/14/2017)