INF231 Week 5 Final
Temperature Conversion
INF231 Week5 Final Project.
import java.util.Scanner;
public class FinalTemp{
public static void main(String[] args) {
System.out.println(“Hello Instructor Alkilani, this is the INF231 Final assignment for Joseph Kennedy”);
Scanner sc = new Scanner(System.in);
boolean repeat=true;
while (repeat)
{
try{
System.out.print(“nEnter temperature in Fahrenheit :”);
String input=sc.next();
int temperature=Integer.parseInt(input);
float celsius = new FinalTemp().toCelsius(temperature);
System.out.printf(“%d degree fahrenheit temperature is equal to “
+ “%.02f degree celsius. n”, temperature, celsius);
System.out.print(“Do you want to continue, enter (true/false):”);
repeat = sc.nextBoolean();
}catch(NumberFormatException ex){
System.out.println(“Error: Age should be numeric only. “
+ “The compiler threw an exception ” + ex );
}
}
}
public float toCelsius(int fahrenheit)
{
float celsius = (fahrenheit – 32) * 5/ 9; return celsius;
}
}
I started by creating the FinalProject and the FinalTemp class. I then imported java.util.Scanner. Then gave code to display Instructor Alkilani this is the Inf231 final for Joseph Kennedy. I then added code to create a scanner to ask for the user’s input and to read user input. When prompted the user enters the temperature in Fahrenheit. Next step was to add the formula for conversion and instructions of what to return after the user input. The temperature is then converted to Celsius and displayed along with the original temp. I added an exception to prevent unrecognizable input. I then added code for the program to repeat until it is told to stop by the user inputting -1.
Place an Order
Plagiarism Free!
Create an Account
Create an account at Top Tutor Online
- Allows you to track orders.
- Receive personal messages.
- Send messages to a tutor.
Post a Question/ Assignment
Post your specific assignment
- Tutors will be notified of your assignment.
- Review your question and include all the details.
- A payment Link will be sent to you.
Wait for your Answer!
Make payment and wait for your answer
- Make payment in accordance with the number of pages to be written.
- Wait for your Answer as a professional works on your paper.
- You will be notified when your Answer is ready.