Question

In: Computer Science

this is my assignment for intro to java tha i could not figure out, my system...

this is my assignment for intro to java tha i could not figure out, my system just crashed wit a lot of errors. thank for your help

Create a new Java class inside your project folder.
The name of the class should be: TempConverter
Note that this means you should have the following line at the top of your program:

public class TempConverter

Write a program that allows the user to convert a temperature given in degrees Celsius or Fahrenheit to the opposite value.

Begin by getting a temperature from the user. After the temperature, ask the user to enter "C" or "c" for Celsius or "F" or "f" for Fahrenheit. If the user enters anything other than "C" or "F", then display an error message telling the user to only enter "C" or "F".

Once you have a temperature and the unit, then convert the temperature to the opposite unit and display the result. The answer should be displayed with only one decimal place.

The formula to convert a Celsius temperature to Fahrenheit is:
Degrees_F = (9(Degrees_C)/5) + 32)

The formula to convert a Fahrenheit temperature to Celsius is:
Degrees_C = 5(Degrees_F− 32)/9

The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:

Enter a temperature: 98.6
Enter (C)elsius or (F)ahrenheit: F

The equivalent temperature in Celsius is: 37.0

Here is another example run of the program:

Enter a temperature: 23.9
Enter (C)elsius or (F)ahrenheit: f

The equivalent temperature in Celsius is: -4.5

Here is another example run of the program:

Enter a temperature: 100
Enter (C)elsius or (F)ahrenheit: C

The equivalent temperature in Fahrenheit is: 212.0

Here is another example run of the program:

Enter a temperature: 49
Enter (C)elsius or (F)ahrenheit: M

Error: Enter only "C" or "F".

Solutions

Expert Solution

Program :

import java.util.Scanner;
public class TempConverter
{
public static void main(String args[])
{
char ch; // variable declaration
double temp,c,f;
System.out.print("Enter a temperature : ");
Scanner sc = new Scanner(System.in);
temp = sc.nextDouble(); // Accept temparature
System.out.println("Enter (C)elsius or (F)ahrenheit: F");
System.out.print("Enter Choice :");
ch = sc.next().charAt(0); // Accept choice
if(ch=='f'||ch=='F')   
{
c = ((temp - 32) * 5) / 9; // convert temparature in Celsius
System.out.println("The equivalent temperature in Celsius is:" + c);
}
if(ch=='c'||ch=='C')
{
f = (9 * temp / 5) + 32; // convert temparature in fahrenheit   
System.out.println("The equivalent temperature in Fahrenheit is:" +f);
}
System.out.println("Enter only C or F.");
}
}

Output :


Related Solutions

This is a question from Intro to Bayesian Statistics but I can't figure out what is...
This is a question from Intro to Bayesian Statistics but I can't figure out what is expected here. Derive the posterior distribution of obtaining heads in coin flips. The prior has p(θ = .25) = .25, p(θ = .50) = .50, and p(θ = .75) = .25. The data consist of a specific sequence of flips with 3 heads and 9 tails, so p(Data|θ) = θ^3 (1 − θ) ^9.
in java: In my code at have my last two methods that I cannot exactly figure...
in java: In my code at have my last two methods that I cannot exactly figure out how to execute. I have too convert a Roman number to its decimal form for the case 3 switch. The two methods I cannot figure out are the public static int valueOf(int numeral) and public static int convertRomanNumber(int total, int length, String numeral). This is what my code looks like so far: public static void main(String[] args) { // TODO Auto-generated method stub...
This is for java For my assignment, I was supposed to make a number guessing game....
This is for java For my assignment, I was supposed to make a number guessing game. The class, HiLo, should pick a random number between 1 and 100 (inclusive). Then, prompt the user to guess the number. On each guess, print if the user is correct or if the guess is too high or too low. Allow only 5 guesses. In the end, print out the correct answer and how many attempts were made. Then give the user the option...
For Python, I cannot figure out why "and" is printing at the beginning of my list....
For Python, I cannot figure out why "and" is printing at the beginning of my list. Can someone help? listToPrint = [] while True: newWord = input("Enter a word to add to the list (prest return to stop adding words) > ") newWord == "": break else: listToPrint.append(newWord) for item in listToPrint[:-1]: print(item, end=', ') print('and', listToPrint[-1]) If I enter m, n, b to the list, it executes to and m, n, b
Hello i am working on an assignment for my programming course in JAVA. The following is...
Hello i am working on an assignment for my programming course in JAVA. The following is the assignment: In main, first ask the user for their name, and read the name into a String variable. Then, using their name, ask for a temperature in farenheit, and read that value in. Calculate and print the equivalent celsius, with output something like Bob, your 32 degrees farenheit would be 0 degrees celsius Look up the celsius to farenheit conversion if you do...
I cannot figure out this problem, I've made a few attempts at solving it. I could...
I cannot figure out this problem, I've made a few attempts at solving it. I could really use some help. The question is : 75.00 mL of 0.225 M HNO2 is titrated to its equivalence point with 0.100 M NaOH. What is the pH at its' equivalence point? Please help!
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
Cant figure out why my out is wrong for my c++ program. for example if the...
Cant figure out why my out is wrong for my c++ program. for example if the initial value is 100, the intrest rate is 10%, and it takes 6 months for maturity the output should be $105 but instead it outputs 101.657 please help. #include <iostream> #include <cmath> using namespace std; struct account { double balance; double interest_rate; int term; }; void info(account& accountinfo); int main(void) { double calc1, calc2, calc3; account accountinfo; info(accountinfo); calc1 = accountinfo.interest_rate / 100; calc2...
I am trying to figure out which test analysis to use for my research questions. I...
I am trying to figure out which test analysis to use for my research questions. I was thinking about think about multivariate because of the number of variable being addressed in the study but there is also the possibility to use univariate to address each question. What are the current levels of police satisfaction in CMPD jurisdictions? What is the public’s perception of crime in CMPD jurisdictions? Does “hot spot” policing reduce crime in CMPD jurisdictions? How does broken windows...
Hey there! My professor wrote this vague problem on the board and I can't figure out...
Hey there! My professor wrote this vague problem on the board and I can't figure out how to solve it so --- I apologize in advance for any lack of clarity. 50.0 mL of 0.03M of Cysteine is titrated by 0.06M of NaOH pKa 2= 8.37 pKa 1 = 1.92 What is the pH of the solution..... 1) Before any titrant is added 2) 12.5 mL of NaOH 3) 25.0 mL of NaOH 4) 37.5 mL of NaOH 5) 50.0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT