Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

add logical operators to your Else Ifs. Logical And (&&), Logical Or (||) and Logical Not (!) SCENARIO 1 import java.util.Scanner; public class Main {

add logical operators to your Else Ifs. Logical And (&&), Logical Or (||) and Logical Not (!)

SCENARIO 1

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println(" You are on an island surrounded by water. There is a path to the woods to the north, the sea to the south, and a beach shack to the east. Which way do you want to go (n,e,s,w)?"); String command = scan.nextLine(); if (command.equals("n")) { System.out.println("You enter the forest and hear some rustling. There may be tigers here or maybe it's just monkeys."); } else if (command.equals("s")) { System.out.println("You take a dip in the sea and feel something approaching. It maybe a shark or some curious dolphins"); } else if (command.equals("e")) { System.out.println("You enter the beach shack and run into a surprise. You get everything for free for the next one hour."); } else { System.out.println("You cant go in that direction."); } System.out.println("End of adventure!"); scan.close(); } }

SCENARIO 2

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println(" You are in a research facility surrounded by machines. There is a cycle to your front, a car to your left and a treadmill to your right. Which way do you want to go (f, l, r, b)?"); String command = scan.nextLine(); if (command.equals("f")) { System.out.println("You climb on the bike. Everything freezes in time. Ring your bicycle bell to unfreeze"); } else if (command.equals("l")) { System.out.println("You take the drivers seat and change the gear. You go forward in time. Use the reverse gear to go back"); } else if (command.equals("r")) { System.out.println("You run on the treadmill and everything becomes slower. Or is it you that became faster??"); } else { System.out.println("You cant go in that direction."); } System.out.println("End of adventure!"); scan.close(); } }

SCENARIO 3

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println(" You are in a city and have to get to your destination in time. You can catch a bus station in 5 minutes, hire a taxi in 10 minutes and catch a train in 15 minutes. Which one do you choose (b, t, r)?"); String command = scan.nextLine(); if (command.equals("b")) { System.out.println("You get the bus on time. You meet a friend and have a good time till you reach the destination"); } else if (command.equals("t")) { System.out.println("You take the taxi and reach the destination 15 minutes early."); } else if (command.equals("r")) { System.out.println("You get the train and reach the destination on time."); } else { System.out.println("You cant select that transport."); } System.out.println("End of adventure!"); scan.close(); } }

SCENARIO 4

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println(" You are in a tourist destination and exploring adventure sports. You have three options to choose from : 1) Bungee Jumping 2) Dirt biking 3) Scuba diving. Which one do you choose (1, 2, 3)?"); String command = scan.nextLine(); if (command.equals("1")) { System.out.println("You conquer your fears and jump from the height. You are not afraid of heights anymore"); } else if (command.equals("2")) { System.out.println("You take the bike and go around the track. Let yourself free and enjoy the moment."); } else if (command.equals("3")) { System.out.println("You dive into the deep waters. Capture the unseen world with your eyes"); } else { System.out.println("You cant select that sport."); } System.out.println("End of adventure!"); scan.close(); } }

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago