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???

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...

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

This article has been dead for over six months. Start a new discussion instead.