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

HWJ4 - Conditionals (if/else) exercises:

Start with the file below and use it to create the 5 methods described. (note example of indexof below).

For index of look at the example below:

 

/*
 * This is HWJ4 - Practice with conditions (If / Else statements)
 * @author Jeff Borland
 * @version 5
 */

public class HWJ4_Conditionals
{

    //This will classify grade as  a,b,c,d,f
    public static void classifyAvg(int grade)
    {
        
    }
    //This method will take in a gender [male, or female] and an age as a parameter and say how many years you have left to live. A women can expect to live 82 yrs and a man 79. So if they put in man,33 ; it would say 46 years left till you die.

    public static void lifeLeft(String gender, int age){
    }
    //Spit out high school, middle school, elementary
    public static void findSchoolTerm (int grade)
    {

    }

    //Spit out cost of item, items accepted: hat - $4.00, shirt - $5, pin - $1
    // otherwise unknown
    public static void findCost (String item)
    {

    }    

    //Find persons letter grade (<70 F ,70-77 D, 78-84 C, 85-92 B, 93+ A)
    public static void findLetterGrade (int numberGrade)
    {
    }

    //IQ range;  if  they are below 82 say they are dull or worse
    // if they are between 82-116 -say average
    //117-152 above average
    //153+ Genuis
    public static void IQrater(int iq)
    {

    }

    //You are writting the payroll program for Subway.  You will say the payRate for each worker.
    //If the job is worker, pay rate is $7 an hour.  If the job is manager, payrate is $11 an hour.
    //If the job is boss, pay rate is $23 an hour. If the job is anything else it will say I dont understand that job
    //To check strings if (job.equals("manager"))
    public static void payRate (String job)
    {
    }

    //The method below will ask the user for three numbers, then it will say those numbers were in order
    // from lowest to greatest, or it will say they werent.
    public static void isInOrder(int a, int b, int c)
    {
    }

    //The method will say if there were any doubles or triples
    //[doubles are two of the same numbers][triples are three of the same]
    // so if they put in 3 5 and 3 it would say doubles
    public static void anyDoubles(int x, int y, int z)
    {
    }   

    //This will ask the user how tall they are in inches and then
    // if they are 6 ft or taller, say they are tall,
    // if they are between 5'9 - 6' they are normal
    // if they are shorter than 5' 9 than they are short  
    public static void isTall(int inches)
    {     
    }

    //ADVANCED STUDENTS OR EXTRA CREDIT BELOW

    //Given three ints, a b c, print true if one of them is 10 or more less than one of the others.
    //lessBy10(1, 7, 11) ? true
    //lessBy10(1, 7, 10) ? false
    //lessBy10(11, 1, 7) ? true
    public static void lessBy10(int a, int b, int c) {

    }

    //This method will take in an email address and if it looks valid it will say valid, otherwise it will say invalid valid emails have @ and a . 
    //See how strong you can make your checker (see if you can add extra checks)
    public static void checkEmail (String address) {
    }

    /*The number 6 is a truly great number. Given two int values, a and b, return true if either one is 6. Or if their sum or difference is 6. Note: the function Math.abs(num) computes the absolute
    value of a number. 
    love6(6, 4) ? true
    love6(4, 5) ? false
    love6(1, 5) ? true  */
    public static void love6(int a, int b) {

    }

    /*Using the scanner class; In this method you will have a magic number already set between 1 and 5 (see below). The person will have to guess the number. If they guess too high it will say too high, and if they guess too low it will say too low. If they guess it, they will say good guess.*/
    public static void guessingGame()
    {
         int randomNum=(int)(Math.random()*5+1);
    }

    public static void main (String[] args)
    {
        HWJ4_Conditionals hw=new HWJ4_Conditionals();
        hw.classifyAvg(92);
    }

}      
        
 

 

Create guessing game from bottom of if-then page make it repeat, so it will keep asking until they guess the number.

 

 

 

 

 

 

 

EXAMPLE OF INDEXOF BELOW

public static void testIndexOf()
    {
        String phrase="Deering HS";
        System.out.println(phrase.indexOf("e"));  //it would spit out 1
        System.out.println(phrase.indexOf("ring"));  //it would spit out 3
        System.out.println(phrase.indexOf("z"));  //it would spit out -1 b/c it is not in the word

		//if we wanted to see if the char scannedChar is in HIDDENWORD we could write
        if (HIDDENWORD.indexOf(scannedChar)==-1)
        	// IT IS NOT IN THE WORD
        else 
        	//it is in the word
        
        // for the gender and age we might say
        if (gender.equals("female")&& age>=20 && age<=39)
        	

    }