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...
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 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...
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 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...
In java, I keep getting the error below and I can't figure out what i'm doing...
In java, I keep getting the error below and I can't figure out what i'm doing wrong. Any help would be appreciated. 207: error: not a statement allocationMatrix[i][j];
I need to figure out what questions could be asked from these scenarios. - A snowboarder...
I need to figure out what questions could be asked from these scenarios. - A snowboarder comes off of a ramp at an angle of theta above the horizontal, with a speed of v. The end of the ramp is a height h above the ground. Neglect friction and air resistance. - A boy is standing on a ramp that is inclined at an angle theta above the ground. He is not slipping due to a static frictional force of...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------ class Robot{ int serialNumber; boolean flies,autonomous,teleoperated; public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){ this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public int getSerialNumber(){ return this.serialNumber; } public boolean canFly(){ return this.flies; } public boolean isAutonomous(){ return this.autonomous; } public boolean isTeleoperated(){ return this.teleoperated; } public String getCapabilities(){ StringBuilder str = new StringBuilder(); if(this.flies){str.append("canFly");str.append(" ");} if(this.autonomous){str.append("autonomous");str.append("...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT