Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Begginer : help would be much appreciated for this exercice!

1. ## Begginer : help would be much appreciated for this exercice!

Conversion between an price before tax (BT) and after tax (AT)

Write a program that, in a menu, give to the user several choices :

- Convert price BT in AT
- Convert price AT in BT
- End the application

(if convert price BT in AT, price should be *1,196, if convert price AT in BT, price should be /1.196)

Here is my code (which is wrong for now!). Thanks in advance for your help!

public class Exercice_3 {

/**
* @param args
*/
public static void main(String[] args) {
int choice;
float price_BT, price_AT
do
{
choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter your choice:" + "\n'1' to calculate the price AT from a price BT," + "\n'2' to calculate the price BT from a price AT" + "\n'3' to end the application."));
if (choice==1);
price_BT = Float.parseFloat(JOptionPane.showInputDialog(null, "Enter a price BT :" + choice1 (float price_BT, float price_AT)));
else if (choice==2)
price_AT= Float.parseFloat(JOptionPane.showInputDialog(null, "Enter a price AT :"+ choice2 (float price_BT, float price_AT)));
}
while(choice !=3);

System.out.println("You ended the application.");
}

private static Object choice2(float price_BT, float price_AT) {
return price_BT*(float)1.196;
}
private static Object choice1(float price_BT, float price_AT) {
{
return price_AT/(float)1.196;
}
}
}

2. ## Re: Begginer : help would be much appreciated for this exercice!

Please explain what the problem is. Post any error messages here.
Show the program's output and explain what is wrong with it and show what the output should be.

3. ## Re: Begginer : help would be much appreciated for this exercice!

Hello linus101!
Your code doesn't compile, it has syntax errors. To fix the errors i think you should make your application work in the console first before using JOptionPane. This will make it easier.

4. ## Re: Begginer : help would be much appreciated for this exercice!

Jumping the gun on trying to make the GUI is always a bad idea. Make your methods work and your logic correct before you try to make it look pretty. What compiler are you using? Also, it might be helpful to format your coding so that it looks nested, ie:
```classname{
methodName{
//code for the inside of your method
}

secondMethod{
//code for the inside of your second method
}
}```

I hope I did a good job of explaining that. I have class in a few minutes, and I THINK I understand what you're trying to do, I will take a more in-depth look after class.

5. ## Re: Begginer : help would be much appreciated for this exercice!

Thank you all, I'll try again with those advices!