guess

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 guess; int count = 3; int newcount; int rnd = (int) (Math.random()*10+1); String type; Scanner in = new Scanner(System.in); double answer; boolean runAgain=true; public CeltoFar() { while(runAgain==true){ askUserForInput(); //convertTemp(); runAgain(); } } public void askUserForInput(){ while (count > 0){ System.out.println("This is the one and only guessing game"); System.out.println("Please guess a number between 1 and 10"); guess=in.nextInt(); //System.out.println("Is this temerature Celsius or Far (C or F): "); //type=in.next(); if (guess == rnd) System.out.println("Winner."); else{ System.out.println("Sorry, wrong."); count = count-1; System.out.println("You have this many tries left: " + count); } } } /**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.