473,414 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Help with conversions in java

11
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
Apr 16 '07 #1
11 1274
r035198x
13,262 8TB
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?
Apr 16 '07 #2
Fozzi
11
Uhm no i havnt been through 1 of those yet, could u give me a link?

Thanks for the reply
Apr 16 '07 #3
r035198x
13,262 8TB
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.
Apr 16 '07 #4
Fozzi
11
uhm had a look at them and it just isnt making any sense
Apr 16 '07 #5
r035198x
13,262 8TB
uhm had a look at them and it just isnt making any sense
You can always ask here anything you don't understand.
Apr 16 '07 #6
Fozzi
11
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
Apr 16 '07 #7
r035198x
13,262 8TB
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.
Apr 17 '07 #8
JosAH
11,448 Expert 8TB
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
Apr 17 '07 #9
Fozzi
11
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 cmdConvertActionPerformed(java.awt.event.ActionEve nt evt) {
int cm = (int)((Double.parseDouble(txtcm.getText()))
* 2.54);
lblOutput.setText(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
Apr 17 '07 #10
JosAH
11,448 Expert 8TB
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 cmdConvertActionPerformed(java.awt.event.ActionEve nt evt) {
int cm = (int)((Double.parseDouble(txtcm.getText()))
* 2.54);
lblOutput.setText(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
Apr 17 '07 #11
Fozzi
11
thanks alot for the help
Apr 17 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Ted | last post by:
I've written a little function to remove everything after the 2nd decimal place for prices which is as follows: - ReturnConvertedCurrency = (fix(iSterling * session("ExchangeRate") * 100) / 100)...
25
by: amit | last post by:
Hi, What will happen in following scenario.. long a = -2; longlong b = a long c; c = *(ulonglong *)&b; b = c; also when
15
by: buda | last post by:
Let me see if I got this :) 1. I know the rules for type conversions in arithmetic expressions 2. I know that an implicit type conversion is done at assignment, so float x = 1.23; int t = (int)...
5
by: MFC | last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key of C#, and C# Weekend Crash Course) and three weeks, I believe I have tried everything to make a certain form function...
36
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a...
18
by: pipito | last post by:
Hi...i am a beginner in C programming... my question is like this... im using the scanf in C to accept input data in output area, printf("name: ");scanf("%s",name); printf(Address:...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
19
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the...
4
by: robtyketto | last post by:
Greetings, I'm a newbie to Java and I cant quite get my head around why it seems most integers appears to be formatted as strings and then later have to be parsed. The code below, passes in the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.