| | |
need help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 4
Reputation:
Solved Threads: 0
This program is working fine except it is suppose to give me the total of all the money inputted when option 4 is selected. It is only giving me the last amount that was inputted when option 4 is selected. Can someone give me a clue about what I am doing wrong???
Java Syntax (Toggle Plain Text)
import java.util.*; import java.io.*; public class GiftsDemo1{ //application entry point public static void main(String[] args) { //Define constants int Input = -1; double Amount = 0.0; double totalCollected = 0.0; //display out System.out.println("Gifts Program"); System.out.println(""); while (Input != 4) { System.out.println("Gifts Types:"); System.out.println("1. Enter the number of U.S. Dollars"); System.out.println("2. Enter the number of euros"); System.out.println("3. Enter the number of yen"); System.out.println("4. Exit the program and get total"); System.out.println(""); System.out.print("Please select an option from 1-4 "); //set input stream Scanner in = new Scanner(System.in); Input = Integer.parseInt(in.nextLine()); while ((Input < 1) || (Input > 4)) { System.out.println(" You have entered an invalid selection, " + "please try again"); System.out.print("Please select an option from 1-4 "); in = new Scanner(System.in); Input = Integer.parseInt(in.nextLine()); } if (Input == 4){ System.out.println("Total collected: " + totalCollected + "dollars\n"); } else{ System.out.print("What is the amount to be converted "); Amount = Double.parseDouble(in.nextLine()); if (Input == 1) { totalCollected += (Amount * 1); System.out.println("Conversion Complete: " + totalCollected + " dollars\n"); } else if (Input == 2) { totalCollected += (Amount * 1.24); System.out.println("Conversion Complete: " + totalCollected + " dollars\n"); } else if (Input == 3) { totalCollected += (Amount * 0.0092); System.out.println("Conversion Complete: " + totalCollected + " dollars\n"); } } } } } class Gifts { double dollars; double euros; double yen; double dollarsRate; double eurosRate; double yenRate; double dollarInDollars; double eurosInDollars; double yenInDollars; double dollarInDollars(){ return dollars * dollarsRate; } double eurosInDollars(){ return euros *eurosRate; } double yenInDollars(){ return yen * yenRate; } }
I get this when compiling...
Do you have the Scanner class by any chance? I'm using netbeans 3.6?
Hmm
Java Syntax (Toggle Plain Text)
GiftsDemo1.java [29:1] cannot resolve symbol symbol : class Scanner location: class GiftsDemo1 Scanner in = new Scanner(System.in); ^ GiftsDemo1.java [29:1] cannot resolve symbol symbol : class Scanner location: class GiftsDemo1 Scanner in = new Scanner(System.in); ^ GiftsDemo1.java [38:1] cannot resolve symbol symbol : class Scanner location: class GiftsDemo1 in = new Scanner(System.in); ^ 3 errors Errors compiling GiftsDemo1.
Do you have the Scanner class by any chance? I'm using netbeans 3.6?
Hmm
*Voted best profile in the world*
![]() |
Other Threads in the Java Forum
- Previous Thread: Homework Help
- Next Thread: Swing - JPanel sizing
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt balls binary bluetooth card chat class classes client code component database draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer invokingapacheantprogrammatically j2me japplet jar java javaprojects jmf jni jpanel jtextarea julia link linux list loop machine map method methods mobile netbeans newbie nls number openjavafx oracle parsing print problem program programming project recursion recursive rim scanner screen server set size smart sms socket sort sortedmaps spamblocker sql sqlite string sun swing test threads time tree trolltech unlimited variablebinding webservices windows






