Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Scanner code won't work

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Scanner code won't work

    Sub: No errors listed / seen
    public class CashRegister {
    	public CashRegister() {
    		purchase = 0;
    		payment = 0;
    	}
    	public void recordPurchase(double amount){
    		 purchase = purchase + amount;
    	}
    	public void enterPayment(int dollars, int quarters, int dimes, int nickels, int pennies){
    		 payment = dollars + quarters*QUARTER_VALUE + dimes*DIME_VALUE
    			 + nickels*NICKEL_VALUE + pennies*PENNY_VALUE;
    	}
    	public double giveChange() {
    		double change = payment - purchase;
    		purchase = 0;
    		payment = 0;
    		return change;
    	}
    		private double purchase;
    	private double payment;
    	public static final double QUARTER_VALUE = 0.25;
    	public static final double DIME_VALUE = 0.1;
    	public static final double NICKEL_VALUE = 0.05;
    	public static final double PENNY_VALUE = 0.01;
     
    	}

    Main (Scanner)
    import java.util.Scanner;
    public class InputTester {
    	public static void main(String [] args) {
    	Scanner in = new Scanner(System.in);
    	CashRegister register = new CashRegister();
    	System.out.print("Enter price: ");
    	double price = in.nextDouble();
    	register.recordPurchase(price);
    		System.out.print("Enter dollars: ");
    		int dollars = in.nextInt();
    		System.out.print("Enter quarters: ");
    		int quarters = in.nextInt();
    		System.out.print("Enter dimes: ");
    		int dimes = in.nextInt();
    		System.out.print("Enter nickels: ");
    		int nickels = in.nextInt();
    		System.out.print("Enter pennies: ");
    		int pennies = in.nextInt();
    		register.enterPayment(dollars, quarters, dimes, nickels, pennies);
    		System.out.print("Your change is: ");
    		System.out.println(register.giveChange());
    	}
    }

    Errors on main
    --------------------Configuration: JDK version 1.6.0_24 <Default>--------------------
    C:\Program Files (x86)\Xinox Software\JCreator LE\MyProjects\School\InputTester\InputTester.java:5: cannot find symbol
    symbol  : class CashRegister
    location: class InputTester
    	CashRegister register = new CashRegister();
    	^
    C:\Program Files (x86)\Xinox Software\JCreator LE\MyProjects\School\InputTester\InputTester.java:5: cannot find symbol
    symbol  : class CashRegister
    location: class InputTester
    	CashRegister register = new CashRegister();
    	                            ^
    2 errors
     
    Process completed.


  2. #2
    Junior Member
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Scanner code won't work

    Every time I make a main and a sub I get this error! I always end up messing around with the folders until it works but it doesn't make sense! I always create and save the main within the same sub folder

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: Scanner code won't work

    Hi r19ecua, I'm beginning programmer so my knowledge is very very limited but I went and copy/pasted your code into eclipse and tried to run it. It worked perfectly fine for me, although after a few trial runs with your program, the change doesn't round out(i.e. change is 1.0999999999999996 instead of 1.10). So I think you're code is perfectly fine and you're in the right direction as for the error.

  4. The Following User Says Thank You to Actinistia For This Useful Post:

    r19ecua (April 21st, 2011)

  5. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Scanner code won't work

    I don't know what to do about the code however I tried recreating the entire thing and it didn't work. Still doesn't work

  6. #5
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Scanner code won't work

    I also copied and paste your code into my compiler & it compiled and ran totally fine. So, there is NO error in your code. I guess it's the problem with saving these two files. Remember to save the main and the CashRegister class inside the same folder. Don't create one folder and put each file into different file even if it's under the sub directory. Save the BOTH file inside one file then try to compile and run the program. I am pretty sure it will work out this time.
    Good luck!

  7. The Following User Says Thank You to andaji For This Useful Post:

    r19ecua (April 21st, 2011)

  8. #6
    Junior Member
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Scanner code won't work

    Quote Originally Posted by andaji View Post
    I also copied and paste your code into my compiler & it compiled and ran totally fine. So, there is NO error in your code. I guess it's the problem with saving these two files. Remember to save the main and the CashRegister class inside the same folder. Don't create one folder and put each file into different file even if it's under the sub directory. Save the BOTH file inside one file then try to compile and run the program. I am pretty sure it will work out this time.
    Good luck!
    All of the programs are inside the same SRC folder! It's JcreatorPro/MyProjects/CashRegister/Src/InputTester
    JcreatorPro/MyProjects/CashRegister/Src/CashRegister

    I don't understand what's wrong???

  9. #7
    Junior Member
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Scanner code won't work

    Thank you guys, I've been programming stuff for hours non-stop hehe. missed an extremely small error!

Similar Threads

  1. Timer code does not work!
    By mariapatrawala in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 10th, 2010, 10:03 AM
  2. WHY this code dont work?
    By sibbe in forum Java Theory & Questions
    Replies: 7
    Last Post: December 9th, 2010, 10:47 AM
  3. please tell me why this code does not work
    By amr in forum Java Theory & Questions
    Replies: 9
    Last Post: December 6th, 2010, 06:46 PM
  4. [SOLVED] "possible loss of precision", except not, code doesn't work, simple question
    By Perd1t1on in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 07:11 PM
  5. Help writing some Scanner code
    By bChEos in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: February 3rd, 2010, 04:27 AM