Starting from:

$29.99

CS1331 Solution


Programming Exercise 01 - Basic Java
Problem Description
This assignment will test your basic knowledge of variables, assignment, expressions, and code comments.
Solution Description
Fahrenheit to Celsius/Kelvin Conversion
1. Create a class called Temperature.
2. Add a main method to this class.
3. In the main method do the following:
a. Declare a variable called fahrenheit and assign the value 450.0 to it. This variable should be the smaller of the two primitive types that can hold floating point numbers.
b. Declare a variable called celsius. This variable should be the larger of the two primitive types that can hold floating point numbers. On the same line as the declaration, calculate the equivalent Celsius temperature based on the fahrenheit variable. The formula for this is: Celsius Value = (Fahrenheit Value – 32) / 1.8.
c. Declare a variable called kelvin. This variable should be the larger of the two primitive types that can hold floating point numbers. For now, assign the value of celsius to the kelvin variable.
d. Using a Compound Assignment Operator, (e.g. *=), calculate the equivalent Kelvin temperature based on the Celsius temperature stored in the kelvin variable. The formula for this is: Kelvin Value = Celsius Value + 273.15.
e. Print out to the console each of the variable values, each on a new line in this order:
{fahrenheit value}
{celsius value}
{kelvin value}
f. For the specified values, your output should be:
450.0
232.22222222222223
505.3722222222222
4. Leave a comment on the line after your last print statement about what you’re excited for this semester!
Submitting
To submit, upload the files listed below to the corresponding assignment on Gradescope:
• Temperature.java
Import Restrictions
Feature Restrictions
There are a few features and methods in Java that overly simplify the concepts we are trying to teach or break our autograder. For that reason, do not use any of the following in your final submission:
• var (the reserved keyword)
• System.exit
Collaboration
No collaboration is allowed on this assignment. See syllabus for more details.
Important Notes (Don't Skip)
• Non-compiling files will receive a 0 for all associated rubric items
• Do not submit .class files
• Test your code in addition to the basic checks on Gradescope
• Submit every file each time you resubmit
• Read the "Allowed Imports" and "Restricted Features" to avoid losing points • Check on Piazza for all official clarifications


More products