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;
}
}
}
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.
Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
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.
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:
Code :
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.
Re: Begginer : help would be much appreciated for this exercice!
Thank you all, I'll try again with those advices!