email me at borlaj@portlandschools.org
notes previous (09/07/06) submit the dump links  
 

Hints:

//To find square root of 16
Math.sqrt(16);
//To find square of 4
Math.pow(4,2)
//To go through a word getting each letter
for (int i=0;i<word.length();i++)
	System.out.println(word.charAt(i));

 

 

HWJ8_Methods - each worth 1 point Do 5 of 7

 

Assignment: (in each method when I say take in; that means as a parameter - DO NOT USE THE SCANNER class)

Create a method that will be as follows:

 

1. Create a method called convertToMiles that takes in kilometers as a double and returns the miles as a double

 

2.Create a method called numOfVowels that takes in a String and returns the number of vowels in the word. Here you will find methods for strings.

 

3. Create a method called makeWheelOfForturne that will take in a String and replace all the vowels with '_'. It will then return that new word.

 

4. Create a method called findMiddleLetter that will take in a String and return the letter in the middle. If the string has an even number of letters take the letter that comes first of the middle; ie pear would give e, and apple would give p.

 

5. Create a method called isLeapYear that will take in a year, and return true if it is a leap year, false otherwise. (The rules for leapYear are not as obvious as you thought. See here

 

6. Create a method called findDiagonal that will take in the width and height of television and it will return the diagonal. So 15,20, would return 25.

 

7. Create a method called ageInDays that will take in 4 arguments - your birth year, the number of your birth month (ie march is 3), number of day you were born. Find the number of days from then until today (November 4,2009)
* you wont have to worry about leap years and lets just make a month 30 days
* this method will return the number of days since you were born
* for extra credit take in to account the leap years and different amount of days in a month. Use the methods you wrote in 5 and 6.

 

Extra Credit:

1. Look at this page. Create a method getHour() that will return the current hour in military time (ie 2pm would return 14) as an int.

2.Look at this page. Create a method getMin() that will return the current minute as an int.
3. Create a method ageInSeconds that will 4 arguments - your birth year, the number of your birth month (ie march is 3), number of day you were born. Find the number of seconds until now: Use 10:00 today if you want.