Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, this is a project where we are supposed make a choose-your-own path story. I was wondering if this code can be shortened in any

Hi, this is a project where we are supposed make a choose-your-own path story. I was wondering if this code can be shortened in any way. For example, I use (console.next()).equalsIgnoreCase("yes") repeatedly; is there a different, shorter way to write that? Thanks!

import java.util.Scanner;

public class DayOfADog{ public static void main (String[] args){ Scanner console = new Scanner(System.in);

System.out.println("It is a nice summer morning, and you just woke up in your dog bed. The house is silent since your owner has already left for work. You sit in peace, contemplating about what to do for the day."); System.out.println("Should you get out of bed?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You stretch your legs and paw your way off your bed and into the kitchen."); System.out.println("Now that you're in the kitchen, do you want to eat?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You munch on a bowl of kibble."); System.out.println("Now that you've eaten to fill your tummy, you feel a bit parched. Take a drink of water?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You lap on some water until your thirst is quenched."); System.out.println("Do you want to go outside?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println(""); } else{ System.out.println("You don't want to go outside, so you go back to the living room."); System.out.println("You see a pile of toys. Do you want to play?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start looking at your toy options."); System.out.println("Do you want to play with the squeaky toy?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start chewing a squeaky, happily entertained with the noise."); System.out.println("You feel your full bladder from the night before."); System.out.println("Since you're too far from outside, should you pee on the carpet?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("Almost out of your control, a liquid puddle appeads below your paws."); System.out.println("Realizing what hs occured, should you feel guilt?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start feeling guilty for the mess you've made. You sit there for the rest of the day, contemplating about your actions."); System.out.println("You stay there until your owner comes home and you can hear their shock and disappointment."); System.out.println("Sadly, you go back to your bed and sleep alone."); } else{ System.out.println("Hoping your owner doesn't notice, you proceed playing with your toy."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You're too good of a puppy to pee on the carpet. Instead, you take a quick trip outside and then come back in to play with your toys."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You aren't really feeling the squeaky today, so you go for the plastic bone."); System.out.println("You feel your bladder full from the night before."); System.out.println("Since you're too far from outside, should you pee on the carpet?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("Almost out of your control, a liquid puddle appeads below your paws."); System.out.println("Realizing what hs occured, should you feel guilt?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start feeling guilty for the mess you've made. You sit there for the rest of the day, contemplating about your actions."); System.out.println("You stay there until your owner comes home and you can hear their shock and disappointment."); System.out.println("Sadly, you go back to your bed and sleep alone."); } else{ System.out.println("Hoping your owner doesn't notice, you proceed playing with your toy."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You're too good of a puppy to pee on the carpet. Instead, you take a quick trip outside and then come back in to play with your toys."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } } } } else{ System.out.println("You ignore the water and trod your way back in to the living room."); System.out.println("You see a pile of toys. Do you want to play?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start looking at your toy options."); System.out.println("Do you want to play with the squeaky toy?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start chewing a squeaky, happily entertained with the noise."); System.out.println("You feel your full bladder from the night before."); System.out.println("Since you're too far from outside, should you pee on the carpet?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("Almost out of your control, a liquid puddle appeads below your paws."); System.out.println("Realizing what hs occured, should you feel guilt?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start feeling guilty for the mess you've made. You sit there for the rest of the day, contemplating about your actions."); System.out.println("You stay there until your owner comes home and you can hear their shock and disappointment."); System.out.println("Sadly, you go back to your bed and sleep alone."); } else{ System.out.println("Hoping your owner doesn't notice, you proceed playing with your toy."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You're too good of a puppy to pee on the carpet. Instead, you take a quick trip outside and then come back in to play with your toys."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You aren't really feeling the squeaky today, so you go for the plastic bone."); System.out.println("You feel your bladder full from the night before."); System.out.println("Since you're too far from outside, should you pee on the carpet?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("Almost out of your control, a liquid puddle appeads below your paws."); System.out.println("Realizing what hs occured, should you feel guilt?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start feeling guilty for the mess you've made. You sit there for the rest of the day, contemplating about your actions."); System.out.println("You stay there until your owner comes home and you can hear their shock and disappointment."); System.out.println("Sadly, you go back to your bed and sleep alone."); } else{ System.out.println("Hoping your owner doesn't notice, you proceed playing with your toy."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You're too good of a puppy to pee on the carpet. Instead, you take a quick trip outside and then come back in to play with your toys."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } } } } else{ System.out.println("You aren't feeling very hungry, so you trod your way back in to the living room."); System.out.println("You see a pile of toys. Do you want to play?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start looking at your toy options."); System.out.println("Do you want to play with the squeaky toy?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start chewing a squeaky, happily entertained with the noise."); System.out.println("You feel your full bladder from the night before."); System.out.println("Since you're too far from outside, should you pee on the carpet?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("Almost out of your control, a liquid puddle appeads below your paws."); System.out.println("Realizing what hs occured, should you feel guilt?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start feeling guilty for the mess you've made. You sit there for the rest of the day, contemplating about your actions."); System.out.println("You stay there until your owner comes home and you can hear their shock and disappointment."); System.out.println("Sadly, you go back to your bed and sleep alone."); } else{ System.out.println("Hoping your owner doesn't notice, you proceed playing with your toy."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You're too good of a puppy to pee on the carpet. Instead, you take a quick trip outside and then come back in to play with your toys."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You aren't really feeling the squeaky today, so you go for the plastic bone."); System.out.println("You feel your bladder full from the night before."); System.out.println("Since you're too far from outside, should you pee on the carpet?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("Almost out of your control, a liquid puddle appeads below your paws."); System.out.println("Realizing what hs occured, should you feel guilt?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You start feeling guilty for the mess you've made. You sit there for the rest of the day, contemplating about your actions."); System.out.println("You stay there until your owner comes home and you can hear their shock and disappointment."); System.out.println("Sadly, you go back to your bed and sleep alone."); } else{ System.out.println("Hoping your owner doesn't notice, you proceed playing with your toy."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } else{ System.out.println("You're too good of a puppy to pee on the carpet. Instead, you take a quick trip outside and then come back in to play with your toys."); System.out.println("You're feeling a bit tired. Do you want to wait for your owner to come home?"); if ((console.next()).equalsIgnoreCase("yes")){ System.out.println("You wander around, occasionally eat and drink, waiting for your owner to arrive home."); System.out.println("Once you hear the garage door open, your ears perk up and you happily greet them. Later, you sleep soundly with them in their bed."); } else{ System.out.println("Not wanting to wait for your owner, you continue to play for a bit, until you feel tired and sleep alone in your bed."); } } } } } } else System.out.println("You're feeling extra tired today. So, you decide to stay in bed the whole day until your owner comes back home."); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Auditing a risk based approach to conducting a quality audit

Authors: Karla Johnstone, Audrey Gramling, Larry Rittenberg

9th edition

9781133939160, 1133939155, 1133939163, 978-1133939153

More Books

Students also viewed these Programming questions

Question

Describe visualization and how it can boost motivation.

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Explain the various techniques of Management Development.

Answered: 1 week ago