![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#31 |
|
Expert Programmer
|
[php]
import java.util.Scanner; public class Temperature { public static void main(String args[]) { Scanner input=new Scanner(System.in); double Celsius=0,Fahrenheit=0,tempValue=0; int choice=0; System.out.print("+===========================+\n"); System.out.print("| [1] Convert to Fahrenheit |\n"); System.out.print("| [2] Convert to Celsius |\n"); System.out.print("+===========================+\n"); System.out.print("+->"); choice=input.nextInt(); switch(choice) { case 1: System.out.print("Enter Celsius: "); Celsius=input.nextDouble(); tempValue=(Celsius+32)*(0.55555555555555555555555555555556); System.out.printf("Fahrenheit = %.2f",tempValue); break; case 2: System.out.print("Enter Fahrenheit: "); Fahrenheit=input.nextDouble(); tempValue=(Fahrenheit-32)*(1.8); System.out.printf("Celsius = %.2f",tempValue); break; default: System.out.println("Invalid Input... Try Again."); break; } } } [/php] Maybe you can explain to me why i convert from Celsius to Fahrenheit.. get 2 numbers try to reverse and get different numbers... i messed up ![]()
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#32 |
|
Sexy Programmer
|
dammn it, that pisses me off! I didnt think of the scheisse Switch statement to do it! I would have been A LOT easier than what I did! OMG!
[PHP] import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Celsius extends JApplet implements ActionListener { double celsius; double fahrenheit; JButton convertbutton; JLabel labelC; JLabel labelF; JTextField celField; JTextField fahrField; public void init() { super.setSize(400, 150); Container window = getContentPane(); window.setLayout(new FlowLayout()); labelC = new JLabel("Celsius"); labelF = new JLabel("Fahrenheit"); convertbutton = new JButton("Convert"); convertbutton.addActionListener(this); celField = new JTextField(10); fahrField = new JTextField(10); window.add(labelF); window.add(fahrField); window.add(labelC); window.add(celField); window.add(convertbutton); } public void actionPerformed(ActionEvent actionEvent) { String input = fahrField.getText(); fahrenheit = Double.parseDouble(input); setConversion(fahrenheit); celsius = getConversion(); celsius = Math.round(celsius); celField.setText(Double.toString(celsius)); } public void setConversion(double d) { celsius = ((5.0 / 9.0) * (d - 32.0)); } public double getConversion() { return celsius; } } [/PHP]
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#33 |
|
Expert Programmer
|
Here is a suggestion... instead of putting a lot of spaces use escape keys.
System.out.println("Hello\t" + "World");Hello World Oh yeah... I think the "Keyboard Class" will replace the Keyboard Listener even in an applet. You can get the "Keyboard Class" from my signature.
__________________
|
|
|
|
|
|
#34 |
|
Expert Programmer
|
converting is easy.. but can you convert back? mine isn't working!!!
i set celsius to 50 then i convert i get 147.60 fahrenheit. then when i set fahrenheit to 147.60 and convert i get 64.22 celsius? WTF??? EDIT: My New Code [php] import java.util.Scanner; public class Temperature { public static void main(String args[]) { Scanner input=new Scanner(System.in); double Celsius=0,Fahrenheit=0,tempValue=0; int choice=0; System.out.print("+===========================+\n"); System.out.print("| [1] Convert to Fahrenheit |\n"); System.out.print("| [2] Convert to Celsius |\n"); System.out.print("+===========================+\n"); System.out.print("+->"); choice=input.nextInt(); switch(choice) { case 1: System.out.print("Enter Celsius: "); Celsius=input.nextDouble(); tempValue=(Celsius+32)*(9.0/5.0); System.out.printf("Fahrenheit = %.2f",tempValue); break; case 2: System.out.print("Enter Fahrenheit: "); Fahrenheit=input.nextDouble(); tempValue=(Fahrenheit-32)*(5.0/9.0); System.out.printf("Celsius = %.2f",tempValue); break; default: System.out.println("Invalid Input... Try Again."); break; } } } [/php] EDIT2: Here is a tip for you reggaeton_king to shorten your code [php] celsius = setConversion(fahrenheit); public double setConversion(double d) { return ((5.0 / 9.0) * (d - 32.0)); } [/php]
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#35 |
|
Sexy Programmer
|
Why even that?
just do this [PHP] System.out.println("Hello\tWorld"); [/PHP]
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#36 |
|
Expert Programmer
|
Oops sorry I forgot about that. Yeah that works too.
![]()
__________________
|
|
|
|
|
|
#37 | |
|
Sexy Programmer
|
Quote:
do this [PHP] //from celsius to fahrenheit tempValue = (9 / 5) * Celsius + 32; //from fahreheit to celsius tempValue = ( 5 / 9 ) * (Fahrenheit - 32); [/PHP] tell us the results! EDIT: Now you did it! lol you did it while I was posting this! lol
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
|
#38 |
|
Expert Programmer
|
i edited my previous post, please observe.
i edited my code to match your post.. and it still doesn't work [php] switch(choice) { case 1: System.out.print("Enter Celsius: "); Celsius=input.nextDouble(); tempValue=(9.0/5.0) * (Celsius+32); System.out.printf("Fahrenheit = %.2f",tempValue); break; case 2: System.out.print("Enter Fahrenheit: "); Fahrenheit=input.nextDouble(); tempValue=(5.0/9.0) * (Fahrenheit-32); System.out.printf("Celsius = %.2f",tempValue); break; default: System.out.println("Invalid Input... Try Again."); break; } [/php]
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#39 |
|
Sexy Programmer
|
lol me too now!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#40 |
|
Expert Programmer
|
did you catch that tip for you to shorten code?
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|