Jump to content

Making A Tempature Conversion Prgram


Ste

Recommended Posts

I have an assignment for programming 1, and the instructions are to make a program where the user can input any number in degrees celsius, and have the program convert it into fahrenheit.

 

So far this is all I have and i don't know where to go from there.

 

/*

Steven Borchard

Tempature input

*/

import javax.swing.JOptionPane;

public class TrivialApplication {

 

public static void main(String args[]) {

 

String firstNumber= JOptionPane.show.InputDialog("Enter a tempature in Degrees Celeius to convert into Degrees Fahrenheit");

 

 

}

}

 

 

any ideas?

Share this post


Link to post
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

yes the formula is

 

Fahrenheit=(9/5) * Celsius (the input from user) + 32

 

heres my progress.

 

/*

Steven Borchard

Tempature input

*/

import javax.swing.JOptionPane;

public class TrivialApplication {

 

public static void main(String args[]) {

 

String firstNumber= JOptionPane.show.InputDialog("Enter a tempature in Degrees Celeius to convert into Degrees Fahrenheit");

 

int celsius= Integer.parseInt( firstNumber );

int num1= 9;

int num2= 5;

int num3= 32;

 

 

}

}

Share this post


Link to post
Share on other sites

yeah it wa one of our 1st java assignments, just parse double that string you took in, once you get that apply the formula to the number you get then i suppose your suposed to print the result correct?

 

EDIT: any reason you stored the formula stuff in variables? why not jsut hard code the formula...it wont change.

 

oh and use parseDouble() instead bc if not and you work with it you will loose the percision. you are goign to want the values to a Decimal now arent you :D.

Edited by cchalogamer

Share this post


Link to post
Share on other sites

as in:

 

double result = ((9/5) * celsius) + 32;

 

granted more ( ) than u need but i tend to do that :)

 

EDIT:

 

ok i hope u understand that bc MY AP comp. Sci. class is about to start. im actually in there...well here....now.

Edited by cchalogamer

Share this post


Link to post
Share on other sites

crap your still lost lol

 

 

ok add

 

double result = ((9/5) * celsius) + 32;

System.out.println("In Deg. F " + result);

 

(actually use the other output stuff you use lol forgot we do everything in console to make it a little less frustrating lol)

 

and it should print out the answer... you dont nees to code variables for all the numbers you use in a formula. it's a waste of time and effort.

 

EDIT: Well i hope that helps you, just finished our quiz. If you think your lost now just wait until you get to Classes/Objects/static arrays/ArrayLists/stacks :blink: torture i tell you :lol:

Edited by cchalogamer

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...