Question

In: Computer Science

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 not remember it, your answer should not always be a whole number.

☑ Then have your program ask for the temperature in celsius and print the equivalent farenheit, in the same way.

I have correctly been able to do the first step, however i am unable to figure out how to properly code for the second task, where the program asks for the temperature in celsius and prints the farenheit equivalent. Here is what i have done.

import java.util.Scanner;


public class TempConverter {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner scName = new Scanner(System.in);
String name;
System.out.print("Enter your name : ");
name = scName.nextLine();
System.out.print("Hi "+name+" Enter temperature in farenheit : ");
double temp = sc.nextDouble();
double tempInCel = (temp - 32) * 5 / 9;
double tempInFahr = (temp *9/5)+ 32;
System.out.println(name+", your "+temp+" degrees farenheit would be "+tempInCel+" degrees celsius");
System.out.println(", your "+temp+ " degrees celsius would be" +tempinFahr+" degrees celsius");
}

}

Solutions

Expert Solution

import java.util.Scanner;


public class TempConverter {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner scName = new Scanner(System.in);
String name;
System.out.print("Enter your name : ");
name = scName.nextLine();
System.out.print("Hi "+name+" Enter temperature in farenheit : ");
double temp = sc.nextDouble();
double tempInCel = (temp - 32) * 5 / 9;
System.out.println(name+", your "+temp+" degrees farenheit would be "+tempInCel+" degrees celsius");
System.out.print("Hi "+name+" Enter temperature in celsius : ");
sc = new Scanner(System.in);
temp = sc.nextDouble();
double tempInFahr = (temp *9/5)+ 32;
System.out.println(name+", your "+temp+ " degrees celsius would be " +tempInFahr+" degrees farenheit");
}

}

/* OUTPUT */

Enter your name : Bob
Hi Bob Enter temperature in farenheit : 32
Bob, your 32.0 degrees farenheit would be 0.0 degrees celsius
Hi Bob Enter temperature in celsius : 0
Bob, your 0.0 degrees celsius would be 32.0 degrees farenheit


Related Solutions

Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I...
Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I am confused on what they're asking :             Choose a stock that interests you. Utilizing Bloomberg (or other financial websites) as a source of data, collect the following      information:                         a. The stock’s Beta                         b. The rate of return on the market (S&P 500 Index)                         c. The risk-free rate (rRF)                         d. The last dividend paid (D0)...
Needs to be coded in Python. Hello i am working on a project for my computer...
Needs to be coded in Python. Hello i am working on a project for my computer programming course and i am having trouble with one part. The code needs to be able to produce two versions of an output given inputs by the user. for instance. Here is the code i have to produce the following output. The input from the user are num1 num2 and asc which is just asking if they want the output to be ascending or...
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...
hello, I am having an issue with a question in my highway engineering course. the question...
hello, I am having an issue with a question in my highway engineering course. the question is: An equal tangent sag vertical curve has an initial grade of –2.5%. It is known that the final grade is positive and that the low point is at elevation 82 m and station 1 + 410.000. The PVT of the curve is at elevation 83.5 m and the design speed of the curve is 60 km/h. Determine the station and elevation of the...
Hello all, I am toward the beginning of my semseter and am still pretty rusty working...
Hello all, I am toward the beginning of my semseter and am still pretty rusty working with code. here is my following goal: basically create a structure and populate an array from a txt file which contains 98 45.70 72 15.0 12 0.0 56 43.26 83 123.0 28 931.96 123 12.38 "Create a struct named familyFinance that contains 2 members: ▪ int acctNos ▪ float balance o (prior to the while loop) Create an array financeAry (size 10), of type...
I have been working on this assignment in Java programming and can not get it to...
I have been working on this assignment in Java programming and can not get it to work. This method attempts to DECODES an ENCODED string without the key.    public static void breakCodeCipher(String plainText){ char input[]plainText.toCharArray(); for(int j=0; j<25; j++){ for(int i=0; i<input.length; i++) if(input[i]>='a' && input[i]<='Z') input[i]=(char)('a'+((input[i]-'a')+25)%26); else if(input[i]>='A'&& input[i]<='Z') input[i]=(char)('A'+ ((input[i]-'A')+25)%26); } System.out.println(plainText)    }
Hello, I am working on a marketing assignment that involves analyzing a Kelloggs cereal commerical that...
Hello, I am working on a marketing assignment that involves analyzing a Kelloggs cereal commerical that involves product/brand anthropomorphism. The short video is on YouTube. And the YouTube address for the video is "https://www.youtube.com/watch?v=2wRjCflAJIU". After watching the video, please answer the following questions. I would greatly appreciate help with this assignment. 1) What is this commercial about, describe the commerical? 2) Define what product/brand anthropomorphism is. 3) Who is the targeted audience? What are their motivations to buy this product?...
Hi, I am working on an assignment in C-Programming language dealing with LInked lists, in the...
Hi, I am working on an assignment in C-Programming language dealing with LInked lists, in the code there is instructions on where to write the code. I do not know how to write Linked Lists. Has to be in the C-language, Any help is greatly appreciated   //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void delink(void); void memexit(void); void wfile(void); /********************************************************************* this is the structure to hold a agent...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT