I am writing a program that takes user input, converts euros or yen to u.s. dollars and should output the total dollars collected when the user chooses to exit the program. My program is converting everything okay. However, when I choose to exit the program and get the total it is only printing out the last value that was entered and not the total collected. Can someone give me a clue about what I am doing wrong???
import java.util.*;
import java.io.*;
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;
}
}
public class GiftsDemo {
//application entry point
public static void main(String[] args) {
//Define constants
int Input = 0;
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 = in.nextInt();
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 = in.nextInt();
}
if (Input == 4){
System.out.println("Total collected: " + totalCollected + "dollars\n");
}
else{
System.out.print("What is the amount to be converted ");
Amount = in.nextDouble();
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");
}
}
}
}
}