(Convert Celsius to Fahrenheit) Write a
fahrenheit = (9 / 5) * celsius + 32
Hint: In Java, 9 / 5 is 1, but 9.0 / 5 is 1.8.
Here is a sample run:
Convert Celsius to Fahrenheit
Program Plan:
- Define the class
- Define the main method using public static main.
- Declare the required variables.
- Prompt the user to enter Celsius value.
- Read the input
- Convert it into Fahrenheit value.
- Display the result on the screen.
- Define the main method using public static main.
The below program is used to convert Celsius to Fahrenheit.
Explanation of Solution
Program:
//class definition
public class Cel_Far
{
//Main method
public static void main(String[] args)
{
//declare scanner variable
Scanner in = new Scanner(System.in);
// Prompt the user to enter Celsius
System.out.print("Enter a temperature in Celsius: ");
//read the input
double celsius = in.nextDouble();
// Convert Celsius to Fahrenheit
double fh = (9.0 / 5) * celsius + 32;
// Display the result on the screen
System.out.println(celsius + " Celsius is " +
fh + " Fahrenheit");
}
}
Enter a temperature in Celsius: 43.5
43.5 Celsius is 110.3 Fahrenheit
Want to see more full solutions like this?
Chapter 2 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Mechanics of Materials (10th Edition)
Degarmo's Materials And Processes In Manufacturing
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
- ) The Bahraini Charity Club is conducting a fundraiser by selling chilli dinners to go.The price is BD2.1 for an adult meal and BD1.2 for a child’s meal.Write a Java program that accepts the number of each type of meal ordered and displaythe total money collected for adult meals, children’s meals and all meals.arrow_forward(the code should have the structure as in the second picture)arrow_forward(follow the template below when writing the program) Write a JAVA procedural program for an artist who is creating art instillation “experiences” consisting of rooms totally full of balloons that people will walk around in. Different instillations will be in different sized rooms and different sized balloons so need different numbers of balloons to fill them. The salesperson will enter the length, width and height of the room in centimetres. Write separate methods to input each of these values (they may possibly call other general methods) and return the results. These three numbers are multiplied together to get the volume of the room. This should by then be converted to m3 (calculated by dividing the volume by 1,000,000). This is then divided by the volume taken up by each balloon in m3 as given by the user. Print out the final number of balloons to be ordered along with the intermediate results as in the examples below. The final answer should be given as an integer (rounded down)…arrow_forward
- (Written in Java or Python) Write a program that allows a user to select 3 points on a graphics panel. Then, draw a triangle using these 3 points. Allow the user to specify a number of random points to be generated inside of the triangle. For each random point that is within the boundaries of the triangle draw a small dot at each of the points that are halfway between the randomly generated point and each vertex of the triangle. Do not draw the randomly generated point. Allow the user to repeat the process without removing the old dots. Allow the user to clear the screen.arrow_forward(Area and perimeter of a rectangle) Write a program that displays the area and perimeterof a rectangle with a width of 5.3 and height of 8.6 using the following formula:area = width X heightperimeter = 2 X (width + height)arrow_forward(In Java) Mathletes Game! With the introduction of loops, we now know enough about programming to begincreating simple games. Our first game (sponsored by the KSU College of Science and Mathematics)will test your ability to solve multiplication problems.Your game will first ask the player if they want to play on easy or hard mode. Save their response inan appropriate variable (you will reference it later). Then, you will randomly generate two numbersand display them to the player in the form of a multiplication problem. The possible numbers willrange between -255 and 255.You will ask the player to solve the equation. You will keep creating multiplication questions until theplayer wins or loses.Based on whether the player chose “hard” or “easy” mode, the game will play a little differently.Refer to the following rules for the difference:Easy Mode Hard ModePlayer only has to answer 5 questions Player has to answer 10 questionsPlayer can try again if they get a question wrong(up to two…arrow_forward
- How would I write this program in Java?arrow_forwardJava code pleasearrow_forward(Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is n x s? Area 4 X tan Here, s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area. Here is a sample run:arrow_forward
- (Convert decimals to fractions)Write a program that prompts the user to enter a decimal number and displays the number in a fraction.Hint: read the decimal number as a string, extract the integer part and fractional part from the string, and use the Rational class in LiveExample 13.13 to obtain a rational number for the decimal number. Use the template athttps://liveexample.pearsoncmg.com/test/Exercise13_19.txt The problem can not use BigInteger //Below is the Rational LiveExample 13.13 that goes with the problem/question; notice "long" instead of "BigInteger" class Rational extends Number implements Comparable<Rational> { // Data fields for numerator and denominator private long numerator = 0; private long denominator = 1; /** Construct a rational with default properties */ public Rational() { this(0, 1); } /** Construct a rational with specified numerator and denominator */ public Rational(long numerator, long denominator) { long gcd = gcd(numerator,…arrow_forward(YOU ARE NOT ALLOWED TO USE ARRAYLIST IN THIS PROJECT)Write a Java program to simulate a blackjack game of cards. The computer will play the role of the dealer. The program will randomly generate the cards dealt to the player and dealer during the game. Cards in this game will be represented by numbers 1 to 13 with Ace being represented by a 1. Remember, that face cards (i.e. Jack, Queen, and King) are worth 10 points to a hand while an Ace can be worth 1 or 11 points depending on the user’s choice. The numbered cards are worth their number value to the hand.arrow_forwardPlease review the image below. Produce the program in C++. Upload screenshots of Code and Output, as well as the source code. 6arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning