Question: There are only two buttons inside an elevator in a building with 50 floors. The elevator goes 11 floors up if the first button is

There are only two buttons inside an elevator in a building with 50 floors. The elevator goes 11 floors up if the first button is pressed and 6 floors down if the second button is pressed. Write a Java program to decide if it is possible to get from floor 32 to floor 33. You must show clearly how you compute the result in your program. Add comments if necessary. Extra credit problems (Optional): If it is possible, how many times do you need to press the button(s) in order to get to floor 33 from floor 32? Write a Java program to output the minimal number of button-pressing required. What to program: The skeleton of the program is given to you in Elevator.java. Finish the program by yourself. What to submit: Elevator.java. that contains finished program.

import java.util.*; public class Elevator { // Finish this function by yourself // Return true if it is possible to move the elevator from floor 32 to 33. // Return false if otherwise static boolean IsPossible(){ return false; } // Extra credit problem (optional) // Return at least how many time do you need to press the button(s) in order to get from floor 32 to floor 33. // Return -1 if you find it is impossible to get from floor 32 to floor 33. int MinimalNumButtonPressing(){ return -1; } public static void main(String[] args) { //Test your function here. System.out.print("Is it possible to move the elevator from floor 32 to 33?"); if( IsPossible() ){ System.out.print("Yes! Here I come floor 33! : )"); }else{ System.out.print("No. I'm stuck in floor 32 I guess. :("); } } } 

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!