email me at borlaj@portlandschools.org

Loading
notes previous (14/<14) submit the dump links  
 

HWJ3 - Using the scanner class: (This counts as 9 points)

Start with the code below and use it to create the 9 methods described.

 
/*
 * @author Jeff Borland   -> Replace w/ your name
 * @version 4
 */

import java.util.Scanner;
public class HWJ3_Scanner
{
    public static void testOfScannerClass()
    {
        //You need to initialize the scanner in order to use it
        Scanner scan=new Scanner(System.in);  
        //test of reading Strings
        System.out.println("Type in a string");
        String theString=scan.nextLine();        
        System.out.println("In case you forgot, you just typed " + theString);

        //test of reading int
        System.out.println("Type in an integer");
        int theInt=scan.nextInt();        
        System.out.println("In case you forgot, you just typed " + theInt);

        //test of reading double
        System.out.println("Type in a decimal");
        double theDouble=scan.nextDouble();        
        System.out.println("In case you forgot, you just typed " + theDouble);                       
    }     

    //Create a method that will ask your name and age and then
    // find how many years older mr borland is then you (im 39)
    //it will spit out Mr Borland is 22 yrs older than Owen
    public static void ageDiff()
    {
        Scanner scan=new Scanner(System.in);  
        //YOUR CODE GOES HERE
    } 

    //Create a method that will convert meters to centimeters and also inches.
    //It will ask for meters and then print out the number of cms and inches
    public static void convertMeters()
    {
        Scanner scan=new Scanner(System.in);  
        //YOUR CODE GOES HERE
    }

    //Ask for a weight in pounds convert to kilograms.  
    //it would say 180 pounds is 81.6466266 kilograms (convert by pounds*.453592
    public static void convertToKilograms()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here        
    } 

    //Ask the user for their dogs name and age.  You will then convert the dogs age in to years by multiplying by 7 and then saying:
    //Your dog Lassie is 42 yrs old.
    public static void findDogsAge()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here

    }   

    //Ask the user for their first and last name and then they will say:
    //Jeff Borland, there are 4 letters in your first name and 7 in your last.
    public static void findLettersInName()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here

    } 

    //Ask the user for 2 numbers and spit out the average
    public static void findAvg()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here

    } 

    //Ask the user for their height in feet and inches (read both things seperately).
    // Then spit out You are 75 inches tall.
    public static void findHeight()
    {
        //You will need the following line in all methods in order to initialize the scanner
        Scanner scan=new Scanner(System.in);  
    }

    //ask for tax rate and price of item and it will display total price
    // ie if item is 50 and tax is 5 (as in 5%), the total price is 52.50.
    public static void totalPrice ()
    {
        //You will need the following line in all methods in order to initialize the scanner
        Scanner scan=new Scanner(System.in);  
    }

    /**************************************************************************/
    //Advanced Students - do __ of below (look at notes on if statements, loops)
    //Ask the user for a number of miles for a taxi ride and then ask for
    // cost per mile and pickup cost. 
    //Then spit out total charge (which is #of miles *cost per mile + pickup cost
    public static void findTaxiCost()
    {
    }

    //This will ask the user for the speed he was going and then spit out
    //the cost of a ticket (from 0-65 - $0, 66-74 - $85, 75-100 - $200 101+ - $1000
    public static void findTicket()
    {
    }

    //This will find out the number of people who attended each block of the day
    //Ask the user 4 times (for each block) how many people attended
    //Then spit out the total
    //you must use a for loop
    public static void find4BlockTotal()
    {
    }

    //This will ask the user how many games they played, then it will find the winning percent 
    //So the user might say 3, and the program will ask them 3 times if they won
    //So they might say y,n,n and then it will spit out you won 33.3% of the time
    public static void findWinningPrct()
    {
    }

    //create a method that will keep asking for a grade until the user hits -1.  They will then
    //find the average of those grades
    // you will need to use loops
    public static void findAverage()
    {
    }	

}    

 
Advanced Students -notes on if statements, loops)