Project Overview Welcome to 2012!Ahem,I mean to the Kiva team! We are working on introducing robots into the Amazon Fulfillment Centers and have plans to one day even have them drive themselves! But...

1 answer below »
Project Overview Welcome to 2012!Ahem,I mean to the Kiva team! We are working on introducing robots into the Amazon Fulfillment Centers and have plans to one day even have them drive themselves! But let's not get ahead ofourselves...The Kiva robots are finished and they're incredible! They know how to move forward (F), turn left (L), turnright (R), take (T), and drop (D). What are they lifting and dropping? They are lifting and dropping pods filledwith products and carrying them between the pod's storage location and a drop zone, where the Kiva robotremains, and a Fulfillment Center employee removes products from the pod to pack an order. We have cre-ated a program that prints out a map showing where the robot currently is, where the pod to pick up is, andwhere it needs to be dropped off.We need you to program a Kiva Robot Remote Control! Right now we've programmed the Remote Control toprint out the map of the FC and then take in directions from the driver, but those directions aren't being sent tothe robot. We need you to interpret the directions and send them to the robot. Kiva Robots are incredibly ex-pensive to make so you need to make sure they won't drive into any walls or obstacles when you make amove.P.S. We found this incredible video from the future showing “A Day in the Life of a Kiva Robot,” after theylearned to drive themselves!https://www.youtube.com/watch?v=6KRjuuEVEZs.Before You Get StartedDownload and Open the Project1.If you do not have BlueJ installed on your computer, please download it from Dukehere. Downloadthe appropriate version based on your operating system directly from that website. Don't downloadBlueJ directly fromhttps://www.bluej.org/because the version there will miss critical dependenciesfrom Duke.2.Open theKivaWorld downloads folderin workdocs.3.Download theKivaWorld-##.zipfile (for example, KivaWorld-01.zip, but may have a different numberin place of the"##") that you see1.There should be aKivaWorld-##.zipfile that contains the starter code -- download this one now2.(There will also be a KivaWorldJavadoc-##.zip file that contains documentation about the exist-ing code -- more on this below in a "Documentation" section)4.Double-click on the .zip file to expand the project contents. Feel free to move the KivaWorld folder towherever you keep your projects on your computer.5.Double-click on KivaWorld/package.bluej. (Note that this is just another way of opening a BlueJ project--besides opening BlueJ first and using the Project menu to find the project)6.You should see theRemoteControlclass that you'll be implementing, and can now run the code!9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemote… 3/24How to Run and Test the ProjectNow that you've got the project open in BlueJ, let's run the code for the first time!Click “Compile” on the left side of the BlueJ project window:9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemote… 4/24Right click on theRemoteControlclass and select “new RemoteControl()” to create a newRemoteControlinstance:Choose a name for your new instance, for example, remoteControl, and hit OK.Right-click on the red instance in the lower portion of the BlueJ window and select “void run()” to exe-cuteRemoteControl's run instance method:9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemote… 5/24The console should appear and you will get aNullPointerExceptionat this point, which is expected.Don't worry, we'll get around to fixing that later! Now you're ready to get started!What is Already Present in the Project?TheRemoteControlclass is responsible for running the program, interacting with the user, and moving theKiva robot. We have provided you this class with some starter code in it. It contains logic to interact with theconsole by printing out the map of the floor, and taking in the string of directions from the user.In addition toRemoteControl, the project will utilize some code that has already been written by theWarehouse Team. The Warehouse Team had already written this code, so they've packaged it up for ourteam to use. You will not need to make changes to any of these classes, but we wanted to explain how thisworks so it doesn't seem like too much magic. These classes are tucked away inside a JAR (JavaARchive)9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemote… 6/24file inside KivaWorld/+libs/. A JAR file is a convenient way to bundle a bunch of related Java classes (oftencalled alibrary) into a single file that the JVM can access. (Optional: Here is agood intro on JARs, though alittle more information than you need right now.)Here's a quick summary of the classes and enumerations provided by the Warehouse Team:FloorMap: Represents a Kiva's environment, including pickup/dropoff points, obstacles and Kiva'sstarting location. It allows identifying what exists at any given location, as well as rendering the entiremap as a String for display.FacingDirection: Represents the direction a robot is facing. There are four orientations, and each in-cludes a “delta” point which moves the robot one space in that direction when added to the currentlocation.FloorMapObject: Represents what is located at any given location of the FloorMap.Optional: Taking a look inside the JARShowOptional: How to open a terminal and cd to the project directoryShowStarter Code Class DiagramIf you downloaded the project before 04/29/2021 and were trying to use theFloorMapmethodsget-PodLocation()andgetDropZoneLocation()but couldn't find them, you can update your project to getthose methods by...1.Downloading the latest version ofKivaWorldJavadoc-01.zipfromSharedCurriculum/KivaWorld, replacing the version of the javadoc you downloaded originally2.Downloading the latest version ofKivaWorld-01.zipfromShared Curriculum/KivaWorldand...1.UncompressingKivaWorld-01.zip.2.Replacing the fileKivaWorld/+lib/KivaWorld-1.0.jarin your copy of the project with thenew version.We created a class diagram to visualize the classes provided by the Warehouse Team and theRemoteControlclass.Actions:Pop Out|Edit|?DocumentationWe've also provided more complete documentation in the form of Javadocs, which are a collection of HTMLfiles that document classes and their methods.1.Open theKivaWorld downloads folderon Workdocs.2.Download the KivaWorldJavadoc-##.zip file with the highest version number (the version should matchthe version of the KivaWorld-##.zip file you downloaded, let us know if this is not the case).3.Double-click onindex.htmlto load the javadoc viewer in your browser.4.Refer to these pages throughout the project to see how the above classes behave.9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemote… 7/24You can view the Javadocs for the classes you're writing and editing (e.g. RemoteControl ) as you build them,via the Tools → Project Documentation menu in BlueJ (if it asks you if you want to regenerate documentation,click “Regenerate”).Sample Floor Map FilesWe have also provided you with three floor map files in the KivaWorld-##.zip that you downloaded. You canuse these for testing purposes.sample_floor_map1.txt - a simple map with walls, but no obstacles. The K, P, and D are all in a straightline.sample_floor_map2.txt - a map with walls and obstaclessample_floor_map3.txt - a map with walls and obstaclesProject GoalsYour goal is to complete all of the project tasks, which will result in RemoteControl interacting with the user inthe following way.Please select a map file.---------------| P *|| ** *|| ** *|| *K D *|---------------Current Kiva Robot location: (3,4)Facing: UPPlease enter the directions for the Kiva Robot to take.FFFRFFFFFFTFFRFFFDSuccessfully picked up the pod and dropped it off. Thank you!The user will not always provide a path that successfully picks up and drops off the pod. We will detail outthese error cases later and how to handle them, but as an example, here the path provided never picks upthe pod.Please select a map file.-------------|P *|--- -||*| *|K--- D -|* * * *|-------------|Current Kiva Robot location: (2,4)Facing: UPPlease enter the directions for the Kiva Robot to take.FLFFFFFF9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemote… 8/24I'm sorry. The Kiva Robot did not pick up the pod and then drop it off in the rightplace.End State Class DiagramThis diagram shows you what your project will look like once you have completed all of the project tasks. Takea look at the new class and enum that you will be responsible for implementing, Kiva and KivaCommand .RemoteControl will interact with both of these new classes, and your Kiva class will use the already definedclasses from the Warehouse Team. We will dive into more details in the implementation overview below.Actions: Pop Out | Edit | ?Implementation OverviewKivaCommand describes the “moves” a Kiva robot can make: turning left or right, moving forwards, taking apod, and dropping a pod. It also includes each move's one-letter abbreviation.Kiva holds the state and logic of a robot: where it is, which way it's facing, whether it's carrying a pod rightnow, and whether it has successfully dropped the pod. A Kiva always starts facing UP (one of our providedFacingDirections ), not carrying a pod, and not having successfully dropped the pod. The move() methodperforms the logic for any KivaCommand , and the isSuccessfulDrop() method indicates whether the previouscommand dropped the pod on the drop zone. We normally don't add getters to class diagrams, but this isthe first time you're encountering a common naming convention that ATA will follow: boolean getters often followthe pattern “ isFieldName() ” or “ hasFieldName() ”.When an impossible move is attempted, move() throws an exception. IllegalMoveException is appropriatefor attempts to move the robot off the warehouse floor or into an obstacle; NoPodException is expectedwhen there's an attempt to TAKE at a location without a POD ; and IllegalDropZoneException should occurwhen we try to drop a pod anywhere but a DROP_ZONE . These exceptions are provided to you by theWarehouse Team.Running the whole show is RemoteControl , initiated by executing its run() method. RemoteControl promptsthe user to select a text file containing a FloorMap to load, prompts the user to input a chain ofKivaCommand s using single-letter abbreviations, and then executes the KivaCommand s until Kiva dropsthe pod successfully into the drop zone (or encounters an error).Now you're ready to get started. We've broken out what you need to do to fully program the remote controlinto the project tasks below. Happy coding!Project Tasks1. Implement the KivaCommand Enum Before starting this task please refer back to the Enums Learning Material as a refresher.Kiva objects can perform actions such as moving around and picking and dropping items. We allow users in9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemote… 9/24our program to enter 1 letter representations of these moves ('F', 'R', 'L', 'T', or 'D'), so we need a way to mapeach action to a particular keyboard key.Referring to the class diagram above, you'll do this by creating a newKivaCommandenum for the actionsthat the robot can perform. The enum will use values that correspond to particular keyboard characters. Thatway theRemoteControlclass can map a char input key to aKivaCommandenum value.In order to create an enum in BlueJ, click the 'New Class...' button. Enter the name of your enum, leave theClass Language as Java, and then select 'Enum' from the options for Class Type. Click 'OK' to create yourenum.Test this by creating aKivaCommandTesterclass. Create one test method per command and test that whenyou run each method you get the expected output. Here is an exampleKivaCommandTesterclass with onemethod filled in:publicclassKivaCommandTester{publicvoidtestForward(){KivaCommand command=KivaCommand.FORWARD;System.out.println(command);System.out.println(command.getDirectionKey());}// For you: create four more methods, each testing a different command.}Test CasesTest:testForward()Input: Creates aKivaCommand.FORWARDobject, then prints the command and its direction keyOutput: “FORWARD” followed by “F” is printed out to the console.Test:testTurnLeft()Input: Creates aKivaCommand.TURN_LEFTobject, then prints the command and its direction keyOutput: “TURN_LEFT” followed by “L” is printed out to the console.Test:testTurnRight()Input: Creates aKivaCommand.TURN_RIGHTobject, then prints the command and its direction keyOutput: “TURN_RIGHT” followed by “R” is printed out to the console.Test:testTake()Input: Creates aKivaCommand.TAKEobject, then prints the command and its direction keyOutput: “TAKE” followed by “T” is printed out to the console.Test:testDrop()Input: Creates aKivaCommand.DROPobject, then prints the command and its direction keyOutput: “DROP” followed by “D” is printed out to the console.9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 10/242. Create theKivaClassRefer to theClass Diagrams learning materialsto refresh yourself on reading class diagrams. Next, we'll im-plement theKivaclass from theclass diagram above. This is a fairly large and complicated task, so we'llbreak it into smaller steps.Implement the Attributes, Getters, and ConstructorsWe will start by creating the class, adding its instance variables, and writing the getter methods and construc-tors. Note there are two constructors for this class, and you must implement both of them. One of them in-stantiates aKivaobject and sets the location of the Kiva robot from the providedFloorMap; the other instan-tiates aKivaobject and sets the location of the Kiva robot from aPoint(remember to importedu.duke.Point). Both constructors should initialize the state with the robot facing up, not carrying any pod,and not having successfully dropped a pod. IgnoremotorLifetimefor now; we'll cover that later. Rememberthe getters for booleans follow the naming convention described above,isSuccessfullyDropped()andisCar-ryingPod().Test theKivaconstructors by creating aKivaConstructorTestclass. First, we will create aFloorMapthat wecan pass to ourKivaconstructors. We can do this by using the providedFloorMap(String map)constructorand thedefaultLayoutStringin the example below. Create a test method for eachKivaconstructor, usingthe same testFloorMapfor each, and checking that the resulting Kiva robot location matches the input. (Wedon't write separate tests for “trivial” getters that contain no logic.) Here's the test for the constructor using asingle argument:importedu.duke.Point;publicclassKivaConstructorTest{String defaultLayout=""+"-------------\n"+" P *\n"+" ** *\n"+" ** *\n"+" K D *\n"+" * * * * * **\n"+"-------------\n";FloorMap defaultMap=newFloorMap(defaultLayout);publicvoidtestSingleArgumentConstructor(){// GIVEN// The default map we defined earlier// WHEN// We create a Kiva with the single-argument constructorKiva kiva=newKiva(defaultMap);// THEN// The initial Kiva location is (2, 4)9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 11/24Point initialLocation=kiva.getCurrentLocation();Point expectedLocation=newPoint(2,4);if(sameLocation(initialLocation,expectedLocation)){System.out.println("testSingleArgumentConstructor SUCCESS");}else{System.out.println(String.format("testSingleArgumentConstructor FAIL: %s != (2,4)!",initialLocation));}}privatebooleansameLocation(Point a,Point b){returna.getX()==b.getX()&&a.getY()==b.getY();}// For you: create a test for the constructor taking two arguments.}Test CasesTest:testSingleArgumentConstructor()Input: Pass the constructor the default map as the argument, then validate that the currentLocation of theKivais as expected.Output: “testSingleArgumentConstructor SUCCESS” is printed to the console.Test:testTwoArgumentConstructor()Input: Pass the constructor the default map and a location of (5, 6) as the arguments, then validate that thecurrentLocation of theKivais as expected.Output: “testTwoArgumentConstructor SUCCESS” is printed to the console.3. ImplementKiva's Move MethodMoving ForwardNext consider themove()method. Depending on theKivaCommandit receives,move()must update thecurrent location, the direction the robot is pointing, whether it is carrying a pod or if the pod has been success-fully dropped. This is a lot of logic; implementing a helper method for each command will make the code morereadable and easier to manage. For now ignore the motorLifetime field.Write a void helper method for theFORWARDcommand (a name such amoveForward()would be appro-priate, but you may use any name you like). Use only the simplest logic, without regard for obstacles, pods,drop zones, or whether the robot is actually carrying anything; simply assume that the command is valid andupdate the state accordingly. This command should update the current location. When the move method getsaKivaCommandthat is equal toFORWARDyou should call your new helper method.Testmove()by creating aKivaMoveTestclass. Create a test method for theFORWARDcommand and testthat after you issue the command,allof the getters return the expected values. Here's a free example,test-9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 12/24ForwardFromUp() , with a bonus helper method that validates the Kiva 's state. You can use it for your othertests.import edu.duke.Point;public class KivaMoveTest {// Define the FloorMap we'll use for all the testsString defaultLayout = ""+ "-------------\n"+ " P *\n"+ " ** *\n"+ " ** *\n"+ " K D *\n"+ " * * * * * **\n"+ "-------------\n";FloorMap defaultMap = new FloorMap(defaultLayout);public void testForwardFromUp() {// GIVEN// A Kiva built with the default map we defined earlierKiva kiva = new Kiva(defaultMap);// WHEN// We move one space forwardkiva.move(KivaCommand.FORWARD);// THEN// The Kiva has moved one space upverifyKivaState("testForwardFromUp",kiva, new Point(2, 3), FacingDirection.UP, false, false);}// For you: create all the other tests and call verifyKivaState() for eachprivate boolean sameLocation(Point a, Point b) {return a.getX() == b.getX() && a.getY() == b.getY();}private void verifyKivaState(String testName,Kiva actual,Point expectLocation,FacingDirection expectDirection,boolean expectCarry,boolean expectDropped) {Point actualLocation = actual.getCurrentLocation();if (sameLocation(actualLocation, expectLocation)) {System.out.println(String.format("%s: current location SUCCESS", testName));}else {System.out.println(String.format("%s: current location FAIL!", testName));System.out.println(String.format("Expected %s, got %s",expectLocation, actualLocation));}FacingDirection actualDirection = actual.getDirectionFacing();if (actualDirection == expectDirection) {System.out.println(String.format("%s: facing direction SUCCESS", testName));9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 13/24}else {System.out.println(String.format("%s: facing direction FAIL!", testName));System.out.println(String.format("Expected %s, got %s",expectDirection, actualDirection));}boolean actualCarry = actual.isCarryingPod();if (actualCarry == expectCarry) {System.out.println(String.format("%s: carrying pod SUCCESS", testName));}else {System.out.println(String.format("%s: carrying pod FAIL!", testName));System.out.println(String.format("Expected %s, got %s",expectCarry, actualCarry));}boolean actualDropped = actual.isSuccessfullyDropped();if (actualDropped == expectDropped) {System.out.println(String.format("%s: successfully dropped SUCCESS", testName));}else {System.out.println(String.format("%s: successfully dropped FAIL!", testName));System.out.println(String.format("Expected %s, got %s",expectDropped, actualDropped));}}}Moving Forward Test CasesTest: testForwardFromUp()Input: Create a Kiva object using the default map, and call move with the FORWARD command. Verify thestate of the Kiva object. Ensure the current location has changed.Output: The following is printed to the console:testForwardFromUp: current location SUCCESStestForwardFromUp: facing direction SUCCESStestForwardFromUp: carrying pod SUCCESStestForwardFromUp: successfully dropped SUCCESSTurning LeftContinue implementing and testing move() with the next command, TURN_LEFT . Once you have implementedits helper method, write tests for it in the KivaMoveTest class. Copy the existing test method to createone test for each possible case of the directionFacing point ( UP , DOWN , LEFT , and RIGHT ). Ensurethat each test verifies the Kiva 's state.Turning Left Test Cases9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 14/24Test:testTurnLeftFromUp()Input: Create aKivaobject using the default map, and call move with theTURN_LEFTcommand. Verifythe state of theKivaobject. Ensure the direction facing is nowLEFT.Output: The following is printed to the console:testTurnLeftFromUp: current location SUCCESStestTurnLeftFromUp: facing direction SUCCESStestTurnLeftFromUp: carrying pod SUCCESStestTurnLeftFromUp: successfully dropped SUCCESSTest:testTurnLeftFromLeft()Input: Create aKivaobject using the default map, and call move twice with theTURN_LEFTcommand.Verify the state of theKivaobject. Ensure the direction facing is nowDOWN.Output: The following is printed to the console:testTurnLeftFromLeft: current location SUCCESStestTurnLeftFromLeft: facing direction SUCCESStestTurnLeftFromLeft: carrying pod SUCCESStestTurnLeftFromLeft: successfully dropped SUCCESSTest:testTurnLeftFromDown()Input: Create aKivaobject using the default map, and call move three times with theTURN_LEFTcom-mand. Verify the state of theKivaobject. Ensure the direction facing is nowRIGHT.Output: The following is printed to the console:testTurnLeftFromDown: current location SUCCESStestTurnLeftFromDown: facing direction SUCCESStestTurnLeftFromDown: carrying pod SUCCESStestTurnLeftFromDown: successfully dropped SUCCESSTest:testTurnLeftFromRight()Input: Create aKivaobject using the default map, and call move four times with theTURN_LEFTcom-mand. Verify the state of theKivaobject. Ensure the direction facing is nowUP.Output: The following is printed to the console:testTurnLeftFromRight: current location SUCCESStestTurnLeftFromRight: facing direction SUCCESStestTurnLeftFromRight: carrying pod SUCCESStestTurnLeftFromRight: successfully dropped SUCCESSFood For Thought: We had to make a lot of if-then choices to determine which direction resulted from a leftturn. TheFacingDirectionenum is provided, and cannot be changed; if wecouldchange it, could we addfunctionality to know which direction was “left of” any other direction? Why would we want to?Updating Moving Forward Test CasesThe existing tests forFORWARDonly covers the case where the robot is facingUP. ImplementingTURN_LEFTallows us to check moving forward from any of four facing directions.Test the new starting conditions when executing theFORWARDcommand. Copy the test method forFORWARDand modify it to account for each possibility. Make each test independent: don't repeat a “turnand check” three times. Instead, write one test that constructs aKiva, turns left, moves forward, and checks9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 15/24all the state; then write a test that constructs aKiva, turns left twice, moves forward, and checks all the state;and so on.Test:testForwardWhileFacingLeft()Input: Create aKivaobject using the default map, and call move once toTURN_LEFT, and again to moveFORWARD. Verify the state of the Kiva object. Ensure the direction facing is nowLEFT, and thecurrentLo-cationhas updated to one space to the left.Output: The following is printed to the console:testForwardWhileFacingLeft: current location SUCCESStestForwardWhileFacingLeft: facing direction SUCCESStestForwardWhileFacingLeft: carrying pod SUCCESStestForwardWhileFacingLeft: successfully dropped SUCCESSTest:testForwardWhileFacingDown()Input: Create aKivaobject using the default map, and call move twice with theTURN_LEFTcommand,and again to moveFORWARD. Verify the state of theKivaobject. Ensure the direction facing is nowDOWN, and thecurrentLocationhas updated to one space below.Output: The following is printed to the console:testForwardWhileFacingDown: current location SUCCESStestForwardWhileFacingDown: facing direction SUCCESStestForwardWhileFacingDown: carrying pod SUCCESStestForwardWhileFacingDown: successfully dropped SUCCESSTest:testForwardWhileFacingRight()Input: Create aKivaobject using the default map, and call move three times with theTURN_LEFTcom-mand, and again to moveFORWARD. Verify the state of theKivaobject. Ensure the direction facing is nowRIGHT, and thecurrentLocationhas updated to one space to the right.Output: The following is printed to the console:testForwardWhileFacingRight: current location SUCCESStestForwardWhileFacingRight: facing direction SUCCESStestForwardWhileFacingRight: carrying pod SUCCESStestForwardWhileFacingRight: successfully dropped SUCCESSImplement Turning Right, Taking, and DroppingContinue implementing and testing move() one command at a time, updating the state variables as if thecommand always succeeds. As each command is implemented, add tests for it in theKivaMoveTestclass.Note that it is possible to check all combinations of outcomes for each command. For instance, you could testthatTAKEworks foreachdirection. The number of conditions is small enough to make this possible, butlarge enough to be extremely cumbersome. This happens in actual development, too.To reduce the burden, we will often examine the decisions that must be made and only write tests checkingeach condition that leads to a decision. For instance, since the code forTURN_LEFTmust make decisionsaccounting for the four possible conditions of thedirectionFacingfield, we should have four tests, one test foreach condition. (We should also have a test for the fifth condition, whendirectionFacingis null, but we'll learnhow to do that in a later unit.) On the other hand, theTAKElogic has no conditions, so we only need onetest.9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 16/24Turning Right, Taking, and Dropping Test CasesTest:testTurnRightFromUp()Input: Create aKivaobject using the default map, and callmove()with theTURN_RIGHTcommand.Verify the state of theKivaobject. Ensure the direction facing is nowRIGHT.Output: The following is printed to the console:testTurnRightFromUp: current location SUCCESStestTurnRightFromUp: facing direction SUCCESStestTurnRightFromUp: carrying pod SUCCESStestTurnRightFromUp: successfully dropped SUCCESSTest:testTurnRightFromLeft()Input: Create aKivaobject using the default map, and callmove()with theTURN_LEFTcommand fol-lowed by a call to move with theTURN_RIGHTcommand. Verify the state of theKivaobject. Ensure the di-rection facing is nowUP.Output: The following is printed to the console:testTurnRightFromLeft: current location SUCCESStestTurnRightFromLeft: facing direction SUCCESStestTurnRightFromLeft: carrying pod SUCCESStestTurnRightFromLeft: successfully dropped SUCCESSTest:testTurnRightFromDown()Input: Create aKivaobject using the default map, and callmove()with theTURN_LEFTcommand twicefollowed by a call to move with the TURN_RIGHT command. Verify the state of theKivaobject. Ensure thedirection facing is nowLEFT.Output: The following is printed to the console:testTurnRightFromDown: current location SUCCESStestTurnRightFromDown: facing direction SUCCESStestTurnRightFromDown: carrying pod SUCCESStestTurnRightFromDown: successfully dropped SUCCESSTest:testTurnRightFromRight()Input: Create aKivaobject using the default map, and callmovewith theTURN_LEFTcommand threetimes followed by a call to move with theTURN_RIGHTcommand. Verify the state of theKivaobject.Ensure the direction facing is nowDOWN.Output: The following is printed to the console:testTurnRightFromRight: current location SUCCESStestTurnRightFromRight: facing direction SUCCESStestTurnRightFromRight: carrying pod SUCCESStestTurnRightFromRight: successfully dropped SUCCESSTest:testTakeOnPod()Input: Create aKivaobject using the default map, and callmove()to go up three times, turn right, moveright six times, and take the pod. Verify the state of theKivaobject. Ensure that it is carrying the pod.Output: The following is printed to the console:testTakeOnPod: current location SUCCESStestTakeOnPod: facing direction SUCCESS9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 17/24testTakeOnPod: carrying pod SUCCESStestTakeOnPod: successfully dropped SUCCESSTest: testDropOnDropZone()Input: Create a Kiva object using the default map, and call move() to go up three times, turn right, moveright six times, take the pod, move to the drop zone, and drop the pod. Verify the state of the Kiva object.Ensure that it is not carrying the pod, and the drop was successful.Output: The following is printed to the console:testDropOnDropZone: current location SUCCESStestDropOnDropZone: facing direction SUCCESStestDropOnDropZone: carrying pod SUCCESStestDropOnDropZone: successfully dropped SUCCESSNow that we have tests that verify all the possible Kiva moves, we can improve our code and run these testswhenever we want to verify that we haven't broken anything.4. Handle Invalid MovesBefore starting this task please refer back to the Throwing Exceptions Learning Material as a refresher.We've been so preoccupied with whether or not we could that we didn't stop to think if we should. Let's improvethe move() method to detect error conditions. We'll modify our helper methods so that if the requestedmove isn't possible, we'll throw an IllegalMoveException . When attempting to take a pod on a space whereno pod exists, we'll throw a NoPodException . When attempting to drop at any space other than a drop zone,we'll throw an IllegalDropZoneException .We'll use the FloorMap 's getObjectAtLocation() , getMaxRowNum() , and getMaxColNum() methods tocheck whether the move is legal. Turning should always be legal, moving forward is only legal if the new locationis on the floor and there isn't anything blocking. Again, we'll break these into single steps and write testsas we go.Implement bounds checking in the helper method for moving forward. Before changing the current location,calculate where the new location would be if the move is successful. If the new location is less than 0 in anydimension, or greater than the corresponding dimension of the floor map, throw an IllegalMoveExceptionwith a message that describes the problem.Test your new functionality by writing a test method that deliberately moves the robot off the map. If your codeworks, it throws an IllegalMoveException , so the test won't be able to check Kiva 's state variables. Instead,we'll have to print an error message if the exception doesn't happen. An example is provided below:public void testMoveOutOfBounds() {Kiva kiva = new Kiva(defaultMap);kiva.move(KivaCommand.FORWARD);kiva.move(KivaCommand.TURN_LEFT);kiva.move(KivaCommand.FORWARD);kiva.move(KivaCommand.FORWARD);System.out.println("testMoveOutOfBounds: (expect an IllegalMoveException)");kiva.move(KivaCommand.FORWARD);// This only runs if no exception was thrownSystem.out.println("testMoveOutOfBounds FAIL!");9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 18/24System.out.println("Moved outside the FloorMap!");}Implement and test obstacle checking in the forward moving helper method. If the new location passes theon-floor check, call getObjectAtLocation() to determine what the robot would be moving into. If it's anOBSTACLE , throw an IllegalMoveException . Create a test that moves into an obstacle and prints a failuremessage if no exception is thrown.Implement and test pod collision checking in the forward moving helper method. If Kiva is carrying a pod,and the new location is also a POD , throw an IllegalMoveException . Create a test that moves into a podwhile carrying a pod and prints a failure message if no exception is thrown.Implement and test checking for presence of a pod in the TAKE helper method. If the TAKE command isissued while the current location is not a POD , throw a NoPodException . Create a test that tries to take apod on an empty space and prints a failure message if no exception is thrown.Food For Thought: It would also be impossible to pick up a pod if the robot were already carrying a pod. Isthere any way to reach this condition? Should we test for it?Implement and test existence checking in the pod drop helper method. If the current location is not a dropzone, throw an IllegalDropZoneException . Create a test that picks up a pod, drops it in an empty space, andprints a failure message if no exception is thrown.Implement and test futility checking in the pod drop helper method. If a DROP command is issued while thecurrent location is a drop zone, but the robot is not carrying a pod, throw an IllegalMoveException . Create atest that moves to a drop zone without a pod, drops on the drop zone, and prints a failure message if no exceptionis thrown.Food For Thought: Does it make any difference which order we implement the checks in the pod drop helper?Does having checks with different results mean our method now has to make decisions on multiple conditions?What should we test? Is NoPodException a better fit when attempting to DROP while not carrying apod?5. Make More Informative Error MessagesThings are working great, but we are getting feedback from our users that it's hard to tell what is going onwhen things fail. We already include a message in each exception; we need to include more data in the message.Examine each of your exception messages and update them with more information where appropriate.Let's consider the NoPodException . Our helper method for taking the pod might check whether it's on the appropriatespace like this:FloorMapObject terrain = map.getObjectAtLocation(currentLocation);if (terrain != FloorMapObject.POD) {throw new NoPodException("No pod here!");}We could improve this experience for our users with a better description, including the command we were executingand the location of the robot.9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 19/24if (terrain != FloorMapObject.POD) {throw new NoPodException("No pod to TAKE from location " +currentLocation + "!"));}While this will work, String.format() is more readable, more powerful, more efficient, and easier to modify ifwe want to make changes later. Read only the (short) Replace a Placeholder in a String section from Howto Format a String, Clarified! for the basic details you need.The only wrinkle to keep in mind is that objects will be automatically converted to String s (via their toString()method) to fit the %s format. With this in mind, here's a better exception message:if (terrain != FloorMapObject.POD) {throw new NoPodException(String.format("Can't TAKE: location %s is %s, not POD!", currentLocation,terrain));}That will print something like 'Can't TAKE: location (3, 1) is EMPTY, not POD!' because the Point andFacingDirection objects get converted to reasonable strings. The user now knows which command wentwrong, where the robot was when it happened, and how the condition differed from what was expected.Implement better messages for all the exceptions you throw. Since you already have tests that throw the exceptions,re-run the tests to verify that your String.format() calls work the way you expected.6. Add MotorLifetime to the Kiva ClassThe motor on each Kiva robot is rated for 20,000 hours. After this point the robot needs to have its motor replacedor be retired. We want to track how many hours a Kiva robot's motor has been running and use a fieldcalled motorLifetime to store the motor lifetime in milliseconds. When a Kiva robot moves forward, turns left,or turns right, the motor lifetime increments by 1000 milliseconds (1 second).We want to track this information in milliseconds for diagnostic purposes. There are more primitive data typesin Java than the ones you learned in the Duke courses. Read more about data types here . What data typeshould you use to store the motor's lifetime?Let's start by adding a field called motorLifetime to your Kiva class (You should choose an appropriate datatype from the reading). Now we can add a getMotorLifetime() method to return the current value, and anincrementMotorLifetime() method to add 1000 milliseconds to the current value.Test this by:creating a KivaMotorLifetimeTester class with one method inside it to execute the followinginstantiate a FloorMap with the following map:-----|K D|| P ||* *|-----9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 20/24instantiate a Kiva using the floor mapprint out the result of getMotorLifetime() . It should start at 0.turn rightprint out the result of getMotorLifetime() , It should be 1000.go forwardprint out the result of getMotorLifetime() , It should be 2000.turn rightprint out the result of getMotorLifetime() , It should be 3000.go forwardprint out the result of getMotorLifetime() , It should be 4000.takeprint out the result of getMotorLifetime() , It should be 4000.7. Write DocumentationFuture developers are also going to be working on converting your remote control to a self-driving feature. Wewant to make sure we leave the code base well documented. To get up to speed, read a little aboutJavadoc .Implement Javadoc comments to the classes and methods in RemoteControl , Kiva and KivaCommand .Be sure to at least include @param and @return tags where appropriate, but feel free to experiment withothers as well! Clean out the existing Javadoc you received on RemoteControl and replace it with somethingmore useful to future developers. (References to “Implement the run() method” etc. were helpful instructionsto you in the state you found the KivaWorld project, but not for posterity).8. Convert User Input to an Array of KivaCommandsThe RemoteControl class currently takes in a String of commands from the user that looks like "FFFTRF".However, our Kiva robots cannot understand instructions in that form. They can simply make one move at atime, accepting a single KivaCommand . So, we'll need to take the user inputted commands and convertthem into a more Kiva friendly format, a list of KivaCommand s that we can send to the robot's move methodone at a time. Before we do that, let's take a look at a couple Java keywords called break and continue .These may be helpful in programming the task we have just described.Learn About break and continuePlease read this short resource on what continue and break statements are: Break and Continue Statementin Java - Begin With Java .Can you answer these quiz questions about continue and break statements?1. What does the following code print out?String[] names = {"Jessica", "Aliyah", "Joe", "Mohammed"};for (int i = 0; i String name = names[i];if (name.equals("Joe")) {continue;}9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 21/24System.out.print(name + " ");}A) Jessica Aliyah JoeB) Jessica AliyahC) Jessica Aliyah MohammedD) Jessica Aliyah Joe MohammedE) Jessica Aliyah Mohammed, and then an exception is thrownAnswerShow2. What does the following code print out?String[] names = {"Jessica", "Aliyah", "Joe", "Mohammed"};for (int i = 0; i String name = names[i];if (name.equals("Joe")) {break;}System.out.print(name + " ");}A) Jessica Aliyah JoeB) Jessica AliyahC) Jessica Aliyah MohammedD) Jessica Aliyah Joe MohammedE) Jessica Aliyah Mohammed, and then an exception is thrownAnswerShowWrite the Convert Method Using continue and/or breakCreate a helper method in the RemoteControl class called convertToKivaCommands() . This method shouldtake a String as a parameter, which will be the commands that the user types into the console (for example“FFFTRF”). It should return an array of KivaCommand s (in this case FORWARD , FORWARD ,FORWARD , TAKE , TURN_RIGHT , FORWARD ). We recommend doing this by using the values()method of the KivaCommand enum to get an array of all of the KivaCommand s. You can then use the get-DirectionKey() method to determine which KivaCommand each char in the String should be converted to. Ifthe user enters a character that does not correspond to a command throw an IllegalArgumentException witha useful error message.Note: When you want to print out the contents of a KivaCommand[] array variable called commands, for example,you would call Arrays.toString(commands) to turn the array into a single String . You'll need to importjava.util.Arrays to use this method. Here is some sample code that you can play with in BlueJ to demonstratethis, then use the approach for your needs:9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 22/24import java.util.Arrays;public class PrintArray {public void testPrinting() {String[] array = {"Cat", "Dog", "Shark"};// Here is a failed attempt to print out the array. It looks garbled andnot useful!System.out.println(array);// Here is a successful attempt to print out the array.System.out.println(Arrays.toString(array));}}Test CasesTo test your new method create a RemoteControlTest class where you will write test methods for the followingcases.Input: “FFFTRF”Output: {FORWARD, FORWARD, FORWARD, TAKE, TURN_RIGHT, FORWARD}Input: “B”Output: java.lang.IllegalArgumentException: Character 'B' does not correspond to a command!9. Fix the NullPointerException and FinishRemoteControlRight now, when we attempt to call the run() method in RemoteControl , it doesn't seem to work. What exceptionis being thrown and where is it thrown from? Let's start with fixing that. If you need a little help gettingstarted, this documentation might be helpful.Now, we are going to fill in the rest of the run() method in the RemoteControl class. We will create a Kiva ,using the FloorMap created from the file, then print some diagnostic information to the user telling them thestart location of the Kiva and what direction it is pointing. We will then convert the user input that is collectedby the KeyboardResource into KivaCommand 's using the convertToKivaCommands() method you wrotepreviously. Finally, we will have the Kiva robot move() each of these KivaCommands , and inform the user ofthe result!Once you're able to get the Kiva to move around, at the end of a sequence of commands you need to figureout if the Kiva successfully picked up the pod and dropped it in the correct place. You can use isSuccessfullyDropped()on the Kiva to determine if you dropped the pod in the right place. Moreover, if you get any exceptionsyou know the Kiva robot failed for some reason. Your improved and informative exception messagesfrom project task five will provide users with enough information to know what went wrong.If the Kiva was successful, print “Successfully picked up the pod and dropped it off. Thank you!”If the Kiva was not successful because it did not pick up the pod or moved after dropping it off, print“I'm sorry. The Kiva Robot did not pick up the pod and then drop it off in the right place.”. The last actionthe Kiva takes must be to drop the pod in the right location. It cannot move away from the dropzone.If the Kiva was not successful because an exception was thrown, you will see the exception come outin the Terminal with your informative exception message.9/20/21, 7:25 PM Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaPr…https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Service_Courses/Course4/JavaProgrammingPostDuke/project/KivaRobotRemot… 23/24Test CasesExecute therun()method with the following inputs. Validate that you see the expected output.Inputs: Floor map file: sample_floor_map1.txt, Command string: “RFFFFFTFFFFFFFD”Output: “Successfully picked up the pod and dropped it off. Thank you!”Inputs: Floor map file: sample_floor_map2.txt, Command string: “RFFFFFFLFFFTRFFRFFFD”Output: “Successfully picked up the pod and dropped it off. Thank you!”Inputs: Floor map file: sample_floor_map3.txt, Command string:“RRFFFLFFFFLFFFRFTFRFFFLFFFFFFFFFFLFFFD”Output: “Successfully picked up the pod and dropped it off. Thank you!”Inputs: Floor map file: sample_floor_map2.txt, Command string: “RFFFFFFLFFFTRFFRFFFDR”Output: “I'm sorry. The Kiva Robot did not pick up the pod then drop it off in the right place.”(Notice these are the same commands as the successful test case above except you turn after dropping thepod. If dropping the pod in the right place is not the last command of your Kiva then this is a test case failure).Inputs: Floor map file: sample_floor_map3.txt, Command string: “R"Output: “I'm sorry. The Kiva Robot did not pick up the pod then drop it off in the right place.”Inputs: Floor map file: sample_floor_map3.txt, Command string: “RRFFFLFFFFLFFFRFT"Output: “I'm sorry. The Kiva Robot did not pick up the pod then drop it off in the right place.”Inputs: Floor map file: sample_floor_map2.txt, Command string: “RFFFFFLFFFTRFFRFFFD”Output: “NoPodException: Can't take nonexistent pod from location (8,1)!”Inputs: Floor map file: sample_floor_map2.txt, Command string: “RFFFFFFLFFFTRFFRFFD”Output: “IllegalDropZoneException: Can't just drop pods willy-nilly at (11,3)!”Inputs: Floor map file: sample_floor_map1.txt, Command string: “F”Output: “IllegalMoveException: Can't move onto an obstacle at (1,0)!”
Answered 6 days AfterOct 03, 2021

Answer To: Project Overview Welcome to 2012!Ahem,I mean to the Kiva team! We are working on introducing robots...

Jahir Abbas answered on Oct 10 2021
134 Votes
Self-Service Course 4 Project - Kiva Robot Remote Control (Amazon_Technical_Academy.Self_Service_Courses.Course4.JavaProgrammingPostDuke.project.KivaRobotRemoteControl.WebHome) - XWiki
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
1 of 26 10/4/2021, 7:23 AM


Amazon Confidential




The required code are written along with the samples provided.
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
2 of 26 10/4/2021, 7:23 AM


Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
3 of 26 10/4/2021, 7:23 AM


Self-Service Course 4 Project - Kiva Robot
Remote Control
Primary Owner amazon-tech-academy (POSIX)
Last modified 4 months ago by bperciva.








About


Launch


Engage


Learn


Hire


Volunteer


FAQs


Contact


Current Participants


Internal

We have provided this project as a way for you to get more familiar with the Course 4 Learning Material, to
prepare you for the Technical Assessment, and to provide individuals interested in applying to After Hours
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
4 of 26 10/4/2021, 7:23 AM


with an opportunity to demonstrate their coding experience.

Project Overview
Welcome to 2012! Ahem, I mean to the Kiva team! We are working on introducing robots into the Amazon
Fulfillment Centers and have plans to one day even have them drive themselves! But let's not get ahead of
ourselves...

The Kiva robots are finished and they're incredible! They know how to move forward (F), turn left (L), turn
right (R), take (T), and drop (D). What are they lifting and dropping? They are lifting and dropping pods
filled with products and carrying them between the pod's storage location and a drop zone, where the Kiva
robot remains, and a Fulfillment Center employee removes products from the pod to pack an order. We
have created a program that prints out a map showing where the robot currently is, where the pod to pick
up is, and where it needs to be dropped off.

We need you to program a Kiva Robot Remote Control! Right now we've programmed the Remote Control
to print out the map of the FC and then take in directions from the driver, but those directi
ons aren't being
sent to the robot. We need you to interpret the directions and send them to the robot. Kiva Robots are in-
credibly expensive to make so you need to make sure they won't drive into any walls or obstacles when
you make a move.
P.S. We found this incredible video from the future showing “A Day in the Life of a Kiva Robot,” after they
learned to drive themselves! https://www.youtube.com/watch?v=6KRjuuEVEZs .
Before You Get Started
Download and Open the Project
1. If you do not have BlueJ installed on your computer, please download it from Duke here .
Download the appropriate version based on your operating system directly from that website. Don't
download BlueJ directly from https://www.bluej.org/ because the version there will miss critical de-
pendencies from Duke.
2. Open the KivaWorld downloads folder in workdocs.
3. Download the KivaWorld-##.zip file (for example, KivaWorld-01.zip, but may have a different num-
ber in place of the "##") that you see
1. There should be a KivaWorld-##.zip file that contains the starter code -- download this one
now
2. (There will also be a KivaWorldJavadoc-##.zip file that contains documentation about the ex-
isting code -- more on this below in a "Documentation" section)
4. Double-click on the .zip file to expand the project contents. Feel free to move the KivaWorld folder to
wherever you keep your projects on your computer.
5. Double-click on KivaWorld/package.bluej. (Note that this is just another way of opening a BlueJ
project--besides opening BlueJ first and using the Project menu to find the project)
6. You should see the class that you'll be implementing, and can now run the code!
http://www.youtube.com/watch?v=6KRjuuEVEZs
http://www.bluej.org/
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
5 of 26 10/4/2021, 7:23 AM




How to Run and Test the Project
Now that you've got the project open in BlueJ, let's run the code for the first time!

Click “Compile” on the left side of the BlueJ project window:
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
6 of 26 10/4/2021, 7:23 AM


Right click on the class and select “new RemoteControl()” to create a new
instance:
Choose a name for your new instance, for example, remoteControl, and hit OK.
Right-click on the red instance in the lower portion of the BlueJ window and select “void run()” to ex-
ecute 's run instance method:
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
7 of 26 10/4/2021, 7:23 AM

The console should appear and you will get a at this point, which is expected.
Don't worry, we'll get around to fixing that later! Now you're ready to get started!
What is Already Present in the Project?
The class is responsible for running the program, interacting with the user, and moving
the Kiva robot. We have provided you this class with some starter code in it. It contains logic to interact
with the console by printing out the map of the floor, and taking in the string of directions from the user.
In addition to , the project will utilize some code that has already been written by the
Warehouse Team. The Warehouse Team had already written this code, so they've packaged it up for our
team to use. You will not need to make changes to any of these classes, but we wanted to explain how this
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
8 of 26 10/4/2021, 7:23 AM


works so it doesn't seem like too much magic. These classes are tucked away inside a JAR (Java
ARchive) file inside KivaWorld/+libs/. A JAR file is a convenient way to bundle a bunch of related Java
classes (often called a library) into a single file that the JVM can access. (Optional: Here is a good intro
on JARs , though a little more information than you need right now.)

Here's a quick summary of the classes and enumerations provided by the Warehouse Team:

: Represents a Kiva's environment, including pickup/dropoff points, obstacles and Kiva's
starting location. It allows identifying what exists at any given location, as well as rendering the en-
tire map as a String for display.
: Represents the direction a robot is facing. There are four orientations, and each
includes a “delta” point which moves the robot one space in that direction when added to the current
location.
: Represents what is located at any given location of the FloorMap.

Optional: Taking a look inside the JAR

Show
Optional: How to open a terminal and cd to the project directory

Show

Starter Code Class Diagram
We created a class diagram to visualize the classes provided by the Warehouse Team and the
class.
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
9 of 26 10/4/2021, 7:23 AM
Please select a map file
P *




Documentation
We've also provided more complete documentation in the form of Javadocs, which are a collection of
HTML files that document classes and their methods.
1. Open the KivaWorld downloads folder on Workdocs.
2. Download the KivaWorldJavadoc-##.zip file with the highest version number (the version should
match the version of the KivaWorld-##.zip file you downloaded, let us know if this is not the case).
3. Double-click on index.html to load the javadoc viewer in your browser.
4. Refer to these pages throughout the project to see how the above classes behave.
You can view the Javadocs for the classes you're writing and editing (e.g. ) as you build
them, via the Tools → Project Documentation menu in BlueJ (if it asks you if you want to regenerate docu-
mentation, click “Regenerate”).

Sample Floor Map Files
We have also provided you with three floor map files in the KivaWorld-##.zip that you downloaded. You
can use these for testing purposes.
sample_floor_map1.txt - a simple map with walls, but no obstacles. The K, P, and D are all in a
straight line.
sample_floor_map2.txt - a map with walls and obstacles
sample_floor_map3.txt - a map with walls and obstacles
Project Goals
Your goal is to complete all of the project tasks, which will result in interacting with the
user in the following way.
Actions: Pop Out | Edit | ?
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
10 of 10/4/2021, 7:23 AM

Please select a map file

-
P *
--- -
|*| *
K--- D -
* * * *
-

Current Kiva Robot location: (2,4
Facing: UP
Please enter the directions for the Kiva Robot to take
LFFFFF

I'm sorry. The Kiva Robot did not pick up the pod and then drop it off in
the right place




The user will not always provide a path that successfully picks up and drops off the pod. We will detail out
these error cases later and how to handle them, but as an example, here the path provided never picks up
the pod.
End State Class Diagram
This diagram shows you what your project will look like once you have completed all of the project tasks.
Take a look at the new class and enum that you will be responsible for implementing, and
. will interact with both of these new classes, and your class will use
the already defined classes from the Warehouse Team. We will dive into more details in the implementa-
tion overview below.
**
**
*K
*
*
D *
Current Kiva Robot location: (3,4
Facing: UP
Please enter the directions for the Kiva Robot to take
FFRFFFFFFTFFRFFF
Successfully picked up the pod and dropped it off. Thank you
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
11 of 10/4/2021, 7:23 AM




Implementation Overview
describes the “moves” a Kiva robot can make: turning left or right, moving forwards, taking
a pod, and dropping a pod. It also includes each move's one-letter abbreviation.

holds the state and logic of a robot: where it is, which way it's facing, whether it's carrying a pod right
now, and whether it has successfully dropped the pod. A always starts facing (one of our pro-
vided ), not carrying a pod, and not having successfully dropped the pod. The
method performs the logic for any , and the method indicates whether
the previous command dropped the pod on the drop zone. We normally don't add getters to class dia-
grams, but this is the first time you're encountering a common naming convention that ATA will follow:
boolean getters often follow the pattern “ ” or “ ”.

When an impossible move is attempted, throws an exception. is appropri-
ate for attempts to move the robot off the warehouse floor or into an obstacle; is ex-
pected when there's an attempt to at a location without a ; and
should occur when we try to drop a pod anywhere but a . These exceptions are provided to
you by the Warehouse Team.

Running the whole show is , initiated by executing its method.
prompts the user to select a text file containing a to load, prompts the user to input a chain of
s using single-letter abbreviations, and then executes the s until
Actions: Pop Out | Edit | ?
1

1
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
11 of 26 10/4/2021, 7:23 AM
1. Implement the Enum


drops the pod successfully into the drop zone (or encounters an error).

Now you're ready to get started. We've broken out what you need to do to fully program the remote control
into the project tasks below. Happy coding!
Project Tasks

Before starting this task please refer back to the Enums Learning Material as a refresher.

objects can perform actions such as moving around and picking and dropping items. We allow users
in our program to enter 1 letter representations of these moves ('F', 'R', 'L', 'T', or 'D'), so we need a way to
map each action to a particular keyboard key.

Referring to the class diagram above, you'll do this by creating a new enum for the actions
that the robot can perform. The enum will use values that correspond to particular keyboard characters.
That way the class can map a char input key to a enum value.

In order to create an enum in BlueJ, click the 'New Class...' button. Enter the name of your enum, leave
the Class Language as Java, and then select 'Enum' from the options for Class Type. Click 'OK' to create
your enum.

Test this by creating a class. Create one test method per command and test that
when you run each method you get the expected output. Here is an example class
with one method filled in:


public void testTurnLeft(){
KivaCommand command = KivaCommand.TURN_LEFT;
System.out.println(command);
System.out.println(command.getDirectionKey());

}




Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
11 of 26 10/4/2021, 7:23 AM
2. Create the Class

public void testTurnRight(){
KivaCommand command = KivaCommand.TURN_RIGHT;
System.out.println(command);
System.out.println(command.getDirectionKey());

}
public void testTake(){
KivaCommand command = KivaCommand.TAKE;
System.out.println(command);
System.out.println(command.getDirectionKey());

}
public void testDrop(){
KivaCommand command = KivaCommand.DROP;
System.out.println(command);
System.out.println(command.getDirectionKey());

}

Test Cases
Test:
Input: Creates a object, then prints the command and its direction key
Output: “FORWARD” followed by “F” is printed out to the console.

Test:
Input: Creates a object, then prints the command and its direction key
Output: “TURN_LEFT” followed by “L” is printed out to the console.

Test:
Input: Creates a object, then prints the command and its direction key
Output: “TURN_RIGHT” followed by “R” is printed out to the console.

Test:
Input: Creates a object, then prints the command and its direction key
Output: “TAKE” followed by “T” is printed out to the console.

Test:
Input: Creates a object, then prints the command and its direction key
Output: “DROP” followed by “D” is printed out to the console.
Refer to the Class Diagrams learning materials to refresh yourself on reading class diagrams. Next, we'll
implement the class from the class diagram above. This is a fairly large and complicated task, so
we'll break it into smaller steps.

Implement the Attributes, Getters, and Constructors
We will start by creating the class, adding its instance variables, and writing the getter methods and con-
structors. Note there are two constructors for this class, and you must implement both of them. One of
them instantiates a object and sets the location of the Kiva robot from the provided ; the
other instantiates a object and sets the location of the Kiva robot from a (remember to import
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
11 of 26 10/4/2021, 7:23 AM
). Both constructors should initialize the state with the robot facing up, not carrying any
pod, and not having successfully dropped a pod. Ignore for now; we'll cover that later.
Remember the getters for booleans follow the naming convention described above,
and .

Test the constructors by creating a class. First, we will create a that
we can pass to our constructors. We can do this by using the provided con-
structor and the in the example below. Create a test method for each con-
structor, using the same test for each, and checking that the resulting Kiva robot location
matches the input. (We don't write separate tests for “trivial” getters that contain no logic.) Here's the test
for the constructor using a single argument:
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
115 of 10/4/2021, 7:23 AM





public void testTw oArgumentConstructor(){

Kiva kiva = new Kiva(defaultMap);

Point init ialLocation = kiva.getCurrentLocation();
Point expectedLocation = new Point(5,6);
if (sameLocation(init ialLocation,expectedLocation)){
System.out.println("testTw oArgumentConstructor SUCCESS");
} else {
System.out.println("Str ing.format( " testTw oArgumentConstructor
FA IL:%s != (5,6) !" , init ialLocation));
}

private boolean sameLocation(Point a, Point b){

return a.getX() == b.getX() && a.getY() == b.getY();
}
}

Test Cases
Test:
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
116 of 10/4/2021, 7:23 AM
3. Implement 's Move Method
Input: Pass the constructor the default map as the argument, then validate that the currentLocation of the
is as expected.
Output: “testSingleArgumentConstructor SUCCESS” is printed to the console.

Test:
Input: Pass the constructor the default map and a location of (5, 6) as the arguments, then validate that
the currentLocation of the is as expected.
Output: “testTwoArgumentConstructor SUCCESS” is printed to the console.

Moving Forward
Next consider the method. Depending on the it receives, must update the
current location, the direction the robot is pointing, whether it is carrying a pod or if the pod has been suc-
cessfully dropped. This is a lot of logic; implementing a helper method for each command will make the
code more readable and easier to manage. For now ignore the motorLifetime field.

Write a void helper method for the command (a name such a would be ap-
propriate, but you may use any name you like). Use only the simplest logic, without regard for obstacles,
pods, drop zones, or whether the robot is actually carrying anything; simply assume that the command is
valid and update the state accordingly. This command should update the current location. When the move
method gets a that is equal to you should call your new helper method.
Test by creating a class. Create a test method for the command and
test that after you issue the command, all of the getters return the expected values. Here's a free example,
, with a bonus helper method that validates the 's state. You can use it for your
other tests.
import edu.duke.Point
public class KivaMoveTest {
// Define the FloorMap we'll use for all the tests
String defaultLayout = ""
+ "- \n"
+ " P *\n"
+ " ** *\n"
+ " ** *\n"
+ " K D *\n"
+ " * * * * * **\n"
+ "- \n"
FloorMap defaultMap = new FloorMap(defaultLayout)
public void testForwardFromUp() {
// GIVEN
// A Kiva built with the default map we defined earlier
Kiva kiva = new Kiva(defaultMap)

// WHEN
// We move one space forward
kiva.move(KivaCommand.FORWARD)

// THEN
// The Kiva has moved one space up
verifyKivaState("testForwardFromUp",
kiva, new Point(2, 3), FacingDirection.UP, false, false)

Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
117 of 10/4/2021, 7:23 AM
// For you: create all the other tests and call verifyKivaState() for
each

private boolean sameLocation(Point a, Point b) {
return a.getX() == b.getX() && a.getY() == b.getY()

private void verifyKivaState(
String testName,
Kiva actual,
Point expectLocation,
FacingDirection expectDirection,
boolean expectCarry,
boolean expectDropped) {

Point actualLocation = actual.getCurrentLocation();
if (sameLocation(actualLocation, expectLocation)) {
System.out.println(
String.format("%s: current location SUCCESS",
testName));
}
else {
System.out.println(
String.format("%s: current location FAIL!", testName));
System.out.println(
String.format("Expected %s, got %s",
expectLocation, actualLocation));
}

FacingDirection actualDirection = actual.getDirectionFacing();
if (actualDirection == expectDirection) {
System.out.println(
String.format("%s: facing direction SUCCESS",
testName));
}
else {
System.out.println(
String.format("%s: facing direction FAIL!", testName));
System.out.println(
String.format("Expected %s, got %s",
expectDirection, actualDirection));
}

boolean actualCarry = actual.isCarryingPod();
if (actualCarry == expectCarry) {
System.out.println(
String.format("%s: carrying pod SUCCESS", testName));
}
else {
System.out.println(
String.format("%s: carrying pod FAIL!", testName));
System.out.println(
String.format("Expected %s, got %s",
expectCarry, actualCarry));
}


boolean actualDropped = actual.isSuccessfullyDropped();
if (actualDropped == expectDropped) {
System.out.println(
String.format("%s: successfully dropped SUCCESS",
testName));
}
else {
System.out.println(
String.format("%s: successfully dropped FAIL!",
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
118 of 10/4/2021, 7:23 AM
testName));

System.out.println(
String.format("Expected %s, got %s", expectDropped,
actualDropped));


Moving Forward Test Cases
Test:
Input: Create a object using the default map, and call move with the command. Verify
the state of the object. Ensure the current location has changed.
Output: The following is printed to the console:

testForwardFromUp: current location SUCCESS
testForwardFromUp: facing direction SUCCESS
testForwardFromUp: carrying pod SUCCESS
testForwardFromUp: successfully dropped SUCCESS
Turning Left
Continue implementing and testing with the next command, . Once you have imple-
mented its helper method, write tests for it in the class. Copy the existing test method to
create one test for each possible case of the directionFacing point ( , , , and ).
Ensure that each test verifies the 's state.

public void testTurnLeftFromUp() {
// GIVEN
// A Kiva built with the default map we defined earlier
Kiva kiva = new Kiva(defaultMap)

// WHEN
// We move one space forward
kiva.move(KivaCommand.TURN_LEFT)

// THEN
// The Kiva has moved one space up
verifyKivaState("testTurnLeftFromUp", kiva, new Point(2, 3), FacingDirection.UP, false, false)

// For you: create all the other tests and call verifyKivaState() for each

private boolean sameLocation(Point a, Point b) { return a.getX() == b.getX() && a.getY() == b.getY()



private void verifyKivaState( String testTurnLeftFromUp, Kiva actual,
Point expectLocation, FacingDirection expectDirection, boolean expectCarry,

boolean expectDropped) {

Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
119 of 10/4/2021, 7:23 AM
Point actualLocation = actual.getCurrentLocation();
if (sameLocation(actualLocation, expectLocation)) {
System.out.println(
String.format("%s: current location SUCCESS",
testTurnLeftFromUp));
}
else {
System.out.println(
String.format("%s: current location FAIL!", testTurnLeftFromUp));
System.out.println(
String.format("Expected %s, got %s", expectLocation, actualLocation));
}

FacingDirection actualDirection = actual.getDirectionFacing();
if (actualDirection == expectDirection) {
System.out.println(
String.format("%s: facing direction SUCCESS",
testTurnLeftFromUp));
}
else {
System.out.println(
String.format("%s: facing direction FAIL!", testTurnLeftFromUp));
System.out.println(
String.format("Expected %s, got %s", expectDirection, actualDirection));
}

boolean actualCarry = actual.isCarryingPod();
if (actualCarry == expectCarry) {
System.out.println(
String.format("%s: carrying pod SUCCESS", testTurnLeftFromUp));
}
else {
System.out.println(
String.format("%s: carrying pod FAIL!", testTurnLeftFromUp));
System.out.println(
String.format("Expected %s, got %s", expectCarry, actualCarry));
}

boolean actualDropped = actual.isSuccessfullyDropped();
if (actualDropped == expectDropped) {
System.out.println(
String.format("%s: successfully dropped SUCCESS",
testTurnLeftFromUp));
}
else {
System.out.println(
String.format("%s: successfully dropped FAIL!",
testTurnLeftFromUp));


System.out.println(String.format("Expected %s, got %s", expectDropped, actualDropped));
Self-Service Course 4 Pro ject - Kiva Robot Remote Control (Amazon_T... https://w.amazon.com/bin/view/Amazon_Technical_Academy/Self_Serv...
120 of 10/4/2021, 7:23 AM
}
}
}



Turning Left Test Cases
Test:
Input: Create a object using the default map, and call move with the command. Verify
the state of the...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here