Question: Modify the following Java code so the code inside main goes outside. Add getters/setters and other methods inside main. The code should do the same

Modify the following Java code so the code inside main goes outside. Add getters/setters and other methods inside main. The code should do the same thing and display the same result.

Change the following Java code so it does the same thing (add getters/setters and methods) inside the main and move the code from inside main, outside:

Move all the code from inside main outside and write methods (getters/setters) inside main:

import java.util.*; import java.io.*; public class GuessingGame1{ public static void main(String[] args){ int low = 1; int high = 100; if(args.length == 2){ low = Integer.parseInt(args[0]); high = Integer.parseInt(args[1]); } int counter = 1; Scanner scan = new Scanner(System.in); int secret = (int)(Math.random()*(high-low+1) + low); System.out.println("Enter a number(" +low+"-"+high+")"); int guess = scan.nextInt(); while(guess!=secret){ counter++; if(guess > high || guess < low){ System.out.println("Out of Range!!! Try again("+low+"-"+high+")"); guess = scan.nextInt(); continue; } if(guesssecret){ if(guess-20 > secret){ System.out.println("Way Too high"); }else{ System.out.println("Too high"); } } System.out.println("Try again("+low+"-"+high+")"); guess = scan.nextInt(); } System.out.println("You WON!!!"); System.out.println("It took you " +counter+ " guesses."); String line = ""; int fromFile = 0; try{ BufferedReader br = new BufferedReader( new FileReader(new File("output.txt"))); while((line = br.readLine())!=null){ //System.out.println(line); fromFile = Integer.parseInt(line); } br.close(); System.out.println("From file: " + fromFile); }catch(FileNotFoundException fnfe){ System.out.println(fnfe.getMessage()); }catch(IOException ioe){ System.out.println(ioe.getMessage()); } if(counter                        

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!