jeudi 17 octobre 2019

java temperature conversion program not working

I have an assignment for an intro to programming class I'm taking, and I don't have any errors but it still isn't working properly. The assignment is to write a program that converts temperatures both from celsius to fahrenheit and vice versa. It also has to be done in different methods and must then loop back through to be done over and over(which is haven't gotten to this part yet. It keeps going to the else statement in my if-else if-else part. Thanks in advance.

package cps101temperatureconverter;
import static cps101temperatureconverter.CPS101TemperatureConverter.enteredTemp;
import java.util.Scanner;

public class CPS101TemperatureConverter 
{

//char inputChoice;
int input;
static double enteredTemp;
static double calculatedTemp;
char retry;
static Boolean moreToProcess = true;
static double fahrenheitTemp;
static double celsiusTemp;
Scanner keyboard = new Scanner(System.in);
static char c;
static char f;

public static void main(String[] args) 
{
    char inputChoice;
    Scanner keyboard = new Scanner(System.in);
    String inputTempString;
    String inputTypeString;
    System.out.println("This program will convert temperatures.");
    System.out.println("Please Enter a Temperature: ");
    inputTempString= keyboard.nextLine();
    enteredTemp = Double.parseDouble(inputTempString);
    System.out.println("You have entered " + enteredTemp);
    System.out.println("Is this value in Celsius or Fahrenheit? ");
    inputTypeString = keyboard.nextLine();
    inputChoice = inputTypeString.charAt(0);

    if (inputChoice == c)
    {
        CelsiusToFahrenheit();
    }
    else if (inputChoice == f)
    {
        FahrenheitToCelsius();
    }
    else
    {
        System.out.println("You have entered an invalid answer. Please try again.");
    }


}

static void CelsiusToFahrenheit()
{
    calculatedTemp = (9.0/5.0)*enteredTemp + 32;
    System.out.println(enteredTemp + " converted to Fahrenheit is " + calculatedTemp);
}
static void FahrenheitToCelsius()
{
    calculatedTemp = (enteredTemp - 32)*(9.0/5.0);
    System.out.println(enteredTemp + " converted to Celisu is " + calculatedTemp);
}

}

Aucun commentaire:

Enregistrer un commentaire