System.out.println("Enter temp (ex. 70 F or 23 C): ")
From there I read the line and take in the temperature number and the "C" or the "F" to determine which function it should be converted in(f2c() or c2f() ).
I am having problems creating a string that will read the letter to determine Fahrenheit or Celsius.
Can anyone please help me fix this? I would greatly appreciate it.
My code is no where near complete. I know I need 3 functions and a do while loop to complete the statement.
Here is my bad code:
Quote
//Converter.java
import java.util.Scanner;
public class Converter {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int x;
double convertedTemp;
double enteredTemp;
do
System.out.println("Enter temp (ex. 70 F or 23 C): ");
enteredTemp = reader.nextDouble();
String d = input.nextInt();
while (input.hasNext())
} if (Sting d = "C")
System.out.println("The Celsius temperature you entered will equal " + convertedTemp + " degrees Farenheit.");
else if (String d = "F")
System.out.println("The Farenheit temperature you entered will equal " + convertedTemp + " degrees Celsius.");
public f2c(String[] args) {
convertedTemp = (5.0/9) * (enteredTemp - 32);
System.out.println("The Farenheit temperature you entered will equal " + convertedTemp + " degrees Celsius.");
}
public f2c(String[] args) {
convertedTemp = (9.0/5)* enteredTemp + 32;
}
}
import java.util.Scanner;
public class Converter {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int x;
double convertedTemp;
double enteredTemp;
do
System.out.println("Enter temp (ex. 70 F or 23 C): ");
enteredTemp = reader.nextDouble();
String d = input.nextInt();
while (input.hasNext())
} if (Sting d = "C")
System.out.println("The Celsius temperature you entered will equal " + convertedTemp + " degrees Farenheit.");
else if (String d = "F")
System.out.println("The Farenheit temperature you entered will equal " + convertedTemp + " degrees Celsius.");
public f2c(String[] args) {
convertedTemp = (5.0/9) * (enteredTemp - 32);
System.out.println("The Farenheit temperature you entered will equal " + convertedTemp + " degrees Celsius.");
}
public f2c(String[] args) {
convertedTemp = (9.0/5)* enteredTemp + 32;
}
}
I will donate money via PayPal for whoever sends me the corrected code.


Sign In
Create Account

Back to top










