Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction: Three Puget Sound tech companies decide that they want to have better relations and so arrange for two employees from each company (an engineer

Introduction: Three Puget Sound tech companies decide that they want to have better relations and so arrange for two employees from each company (an engineer and a manager) are going to go on a hike. All is going well until they come to a river that they have to cross in a boat. The boat can only hold two people at a time. Being functional adults, any of them can pilot the boat. However, there is a problem. Engineers are in short supply, and so if an engineer from one company is in the presence of a manager from a different company, without the engineers manager being present, the manager from the other company will try to recruit the engineer. This will ruin the good times. Can all six people make it to the other side without the good times being ruined?

The Problem: Similar to the Farmer Game that we talked about in Lecture 6, you are going to write the code to check to see if a proposed move from one side of the river to the next is a legal move. You will also check to see if a move has been made to win the game. That is, youll check to see if all hikers have made it to the other side of the river. Your program will be a class called ManagersCrossing. Inside youll create a method:

public static boolean isMoveOkay(int boatBefore, int managerABefore, int managerBBefore, int managerCBefore, int engineerABefore, int engineerBBefore, int engineerCBefore, int boatAfter, int managerAAfter, int managerBAfter, int managerCAfter, int engineerAAfter, int engineerBAfter, int engineerCAfter)

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! Note that unlike the Farmer Game, we have a variables for both the before and after states of the boat.

Inside the isMoveOkay method, youll 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 youre 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 youre 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!

6.Make sure you add at least two comments in your code to explain what you are doing.

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!

Notes:

A skeleton program is provided for you at our class page in Canvas. Anything that you print out must match exactly with what is called for in the above checks. You can add more methods than the one called for, but everything must be coordinated from inside the isMoveOkay method. So, if you write a separate method for each of the checks, that is fine. Just call them from the isMoveOkay method. This program is much longer than the first one, but most of it is repetitive coding. Creating separate methods to check each individual rule is encouraged. Your method will be very long if you include everything in one method. Commenting: Make sure you adequately comment your code.

Testing: You should adequately test your code in a main method before trying to use the testing program (available on Canvas). I would test each rule check separately with several inputs that generate true and false. To use the testing program, bring the testing program into the Java project where your program is (Import helps here). You should be able to run the testing program (it will call your program) to see if your program is working correctly.

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

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions