Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA* I need to clean and add onto the code a little more (preferrably with meth

ID: 3582959 • Letter: J

Question

JAVA* I need to clean and add onto the code a little more (preferrably with methods used). Any help would be great! il be sure to leave good feedback thanks.

________________________

import java.util.Scanner;

public class Adventure1 {

   public static void showMessage() {
       System.out.println("Enter a valid input, Please try again.");
   }

   @SuppressWarnings("resource")
   public static String getInput(){
       return new Scanner(System.in).next();
   }
   public static void main(String[] args) {

       String Go, Look, Side, TV;

       System.out.println("Welcome to Creepy House");

       System.out.println(" ");

       int pointCounter = 0;

       while (true) {

           System.out
                   .println(" You have encountered the creepy house and you're eager to see what's inside! You're goal is to get in and collect valuable items before being caught by the owner. Would you like to go inside through the 'front' or sneak in through the 'side-door'? ");

           System.out.print("> ");

           Go = getInput();

           if (Go.equalsIgnoreCase("front")) {

               System.out
                       .println("There is a big room with only a TV and a couch. Do you want to sit and watch 'TV' or go 'upstairs'? ");

               System.out.print("> ");

               Look = getInput();

               if (Look.equalsIgnoreCase("TV")) {

                   System.out
                           .println("Would you like to turn the TV on? 'Yes' or 'No'?");

                   System.out.print("> ");

                   TV = getInput();

                   if (TV.equalsIgnoreCase("No")) {

                       System.out.println(" ");

                       System.out
                               .println("Good choice! No one suspects you're here. You can keep exploring the house, but be sure to be quiet");

                       pointCounter++;

                       if (pointCounter == 2)

                       {

                           System.out
                                   .println("You scored enough points to leave on your own accord. You win!! Congratulations!");

                           System.exit(0);

                       }

                       else {

                           System.out
                                   .println("You've been spotted! Next time don't go through the front door.");

                       }

                   } else if (TV.equalsIgnoreCase("Yes")) {

                       System.out.println(" ");

                       System.out
                               .println("You turned the TV on a little too loud! You've alerted the owner that someone snuck into the house. Run!");

                       System.out.println(" ");

                       System.out.println("Game over please start again.");

                       System.exit(0);

                   } else {

                   }

               } else if (Look.equalsIgnoreCase("upstairs")) {

                   System.out
                           .println("You have found the killer's room. Do you want to 'proceed', or 'run'?");

                   System.out.print("> ");

                   Side = getInput();

                   if (Side.equalsIgnoreCase("proceed")) {

                       System.out.println(" ");

                       System.out
                               .println("You walked right into a trap. Game over");

                       System.exit(0);

                   } else if (Side.equalsIgnoreCase("run")) {

                       System.out.println(" ");

                       System.out
                               .println("You've found a window to jump out, make sure you take something valuable first!");

                       pointCounter++;

                       if (pointCounter == 2)
                       {

                           System.out
                                   .println("You scored enough points to leave on your own accord. You win!! Congratulations!");

                           System.exit(0);

                       }

                   } else {
                       showMessage();
                   }

               } else {

                   showMessage();
               }

           } else if (Go.equalsIgnoreCase("side-door")) {

               pointCounter++;

               System.out
                       .println("House is cluttered. Would you like to go to the 'bedroom' or 'playroom'. ");

               System.out.print("> ");

               Look = getInput();

               if (Look.equalsIgnoreCase("bedroom")) {

                   System.out
                           .println("You look tired, Would you like to take a nap 'Yes' or 'No'?");

                   System.out.print("> ");

                   String bedroom = getInput();

                   if (bedroom.equalsIgnoreCase("yes")) {

                       System.out.println(" ");

                       System.out.println("Sweet Dreams! You lose!");

                       System.exit(0);

                   } else if (bedroom.equalsIgnoreCase("No")) {

                       System.out.println(" ");

                       System.out
                               .println("Move toward the closed door. If you open it, there will either be money or someone who isn't very happy you're in their house");

                       pointCounter++;

                       if (pointCounter == 2)

                       {

                           System.out
                                   .println("You scored enough points to leave on your own accord.You win!! Congratulations!");

                           System.exit(0);

                       }

                       else {

                           System.out
                                   .println("You've angered the killer. You lose!");

                       }

                   } else {

                       showMessage();

                   }

               } else if (Look.equalsIgnoreCase("playroom")) {

                   System.out
                           .println("There is an xbox inside. Do you want to 'play', or 'take' what's valuable and leave?");

                   System.out.print("> ");

                   String playroom = getInput();

                   if (playroom.equalsIgnoreCase("play")) {

                       System.out.println(" ");

                       System.out
                               .println("The owner is happy you like xbox and wants to play");

                       pointCounter++;

                       if (pointCounter == 2)

                       {

                           System.out
                                   .println("You scored enough points to leave on your own accord.You win!! Congratulations!");

                           System.exit(0);

                       }

                   } else if (playroom.equalsIgnoreCase("take")) {

                       System.out.println(" ");

                       System.out
                               .println("You escaped with some important items! Good job!");

                       pointCounter++;

                       if (pointCounter == 2)

                       {

                           System.out
                                   .println("You scored enough points to leave on your own accord.You win!! Congratulations!");

                           System.exit(0);

                       }

                   } else {

                       showMessage();

                   }

               } else {
                   showMessage();
               }

           } else {

               showMessage();

           }

       }

   }

}

Explanation / Answer

//Break into two classess

//first class

package com.general;

import java.util.Scanner;

public class Adventure {


   public static void main(String[] args) {
       AdventureProcessing adventureProcessing=new AdventureProcessing();
       adventureProcessing.doAdventure();

   }

}


//...........................................................................second class.......................

package com.general;

import java.util.Scanner;

public class AdventureProcessing {
   String Go, Look, Side, TV;
  
   public static void showMessage() {
           System.out.println("Enter a valid input, Please try again.");
       }

       @SuppressWarnings("resource")
       public static String getInput(){
           return new Scanner(System.in).next();
       }
     
   public void doAdventure(){
      

           System.out.println("Welcome to Creepy House");

           System.out.println(" ");

           int pointCounter = 0;

           while (true) {

               System.out
                       .println(" You have encountered the creepy house and you're eager to see what's inside! You're goal is to get in and collect valuable items before being caught by the owner. Would you like to go inside through the 'front' or sneak in through the 'side-door'? ");

               System.out.print("> ");

              // Go = getInput();
               setGo(getInput());

               if (getGo().equalsIgnoreCase("front")) {

                   System.out
                           .println("There is a big room with only a TV and a couch. Do you want to sit and watch 'TV' or go 'upstairs'? ");

                   System.out.print("> ");

                  // Look = getInput();
                   setLook(getInput());
                   if (getLook().equalsIgnoreCase("TV")) {

                       System.out
                               .println("Would you like to turn the TV on? 'Yes' or 'No'?");

                       System.out.print("> ");

            
                       setTV(getInput());
                       if (getTV().equalsIgnoreCase("No")) {

                           pointCounter=playRoomPointCounter(pointCounter,"Good choice! No one suspects you're here. You can keep exploring the house, but be sure to be quiet");

                           if (pointCounter == 2)

                           {

                               System.out
                                       .println("You scored enough points to leave on your own accord. You win!! Congratulations!");

                               System.exit(0);

                           }

                           else {

                               System.out
                                       .println("You've been spotted! Next time don't go through the front door.");

                           }

                       } else if (getTV().equalsIgnoreCase("Yes")) {

                           System.out.println(" ");

                           System.out
                                   .println("You turned the TV on a little too loud! You've alerted the owner that someone snuck into the house. Run!");

                           System.out.println(" ");

                           System.out.println("Game over please start again.");

                           System.exit(0);

                       } else {

                       }

                   } else if (getLook().equalsIgnoreCase("upstairs")) {

                       System.out
                               .println("You have found the killer's room. Do you want to 'proceed', or 'run'?");

                       System.out.print("> ");

                       setSide(getInput());
                       if (getSide().equalsIgnoreCase("proceed")) {

                           System.out.println(" ");

                           System.out
                                   .println("You walked right into a trap. Game over");

                           System.exit(0);

                       } else if (getSide().equalsIgnoreCase("run")) {

                           pointCounter=playRoomPointCounter(pointCounter,"You've found a window to jump out, make sure you take something valuable first!");

                           if (pointCounter == 2)
                           {

                               System.out
                                       .println("You scored enough points to leave on your own accord. You win!! Congratulations!");

                               System.exit(0);

                           }

                       } else {
                           showMessage();
                       }

                   } else {

                       showMessage();
                   }

               } else if (getGo().equalsIgnoreCase("side-door")) {

               pointCounter=playRoomPointCounter(pointCounter,"House is cluttered. Would you like to go to the 'bedroom' or 'playroom'. ");

                   System.out.print("> ");

                   setLook(getInput());
                   if (getLook().equalsIgnoreCase("bedroom")) {

                       System.out
                               .println("You look tired, Would you like to take a nap 'Yes' or 'No'?");

                       System.out.print("> ");

                       String bedroom = getInput();

                       if (bedroom.equalsIgnoreCase("yes")) {

                           System.out.println(" ");

                           System.out.println("Sweet Dreams! You lose!");

                           System.exit(0);

                       } else if (bedroom.equalsIgnoreCase("No")) {
                     
                           pointCounter=playRoomPointCounter(pointCounter,"Move toward the closed door. If you open it, there will either be money or someone who isn't very happy you're in their house");

                           if (pointCounter == 2)

                           {

                               System.out
                                       .println("You scored enough points to leave on your own accord.You win!! Congratulations!");

                               System.exit(0);

                           }

                           else {

                               System.out
                                       .println("You've angered the killer. You lose!");

                           }

                       } else {

                           showMessage();

                       }

                   } else if (getLook().equalsIgnoreCase("playroom")) {

                       System.out
                               .println("There is an xbox inside. Do you want to 'play', or 'take' what's valuable and leave?");

                       System.out.print("> ");

                       String playroom = getInput();

                       if (playroom.equalsIgnoreCase("play")) {

                           pointCounter=playRoomPointCounter(pointCounter,"The owner is happy you like xbox and wants to play");

                           if (pointCounter == 2)

                           {

                               System.out
                                       .println("You scored enough points to leave on your own accord.You win!! Congratulations!");

                               System.exit(0);

                           }

                       } else if (playroom.equalsIgnoreCase("take")) {

                           pointCounter=playRoomPointCounter(pointCounter,"You escaped with some important items! Good job!");

                           if (pointCounter == 2)

                           {

                               System.out
                                       .println("You scored enough points to leave on your own accord.You win!! Congratulations!");

                               System.exit(0);

                           }

                       } else {

                           showMessage();

                       }

                   } else {
                       showMessage();
                   }

               } else {

                   showMessage();

               }

           }
   }
  
   public int playRoomPointCounter(int pointCounter,String msg){
       System.out.println(" "+msg);
         pointCounter++;
         return pointCounter;
   }

   public String getGo() {
       return Go;
   }

   public void setGo(String go) {
       Go = go;
   }

   public String getLook() {
       return Look;
   }

   public void setLook(String look) {
       Look = look;
   }

   public String getSide() {
       return Side;
   }

   public void setSide(String side) {
       Side = side;
   }

   public String getTV() {
       return TV;
   }

   public void setTV(String tV) {
       TV = tV;
   }
  
  
}