CSCE 145 -- Fall 2008

Sections 4, 5, 6

Introduction to Algorithmic Design

Lab Assignments

Lab Assignment 2


  • To install the textbook software on your H: drive, go to the CD that came with the textbook and open the directory named LibraryAndDoc. Alternatively, download to any directory on your H: drive, such as H:\csce145, the files Robots.exe and Robots.zip from the textbook's website (see the class web page for that website).
  • Double-click on your copy of Robots.exe. In the window that pops up, either browse to the folder H:\csce145\Robots\ or simply type that folder name into the field labeled: Unzip to folder:. Click the Unzip button. A progress bar will appear at the bottom of the dialog box. When it has finished, a completion dialog will appear. Click OK and then click the Close button.
  • Open eclipse by double-clicking on its icon on the desktop. If the Welcome window appears, click on the icon for the Workbench; Eclipse will request that you Select a workspace. Either type in or browse to the H:\csce145 directory and click OK.
  • Use File/New/Project and then choose Java Project and click next. In the window that pops up, choose a project name of lab02 and click next. To add the jar file from the textbook to your library path, first click on the tab Libraries. Click on the button Add external JARs. Browse to find the becker.jar file in H:\csce145\Robots and click Open. Now becker.jar is in your library path for this lab assignment.
  • NOTE: For every new project you create, you will need to include the becker.jar JAR in your library path if you are going to use the Robots library in that JAR.
  • We need to include the documentation for the textbook software. Click on the plus next to becker.jar. Choose Javadoc location and click on the Edit... button. Browse to find the documentation in Robots/doc/ and click OK. Now the documentation is set for Eclipse.
  • Finally, click finish at the bottom.
  • To add example files to the project, on Eclipse's main menu choose File, Import..., File System, and click on Next. Then browse to, for example, \Robots\examples\ch01\deliverParcel. Click Open, check the box next to deliverParcel, Make sure Into folder: contains lab02, and click Finish. The files will be located in the default package.
  • To run a program, first double click on a .java file in the left Package Explorer frame, such as DeliverParcel.java. Then right click and go to the bottom where it says Run as and choose Java application.
  • For this lab this week, you will write a Java program to solve Exercise 1.12 on page 49 in the textbook.
  • Now is as good a time as any to find out how to read the robots documentation on the web.
  • Go the author's page for the text on the web. Click on Software. This makes the drop down list appear. You want to click on Robots Documentation. This brings up the standard Javadoc-look web page, which can be a little formidable to stare at for the first time. Click on the second package, becker.robots, and then notice the Class Summary list. The second class listed is City and the eighth class is Robot. This is where all the good stuff on cities and on robots is listed in detail.
  • Note that there are several constructors for a City, and that one of them allows you to specify the first visible street and avenue.
  • Right click on default package in the left Package Explorer frame and choose class. In the window that pops up, choose a meaningful name for your class (e.g., GoAroundWalls) and type it in the Name box. In the Which method stubs would you like to create section, check the box for
    public static void main(String[] args). Click the Finish button.
  • A new class file will be created with the basic code you will need for your assignment. Include the following statement at the beginning of the class so that you can use the Robots code:
    import becker.robots.*
    (Make sure you include the semicolon at the end of the line.)
  • Write the necessary statements to solve Exercise 1.12 between the curly braces in the main method.
  • The construction of the walls requires you to understand where the walls get put depending on the values of the parameters. The two walls in the northeast corner of the configuration for 1.12 are at intersection 1 (street=row), 2 (avenue=column), and to the North and the East of that intersection.
  • Once your program is working, go to https://cse.sc.edu (note the difference of an extra s after http) and enter your user name and password. If you are logging in for the first time, the password will be your Student ID. After logging in, click and go to Dropbox Center and then Dropbox Student. Click on browse to go to the location where you stored the lab (H:/csce145/lab02) and click on the open button. Then click the upload button to upload the file. You will have to do this for all of your homework and lab assignments this semester.

Congratulations! You've just written and run your second CSCE 145 Java program.

Swearingen Engineering Center | Columbia, SC 29208 | 803.777.2880 | web@cse.sc.edu