Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 4th, 2005, 07:09 PM
jrg0088 jrg0088 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 jrg0088 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 32 m 42 sec
Reputation Power: 0
Question could please help to write a program using loop (if-else)

I don't experience in programing could please help me
Write a program that will have a following menu
1.Convert fahrenheit to Celsius
2. Convert Celsius to Fahrenheit
The formula for conversion is:

fahrenheit=(9.0)/5)*celsius + 32
Celsius=(5/9)(f-32)
import javax.swing.JOptionPane;
publicclass temperatura
{
publicstaticvoid main (String[]args)
{
int temp;
finalfloat fahrenheit,celsius;


System.out.println(
"enter temperature celsius");

String input=JOptionPane.showinputDialog(
null,"Enter your temperature in celsius", "fahrenheit",JOptionPane.QUESTION_MESSAGE);
floatfahrenheit=parsefloat(input);

if (temp == fahrenheit)
{
fahrenheit=(9.0/5)*temp+32;
System.out.println(
"temperature in celsius");

JOptionPane.showinputDialog(
null,"Enter your temperature in celsius", + celsius, "Output ",JOptionPane_INFORMATION_MESSAGE);
}
else (temp == celsius)
{
celsius=(5/9)*(temp -32);
System.out.println(
"temperature in fahrenheit");
}

JOptionPane.showinputDialog(
null,"Enter your temperature in celsius", + celsius, "Output ",JOptionPane.INFORMATION_MESSAGE);


}
}


Reply With Quote
  #2  
Old March 5th, 2005, 08:54 PM
robertbwild robertbwild is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Location: Jacksonville, Fl.
Posts: 2 robertbwild User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 10 sec
Reputation Power: 0
Send a message via Yahoo to robertbwild
Ooops, I replied to the wrong person..... My Bad......Anyways.... Here's What I tried out today, maybe it will help you...... :

package Temperatura;
import javax.swing.JOptionPane;
public class temperatura
{
public static void main (String[] args)
{
String celsius; // first string entered by user
String fahrenheit; // second string entered by user
String temp; // third string by user
int t; // else if variable
double f; // fahrenheit variable used for both RESULT and celsius calculation
double c; // celsius variable used for both RESULT and fahrenheit calculation
celsius = JOptionPane.showInputDialog( "Enter the temperature in celsius: ");
fahrenheit = JOptionPane.showInputDialog("Enter the temperature in fahrenheit: ");
c = Double.parseDouble(celsius);
f = Double.parseDouble(fahrenheit);

//attempt a menu to calculate either celsius or fahrenheit
temp = JOptionPane.showInputDialog("Enter which temp to calculate 1. celsius or 2. fahrenheit ");

// check menu number for correct t value
t = Integer.parseInt(temp);
JOptionPane.showMessageDialog(null, "You entered: " + t, "RESULTS", JOptionPane.PLAIN_MESSAGE);
if (t == 1) //calculate fahrenheit
{
f =(9.0/5)*c + 32;

// display result
JOptionPane.showMessageDialog(null, "The temperature in fahrenheit is: " + f, "RESULTS", JOptionPane.PLAIN_MESSAGE);
}
else if (t == 2) // calculate celsius
{
c = ((5.0/9) * (f - 32));

JOptionPane.showMessageDialog(null, "The temperature in celsius is: " + c, "RESULTS", JOptionPane.PLAIN_MESSAGE);
}
JOptionPane.showMessageDialog(null, "That's all Folks\nOK I had fun learning this also,\nI'm addicted... I admit it....lol!!!"); // enter silly message here
System.exit(0);
}// end main
}// end class temperatura

Reply With Quote
  #3  
Old March 7th, 2005, 09:08 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Try using [code][/code] tags when posting your code to the forum.
These tags are designed to keep your indents and code structure.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > could please help to write a program using loop (if-else)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT