One question on the Quiz asks, which section of Java in A Nutshell is called "Subclasses and Inheritance"? You should look this up on Safari Tech Books Online, as described in the Syllabus, before taking the quiz. The purpose for this question is to make sure everyone knows how to find the books there. Note that Logan Library's license for Safari only allows a few students at a time to access its books, and only one or two students at a time to access a specific book. To avoid long waits for other students, please log out of Safari as soon as you are done (by clicking the link near the top right of the page).
Create a simple Java class called HW1 in file HW1.java
,
that implements the following two static methods. Note that each method must
return a value.
Neither method should print anything. To test these methods, you should write your own
main()
method that calls the
prescribed methods with various arguments and prints the results so you can check the answers. When I test your program after you turn it in,
my test code will not use your main()
function,
but it will call the other two functions, expecting exactly the signatures that I give you here.
public static int maxOfThree (int a, int b, int c)
? :
) helpful for
this one (it can also be done with if)public static int monthsToReach(double target, double monthlyDeposit, double annualInterestRate)
A savings account starts with a zero balance. On the first day of each month, interest is calculated on the current balance and added to the account, based on 1/12 of the annual interest rate. Then monthlyDeposit is added to the account. This continues each month until the balance reaches or goes beyond target. This method returns the number of the months it takes for the balance to equal or exceed the value of target.
For example, the call monthsToReach (30000, 500, 0.05)
represents a monthly
deposit of $500 and an annual interest rate of 5%, asking how long it will
take to accumulate $30,000.00. The method returns 54 in this case
(recall that it does not print anything).
Estimated time: 30 minutes.
HW1.java
file to the AFS folder /class/csse/csse220/200820/turnin/yourusername/Homework1 .
Of course you should substitute your actual username where I wrote "yourusername".
If you use FTP or some other approach to turn it in, you might
need to begin the path to the folder with /afs/rose-hulman.edu/class/csse.