need help

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2006
Posts: 4
Reputation: warriorone357 is an unknown quantity at this point 
Solved Threads: 0
warriorone357 warriorone357 is offline Offline
Newbie Poster

need help

 
0
  #1
Mar 23rd, 2006
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???

  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: need help

 
0
  #2
Mar 24th, 2006
I get this when compiling...

  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
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: need help

 
0
  #3
Mar 25th, 2006
Scanner is new in JDK 5.0.
Netbeans 3.x is seriously outdated, won't know about it.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC