temp

import java.util.*; /** * Should convert Cel. to Far and vice versa. * * @triiiton * @2.0 Sept 08 2017 */ public class CeltoFar { // instance variables - replace the example below with your own int temp; String type; Scanner in = new Scanner(System.in); double answer; boolean runAgain=true; /** * Constructor for objects of class CeltoFar */ public CeltoFar() { while(runAgain==true){ askUserForInput(); convertTemp(); runAgain(); } } public void askUserForInput(){ System.out.println("Enter a Temperature: "); temp=in.nextInt(); System.out.println("Is this temerature Celsius or Far (C or F): "); type=in.next(); } public void convertTemp(){ if(type.equalsIgnoreCase("c")){ //convert from c to F //T(°F) = T(°C) × 1.8 + 32 answer= temp *1.8+32; System.out.println("You entered: "+temp +"C"); System.out.println("This equals "+answer +"F"); }else{ //(°F - 32) x 5/9 = °C answer= (temp-32) *0.55; System.out.println("You entered: "+temp +"F"); System.out.println("This equals "+answer +"C"); } } public void runAgain(){ //Play again code System.out.println("To continue type 1 else type 2"); int cont = in.nextInt(); if(cont!=1) runAgain=false; } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.