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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default 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. #4
    Junior Member Blackrabbitjack's Avatar
    Join Date
    Mar 2012
    Posts
    16
    My Mood
    Fine
    Thanks
    3
    Thanked 1 Time in 1 Post

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

  5. #5
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Begginer : help would be much appreciated for this exercice!

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

Similar Threads

  1. Begginer Java - Bug in my code?
    By rk2010 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 7th, 2012, 08:12 AM
  2. help im a begginer
    By ivankov2 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 24th, 2011, 07:33 AM
  3. [SOLVED] Begginer Question please help ASAP! (Easy to Answer)
    By Bagzli in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 11th, 2010, 10:00 PM
  4. begginer wondering why his guessing game won't work
    By Ligawulf in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 8th, 2010, 12:22 AM
  5. Any ideas for begginer?
    By SwEeTAcTioN in forum Java Theory & Questions
    Replies: 11
    Last Post: October 27th, 2009, 03:28 AM