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

HWJ5 - More string 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 HWJ5 - Practice with conditions (If / Else statements)
 * @author Jeff Borland
 * @date 10-18-11
 */
 
import java.util.Scanner;
public class HWJ5
{
    //IQ range; using scanner as for their iq (generally between 50-200) 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 void IQrater()
    {
     	Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class        
    }

    //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
    public void payRate (String job)
    {
    }
     
    //Will take in a character and check to see if its a vowel, it will then say yes, its a vowel or no it is not.
    public void isVowel(char c)
    {
    }
    
    //The method below will ask the user for three numbers (using scanner), then it will say those numbers were in order
    // from lowest to greatest, or it will say they werent.
    public void isInOrder()
    {
    }

    //The method below will ask the user for three numbers (using scanner), then it 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 void anyDoubles()
    {
    }    
    
    //This will ask the user how tall they are (using scanner) (ask for ft and inches seperately) 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 void isTall()
    {
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class        
    }
   

     
    //Below is a table for average weight for ages and gender
    //age   male    female
    //20-39 185     145
    //40-59 190     148
    // 60+  165     135
    //Create a method that will take in (as parameters) the gender,age, weight and spit out
    //You are 22 pounds over the average.
    public void findAverageWeight(String gender, int age, int weight)
    {
    }
    
    
     
}       
        
 
Students finished early - must do 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 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 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 void love6(int a, int b) {
  
}


 

 

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 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)
        	

    }