ConvertTemp

ConvertTemp - (or 'c') for Celsius: ");...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* @author: * Class: ITP 109 * Lab#: 4 * Date modified: 02/10/2010 * Program description: This program will ask the user to input a temperature and then enter a * a c or C for Celsius and f or F for Fahrenheit. Then, the program will display the temperature in * a readable format and convert it to the other type. It will also show an error message if * anything else other than f, F, c, or C is entered. */ import java.util.Scanner; i public class ConvertTemp { p public static void main(String[] args) { //declare all variables that will be used float temp = 0, convertedTemp = 0; String tempType; S Scanner keyboard = new Scanner(System.in); S //Getting inputs (degrees) from the user System.out.println ("Please enter the temperature in degrees (for example 29.6): "); temp = keyboard.nextFloat(); System.out.println ("Please enter an 'F' (or 'f') for Fahrenheit or 'C'
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (or 'c') for Celsius: "); tempType = keyboard.next(); t // Condition / if (tempType.equalsIgnoreCase("c")) { convertedTemp = (9 * (temp/5))+ 32; // To convert from Celsius to Fahrenheit System.out.println(temp + " degrees " + tempType + " = " + convertedTemp + " degrees Fahrenheit."); // Display the temperature and converted one } else if (tempType.equalsIgnoreCase("f")) { convertedTemp = 5*(temp - 32 / 9); // To convert from Fahrenheit to Celsius System.out.println(temp + " degrees " + tempType + " = " + convertedTemp + " degrees Celsius."); // Display the temperature and converted one } else { System.out.println ("Oops! you have entered the wrong letter, " + "please enter one of the required lettes after you run the program again. Sorry!"); } } } }...
View Full Document

Page1 / 2

ConvertTemp - (or 'c') for Celsius: ");...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online