Results 1 to 3 of 3

Thread: Problem with Scanner util. Please help!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Problem with Scanner util. Please help!

    Anyone have any ideas?

    Given Info:
    Conway population is 55,000
    There is a toilet for every 3 people in the population
    Existing toilets use 15 liters of water
    New toilets will use 2 liters of water
    Each toilet is flushed 14 times per day
    $350 per toilet to replace all toilets in city
    costs $0.01 per liter of water

    Find:
    Cost to operate old vs new toilet per day?
    Cost to replace all toilets in city?
    How long will it take to recover replacement cost with water saved from using new toilets?

    Here's my code:

    Code:
    //***********************************************************************************************
    //Toilet.java			Author: Jeremy S. Gates                                         *
    //                                                                                              *
    //Calculates the cost of replacing all toilets in Conway, the operation cost of old toilets,    *
    //the operation cost of new toilets, & the time required to recover the cost of replacing the   *
    //old toilets with new ones.                                                                    *
    //***********************************************************************************************
    
    
    import java.text.DecimalFormat;  //make DecimalFormat available
    import java.util.Scanner;        //make scanner available
    
    public class Toilet
    
    {                               //start class
    
    public static void main (String args[])  //main method
    
    {                               //start method
    
    String userin;
    int pop;
    double repcost, oldopcost, newopcost, recovertime;
    
    DecimalFormat twoDigits = new DecimalFormat("0.00");
    
    Scanner scan = Scanner.create(System.in);
    
    System.out.println ("Enter the population:");  //ask for input
    
    userin = scan.nextLine();               //read the input
    
    pop = Integer.parseInt(userin);        //convert the input to an integer
    
    repcost = (pop/3) * 350;           //calculates the replacement cost
    
    oldopcost = ((15*.01) * 14) * (pop/3);  //calculates the operating cost of the old toilets
    
    newopcost = ((2*.01) * 14) * (pop/3);    //calculates the operating cost of the new toilets
    
    recovertime = repcost/(oldopcost - newopcost)
    
    
    System.out.println ("The replacement cost = " +twodigits.format(repcost));
    
    System.out.println ("The old toilet operation cost per day = $" +twodigits.format(oldopcos));
    
    System.out.println ("The new toilet operation cost per day = $" +twodigits.format(newopcost));
    
    System.out.println ("The recovery time in days = " +twodigits.format(recovertime));
    
    
    System.exit(0);
    
    }                 //end of method
    }                 //end of class
    I get errors on the following lines when I try to compile. I'm using jdk1.5.0
    Code:
    Scanner scan = Scanner.create(System.in);
    This gives the error on the "." between Scanner and create. It says I gave a value and a class is expected.

    Also the following code gives an error on the "-" sign:
    Code:
    recovertime = repcost/(oldopcost - newopcost)
    Any help is extremely appreciated. This is my last college semester and the instructor for this class is so bad that this is our FIRST assignment and there is about 5 weeks of class left! I hope to learn some Java on my own using the book and forums.

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Problem with Scanner util. Please help!

    Originally posted by hipopony66

    I get errors on the following lines when I try to compile. I'm using jdk1.5.0
    Code:
    Scanner scan = Scanner.create(System.in);
    This gives the error on the "." between Scanner and create. It says I gave a value and a class is expected.

    Also the following code gives an error on the "-" sign:
    Code:
    recovertime = repcost/(oldopcost - newopcost)
    [/B]
    On the first error I think you need to do something like this:

    Code:
    Scanner stdin = new Scanner(System.in);
    On the second error it looks as if you are missing semicolon[;].

    I don't know if this will help or not. I can't test it because I haven't downloaded sdk 1.5 yet.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Yes Scanner sc = new Scanner(System.in); is correct. Also as System_Error pointed out you need a ; at the end of recovertime = repcost/(oldopcost - newopcost)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width