944,192 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1368
  • Java RSS
Mar 23rd, 2006
0

need help

Expand Post »
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)
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class GiftsDemo1{
  5.  
  6. //application entry point
  7. public static void main(String[] args) {
  8.  
  9. //Define constants
  10. int Input = -1;
  11. double Amount = 0.0;
  12. double totalCollected = 0.0;
  13.  
  14. //display out
  15. System.out.println("Gifts Program");
  16. System.out.println("");
  17.  
  18. while (Input != 4) {
  19.  
  20. System.out.println("Gifts Types:");
  21. System.out.println("1. Enter the number of U.S. Dollars");
  22. System.out.println("2. Enter the number of euros");
  23. System.out.println("3. Enter the number of yen");
  24. System.out.println("4. Exit the program and get total");
  25. System.out.println("");
  26. System.out.print("Please select an option from 1-4 ");
  27.  
  28. //set input stream
  29. Scanner in = new Scanner(System.in);
  30. Input = Integer.parseInt(in.nextLine());
  31.  
  32. while ((Input < 1) || (Input > 4))
  33. {
  34. System.out.println(" You have entered an invalid selection, " +
  35. "please try again");
  36.  
  37. System.out.print("Please select an option from 1-4 ");
  38. in = new Scanner(System.in);
  39. Input = Integer.parseInt(in.nextLine());
  40. }
  41.  
  42. if (Input == 4){
  43. System.out.println("Total collected: " +
  44. totalCollected + "dollars\n");
  45. }
  46. else{
  47. System.out.print("What is the amount to be converted ");
  48. Amount = Double.parseDouble(in.nextLine());
  49.  
  50. if (Input == 1)
  51. {
  52. totalCollected += (Amount * 1);
  53. System.out.println("Conversion Complete: " +
  54. totalCollected + " dollars\n");
  55. }
  56. else if (Input == 2)
  57. {
  58. totalCollected += (Amount * 1.24);
  59. System.out.println("Conversion Complete: " +
  60. totalCollected + " dollars\n");
  61. }
  62. else if (Input == 3)
  63. {
  64. totalCollected += (Amount * 0.0092);
  65. System.out.println("Conversion Complete: " +
  66. totalCollected + " dollars\n");
  67. }
  68. }
  69. }
  70. }
  71. }
  72.  
  73. class Gifts {
  74. double dollars;
  75. double euros;
  76. double yen;
  77. double dollarsRate;
  78. double eurosRate;
  79. double yenRate;
  80. double dollarInDollars;
  81. double eurosInDollars;
  82. double yenInDollars;
  83.  
  84. double dollarInDollars(){
  85. return dollars * dollarsRate;
  86. }
  87.  
  88. double eurosInDollars(){
  89. return euros *eurosRate;
  90. }
  91.  
  92. double yenInDollars(){
  93. return yen * yenRate;
  94. }
  95. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
warriorone357 is offline Offline
4 posts
since Mar 2006
Mar 24th, 2006
0

Re: need help

I get this when compiling...

Java Syntax (Toggle Plain Text)
  1. GiftsDemo1.java [29:1] cannot resolve symbol
  2. symbol : class Scanner
  3. location: class GiftsDemo1
  4. Scanner in = new Scanner(System.in);
  5. ^
  6. GiftsDemo1.java [29:1] cannot resolve symbol
  7. symbol : class Scanner
  8. location: class GiftsDemo1
  9. Scanner in = new Scanner(System.in);
  10. ^
  11. GiftsDemo1.java [38:1] cannot resolve symbol
  12. symbol : class Scanner
  13. location: class GiftsDemo1
  14. in = new Scanner(System.in);
  15. ^
  16. 3 errors
  17. Errors compiling GiftsDemo1.

Do you have the Scanner class by any chance? I'm using netbeans 3.6?
Hmm
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 25th, 2006
0

Re: need help

Scanner is new in JDK 5.0.
Netbeans 3.x is seriously outdated, won't know about it.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Homework Help
Next Thread in Java Forum Timeline: Swing - JPanel sizing





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC