Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I need help understanding what I'm doing wrong in my program...

807601May 2 2008 — edited May 5 2008
I have already turned the following source code in so this will not help me with my grade. I just want to understand what I'm doing wrong and my professor basically didn't tell me when I asked. I have one more project I have to do for this class and I know that if I can't figure out how to do this current project I will not be able to complet my last project. Basically I am trying to call a method in an if-else statement in another class. Please look at the following code and help me understand where I'm going wrong. Any help is very much appreciated.

public class Gift{

double usDollars = 1;
double euros = 1;
double yen = 1;
final double eurosCalc = 1.24;
final double yenCalc = 0.0092;
Scanner scanner = new Scanner(System.in);
private double totalCollected;

public void enterUSdollar() {
System.out.println("Please enter amount of US currency to add to savings");
usDollars = scanner.nextDouble();
totalCollected = (usDollars + totalCollected);
// Display results
System.out.println("Total money saved:$" + totalCollected);
}

public void enterEuros() {
System.out.println("Please enter amount of euros to add to savings");
euros = scanner.nextDouble();
euros = (euros * eurosCalc);
totalCollected = (euros + totalCollected);
// Display results
System.out.println("Total money saved:$" + totalCollected);
}

public void enterYen() {
System.out.println("Please enter amount of euros to add to savings");
yen = scanner.nextDouble();
yen = (yen * yenCalc);
totalCollected = (yen + totalCollected);
// Display results
System.out.println("Total money saved:$" + totalCollected);

}

}

public static void main(String[] args) {
// TODO Auto-generated method stub


Scanner scanner = new Scanner(System.in);
int menuChoice = 1;
boolean menu = true;


// Prompt the user to choose a number
while (menu == true) {
System.out.println("Please select currency type to enter:");
System.out.println("1. Enter US dollars:");
System.out.println("2. Enter euros:");
System.out.println("3. Enter yen:");
System.out.println("4. To exit the program.");
menuChoice = scanner.nextInt();
}

if (menuChoice == 1){
enterUSdollar();

}
else if (menuChoice == 2){
enterEuros();
}

else if (menuChoice == 3){
enterYen();
}

else if (menuChoice == 4){
menu = false;
System.out.println("Good Bye!");
}

else {
System.out.println("Invalid chioce please select");
System.out.println("a valid choice!");

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2008
Added on May 2 2008
26 comments
115 views