java Help Please

Discussion in 'OT Technology' started by High Voltage, Jan 17, 2006.

  1. High Voltage

    High Voltage Guest

    i dont know what i am doing wrong i am getting this error. it s problem with the type scanner being undefined. how do i define it?

     
  2. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    I believe the java.util.Scanner class is new in the Java 2 SE 5.0 release.
     
  3. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    1st, class names are supposed to start with a capitol.

    2nd, its Scanner scan = new Scanner(System.in);
    read the api http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

    3rd, format the number, otherwise you'll get 00000000000001 at the end of your double in java.

    Code:
    import java.util.Scanner;
    import java.text.NumberFormat;
    
    public class JarCoinAdd {
    	public static void main(String[] args) {
    		double pennies;
    		double nickels;
    		double dimes;
    		double quarters;
    		Scanner scan = new Scanner(System.in);
    		System.out.print("How many pennies in your jar:");
    		pennies = scan.nextDouble();
    		System.out.print("How many nickels in your jar:");
    		nickels = scan.nextDouble();
    		System.out.print("How many dimes in your jar:");
    		dimes = scan.nextDouble();
    		System.out.print("How many quarters in your jar:");
    		quarters = scan.nextDouble();
    		double total;
    		double numofpennies;
    		double numofnickels;
    		double numofdimes;
    		double numofquarters;
    		numofpennies = pennies * .01;
    		numofnickels = nickels * .05;
    		numofdimes = dimes * .1;
    		numofquarters = quarters * .25;
    		total = numofpennies + numofnickels + numofdimes + numofquarters;
    		NumberFormat nf = NumberFormat.getInstance();
    		System.out.println("your total is $" + nf.format(total));
    	}
    }
    
     
  4. High Voltage

    High Voltage Guest

    CyberBullets and Samm thank you so much for your help and replies. I am a newbie at this so i am still learning. thanks again!
     
  5. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    np. i'm always trollin/helpin in OTC&P :) :wiggle:
     

Share This Page