CMSC 280
Fall 2017
08/28/2017
Carpet Hallways - 2
Due:  Fri, Sept 1
5pm

Relevant Reading:

Chapter 3 of the KarelJRobot book.

Assignment: (worth 5 exercise points)

Consider the CarpetHallways assignment.   How might you use inheritance and new classes of Robots to make the program simpler?
In other words, if you had a CarpeterRobot class, what capabilities would you like that robot to have and why? 
How would it make your coding simpler?
How would it make the code in Application easier to read?
How would it make the program easier to modify for similar problems?



Now, get CarpetHallways2.zip.   Use the files in this folder as your basis for this assignment.

For this assignment, you will be redoing last weekend's hw, where you carpeted hallways. The difference this time is that you are to use a new class of robots that makes the code in Application.java easy to understand the overall task.

Run the program as given and see the world that you are given. In this world are 4 "hallways" indicated by wall segments. You are to write a program that has 4 robots "carpet" those hallways by placing one beeper on each intersection within the hallways.


Detailed Specifications:
  • As usual, there should be no error shutoffs.
  • There must be a separate robot responsible for each hallway.
  • Each Robot object must start or begin outside of the hallway.
  • Each Robot object must finish or end outside of the hallway.
  • The carpet must consist of one beeper per intersection and only one beeper per intersection (beepers are expensive).
  • Each Robot object must be turned off when the program terminates (the cost of energy is high).
  • In the comment at the top of each file that you create or modify, be sure to put your name in a comment.
  • Each method you write should have a comment that says what the instruction does.
  • At the top of .java file with your new subclass of Robot, you should add to the comment what behaviors you have added to the robot.
Before
Empty Hallways
After
Carpeted Hallways
Note that the robots might end in different places,
as long as they are outside of the hallway.


Notes:
  • Remember that you are permitted to talk with others regarding how the program works. However, you need to do the actual work yourself and understand the answer that you produce.
  • Put your name in the comment at the top of the file. Also, put in the top of the file a note saying what the most difficult part of this homework was.

How to create a new class:
  • In Eclipse, highlight the kareltherobot folder.
  • Go to the File Menu
  • Choose "New"
  • Choose "Class"
  • For "Name", type the name of the new class.
  • Click "Finish".   The .java file should now appear next to the Application file.    Some starter code will appear in the window.
  • Don't forget that you will need to:
    • Copy the four lines of code for a constructor into this file and change the name to be the same as the name you chose for your class. e.g:
      •         public TurningRobot(int street, int avenue, Direction direction, int numberOfBeepers)
                {      
                   super(street, avenue, direction, numberOfBeepers);
                }

    • You will need to add "extends Robot" in order for this to have the Robot commands.  (You may wish to extend another class if you wish.)


If you wish to use the TurningRobot class in your assignment, here are two different ways of doing it:
  • Go to the desktop and drag a COPY of the TurningRobot.java file into the kareltherobot folder for this project.
  • In Eclipse, highlight the project (eg  Candles).  
  • Choose to Refresh, by one of these methods:
    • right-click and then choose Refresh
    • hit F5
    • Choose Refresh from the File menu.
OR
  • Create a new class called TurningRobot (see instructions above).
  • Copy and paste the contents of the entire file I wrote into this new file.

Handin:

  • Go to your Workspace folder.  
  • Create a Zip file of the folder containing your work.
  • Submit that file to Canvas