Help with conversions in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fozzi
    New Member
    • Apr 2007
    • 11

    #1

    Help with conversions in java

    Hey all, i recently started java programming and im a bit stuck with it all and just wondered if u could help. What i am trying to do id to convert cm to ft and inches, i have the jframe set up with a text field for entering the cm and a text field ready for the output with a button for the convert. However i have only just started, so could someone possibly help me out with the code please to set me on my way? would be much appriciated
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Fozzi
    Hey all, i recently started java programming and im a bit stuck with it all and just wondered if u could help. What i am trying to do id to convert cm to ft and inches, i have the jframe set up with a text field for entering the cm and a text field ready for the output with a button for the convert. However i have only just started, so could someone possibly help me out with the code please to set me on my way? would be much appriciated
    Do not use a textfield for output. Use a label instead. Have you gone through a simple event handling tutorial yet?

    Comment

    • Fozzi
      New Member
      • Apr 2007
      • 11

      #3
      Uhm no i havnt been through 1 of those yet, could u give me a link?

      Thanks for the reply

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Fozzi
        Uhm no i havnt been through 1 of those yet, could u give me a link?

        Thanks for the reply
        Have a look at this and this.

        Comment

        • Fozzi
          New Member
          • Apr 2007
          • 11

          #5
          uhm had a look at them and it just isnt making any sense

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Fozzi
            uhm had a look at them and it just isnt making any sense
            You can always ask here anything you don't understand.

            Comment

            • Fozzi
              New Member
              • Apr 2007
              • 11

              #7
              could u just give me a little help with the coding because i looked at the link and its fareheit but could u help me with the coding for cm to ft and inches, would be much appreciated

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by Fozzi
                could u just give me a little help with the coding because i looked at the link and its fareheit but could u help me with the coding for cm to ft and inches, would be much appreciated
                I was not giving you a link to a solution for your homework. I was pointing you to a tutorial. You should really be trying to do the homework yourself rather than trying to get someone to give you a solution.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by Fozzi
                  could u just give me a little help with the coding because i looked at the link and its fareheit but could u help me with the coding for cm to ft and inches, would be much appreciated
                  Your reply really surprises me: the supplied example teaches you something
                  about converting X to Y. The example uses Fahrenheit and Celcius; your Xs
                  and Ys are centimeters and feet. It doesn't take a rocket scientist to convert
                  the example's constants and conversion formula to the constants and formulas
                  you need in your example.

                  kind regards,

                  Jos

                  Comment

                  • Fozzi
                    New Member
                    • Apr 2007
                    • 11

                    #10
                    ok sorry about that guys was in a bit of a rush last night, i sat down this morning and got the basics sorted here is my code:

                    private void cmdConvertActio nPerformed(java .awt.event.Acti onEvent evt) {
                    int cm = (int)((Double.p arseDouble(txtc m.getText()))
                    * 2.54);
                    lblOutput.setTe xt(cm + " inches ");

                    However there is just 1 thing that i need help with now, i need the output not to come out as a interger but as a decimal

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by Fozzi
                      ok sorry about that guys was in a bit of a rush last night, i sat down this morning and got the basics sorted here is my code:

                      private void cmdConvertActio nPerformed(java .awt.event.Acti onEvent evt) {
                      int cm = (int)((Double.p arseDouble(txtc m.getText()))
                      * 2.54);
                      lblOutput.setTe xt(cm + " inches ");

                      However there is just 1 thing that i need help with now, i need the output not to come out as a interger but as a decimal
                      That's easy: make your 'cm' variable a double then and remove the (int) cast.

                      kind regards,

                      Jos

                      Comment

                      • Fozzi
                        New Member
                        • Apr 2007
                        • 11

                        #12
                        thanks alot for the help

                        Comment

                        Working...