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)...
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...
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?...
Need some clarification on the following: I am currently working on an assignment with the following...
Need some clarification on the following: I am currently working on an assignment with the following question: - Identify the commands that are generally causing the highest load on your system and discuss your perspectives on why they cause such a load. Discuss your perspectives on the considerations system administration must give while using these commands. In my research, I can only find linux commands used to identify high loads on a linux system, but as we can see the...
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked...
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked to calculate the sum of all fines in the policeOfficer class from the arraylist i created. I modified the issueParking ticket method which i bolded at the very end to add each issued Parking ticket to the arrayList, i think thats the right way? if not please let me know. What I dont understand how to do is access the fineAmountInCAD from the arrayList...
Hello! I am having trouble starting this program in Java. the objective is as follows: "...
Hello! I am having trouble starting this program in Java. the objective is as follows: " I will include a text file with this assignment. It is a text version of this assignment. Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number. " my question is, how do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT