Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Three Puget Sound area tech companies (Company A, Company B, Company C) have decided to hold an event to improve relations. Each company sends

Three Puget Sound area tech companies (Company A, Company B, Company C) have decided to hold an event to improve relations. E 

Three Puget Sound area tech companies (Company A, Company B, Company C) have decided to hold an event to improve relations. Each company sends one engineer and one manager to go on a hike. The three engineers and three managers hike for an hour and eventually reach a river which they need to cross. There is a small boat where at most two people can fit at a time. Any person can pilot the boat. There is one caveat: If a manager is in the presence of an engineer of a different company when that engineer's manager is not present, the manager will feel obligated to recruit the engineer to join their company. However, this would ruin the event's synergy. Let's model the rules of this problem so that a player could try to solve the puzzle without violating the laws of physics or ruining the event. Create a class called ManagersCrossing. Inside that class, create a method with the following signature: public static boolean isMoveokay (int boatBefore, int managerABefore, int VaNagerRRefore, int panagerCBefore, int engineerABetere, int engineerBBetere, int engineerCBefore, int boatafter, int managerAAfter, int managerBAfter, int managerCAfteR, int engineerAAfter, int engineerBAfter, int engineeRGAfter) The boat and each of the six people have their own "Before" position parameter variable which is 1 if the position is on the left (original) side of the river and 2 if it is on the right (desired) side before the move. In addition, the boat and each of the six people have their own "After" position parameter which is 1 if the player wants the next position to be on the left side and 2 if they want it to be on the right side. Only a few positions can change in one move! Inside the isMovokay method, you'll implement logic to check whether the After positions are compatible with the rules of the game compared with the Before positions. An overview of the logic follows. Note that at most one error message should be printed, and the order of the checks determines which error message to print. First, make sure that all parameter variables are 1 or 2. If not, print the following error message and return false: All positions must be 1 or 2! Second, make sure that the boat is changing position. If not, print the following error message and return false: The boat must move! Third, make sure that each person you're trying to move is on the same side as the boat. If not, print the following error message and return false: You may not move a person who is not with the boat! Fourth, make sure you're moving one or two people. If not, print the following error message and return false: You must move one or two people! Fifth, make sure that no manager would recruit anyone. There will be three separate checks, one for each manager A, B, and C, in that order. For each check, if a recruitment would happen, print the following error message, replacing X with A, B, or C as appropriate, and return false: Manager X would try to recruit someone! Finally, if none of the errors above occurred, check to see if the after positions solve the puzzle. If so, print: You solved the puzzle! If no errors occurred, you should return true to indicate that the move is okay. A tester program will test your code and provide helpful messages if there are problems!

Step by Step Solution

3.51 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

CODE package managerscrosing import javautilScanner public class ManagersCrosing static method isMoveOkay public static boolean isMoveOkayint boatBefore int managerABefore int managerBBefore int manag... 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

Applied Regression Analysis And Other Multivariable Methods

Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg

5th Edition

1285051084, 978-1285963754, 128596375X, 978-1285051086

More Books

Students also viewed these Accounting questions

Question

What is market segmentation?

Answered: 1 week ago