email me at borlaj@portlandschools.org

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

HWJ4 - Using the scanner class: (This counts as 2 hws)

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

 
 /*
 * @author Jeff Borland   -> Replace w/ your name
 * @date 10-26-10
 */

import java.util.Scanner;
public class HWJ4
{

    //Ask for a weight in pounds convert to kilograms.  
    //it would say 180 pounds is 81.6466266 kilograms
    public void convertToKilograms()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    
        //add your code here        
    } 

    //Ask for a number of feet and convert to meters.
    //So they say  5260 feet
    //it would say 
    //5260 feet is 1603.248 meters
    public void convertToMeters()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    
        //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 void findDogsAge()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    
        //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 void findLettersInName()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    
        //add your code here
        
    } 

    //Ask the user for 2 numbers and spit out the average
    public void findAvg()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    
        //add your code here
        
    } 
    
    //Ask the user for a name of a player and how many hits and how many at bats
    //So the user will type in Barry Bonds, 150, 420 and then display Barry Bonds has an average of .3571...
    public void findBattingAVG()
    {
        //You will need the following line in all methods in order to initialize the scanner
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    
        //add your code here
        
    }  
    
    //Ask the user for their name and their height in feet and inches (read all 3 things seperately).
    // Then spit out Jeff Borland you are 75 inches which is ___ meters.
    public void findHeight()
    {
        //You will need the following line in all methods in order to initialize the scanner
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    }
    
    //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 void totalPrice ()
    {
        //You will need the following line in all methods in order to initialize the scanner
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    }
    
    //At a famous hamburger restaurant they have a very simple menu.  A burger, drink and fries.  One size of each.  Thats all
    // they do and they do it well.  A burger costs $2.55.  A drink costs $1.75.  Fries cost $1.95.  
    // Ask the user for how many of each they want, then print the subtotal.  Then calculate the tax (Maine food tax is 7%)
    // Print out the tax and then the total of the order.
    // So if they ordered 3 burgers, 3 drinks and 2 fries it would say
    // Your subtotal is $16.80.  
    // The tax is $1.176
    // Your total is $17.976
    // for simplicity, dont worry if there are more decimals than exist in money.
    public void findCostDinner()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  //The Scanner constructor requires the use of the io class
    
        //add your code here        
    } 
    
}    
 
Students finished early - must do below (note 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 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 void findTicket()
    {
    }
    
    //This will find out the number of people who dressed up for spirit week
    //Ask the user 5 times (for each day) how many people dressed up [like how many people dressed up on day1? etc]
    //Then spit out the total
    //you must use a for loop
    public void find5DayTotal()
    {
    }
    
    //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 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 void findAverage()
    {
    }