The goals of this lab are to get familiar with our work environment: the svn repository, the Eclipse IDE, and the basics of running a program in Java-like languages. In the second part of the lab, (the one that really teaches you something) will focus on data definitions and examples in a simple subset of Java language.
We start with designing data - designing classes of data that are connected to each other in a systematic way, showing that the Design recipe for Data Definitions can be used virually without change in a completely different language than we have used in the first part.
We start designing methods in the functional style, i.e., every
method produces a new value (primitive or a new object) and makes no
changes in the existing data. This allows us to use a very simple
language, one where the only two statements are return
and if (condition) then statement else statement
.
The programs we provide give you examples of the progressively more complex data (class) definitions, and illustrate the design of methods for these class Hierarchies.
The design of methods follows
the same Design Recipe we have seen before. The only
difference here is that for classes that represent a union type (for
example classes Circle
and Rectangle
that
are both a part of the union type Shape
, the conditional
statement used in TeachScheme! inventory/template is replaced by the
dynamic dispatch into the class whose constructor has been used to
define the specific object.
Managing your work
Professional programmers need to keep track of the changes to their programs in a systematic way. Several different version control systems are designed to keep track of all changes in the program over its lifetime. They allow programmer to access their code from different computers, to return to an earlier version if the new changes prove to be ill conceived, and allow others to see what changes have been made over the lifetime of the program.a
We will use the svn version control system to manage the work of each homework pair. It will help you from loosing your work if a computer crashes, it will allow the partners to collaborate on the project, and will let us see your progress, aswell as the final completed project.
We will start the lab getting set up with the svn. Make sure you ask questions, try to submit at least a simple program to the system, and see how it handles your work.
First of all, you will need to have an CCIS user id.
Log into the lab computer using your CCIS credentials.
Open your web browser to the following web page for information on how to access your Unix/Linux directories. (likely not necessary, if you trust us)
http://howto.ccs.neu.edu/howto/accounts-homedirs/home-directory-access-on-linux-and-windows/
Navigate your way to the Z:
drive. If you can't find Computer on the desktop, then double-click the Recycle Bin and click on Computer in the left pane, then double-click the network drive myhome ... (Z:).
You should see the various directories and files that make up your Unix home directory. Right-click on the classes directory and select SVN Checkout... from the pop-up menu.
Visit this page to locate your HW partern's information:
http://www.ccs.neu.edu/course/cs2510/lab-pairs.txt
From there you should be able to locate your HW partner's information, and the number of your pair. Back to the checkout... for the URL of the repository, enter:
https://trac.ccs.neu.edu/svn/cs2510spring2012/pairXXX
where XXX is your pair number from the HW submission page. For the Checkout directory, enter:
Z:\classes\CS2510-Workspace
Or name it something you like better. Click OK. It should ask you for your CCIS username and password. Once you enter those a and it's finished, click OK, then navigate into the classes directory. You should be able to see your new SVN workspace directory!
Or name it something you like better. Click OK. It should ask you for your CCIS username and password. Once you enter those a and it's finished, click OK, then navigate into the classes directory. You should be able to see your new SVN workspace directory!
Create another directory in classes where you will keep all library (JAR) files, call it EclipseJars. For the rest of the Lab/term we will refer to these two directories as EclipseWorkspace and EclipseJars. Keep the file/explorer window open, we'll be using it later in the Lab.
Eclipse includes an editor and allows you to organize your work into many files that together make up a project. It has an "incremental" compiler that so you can edit and run your programs while getting relatively fast error feedback. Your Eclipse workspace can contain many projects, so you should be able to keep all your work in one workspace, with one project for each assignment or lab.
Start Eclipse. It should ask you where you want your workspace to be... so enter (or click Browse and navigate to) the workspace directory you created (saw that coming). Feel free to check the "Use this as the default..." box. Click OK.
Once Eclipse starts, close the annoying Welcome screen if it comes up.
There's a few settings we need to get out of the way before you start. If/when you work from your own computer you'll have to adjust these settings too, otherwise the graders might be angry... and you wouldn't like them when they're angry.
Select Preferences under the Window menu and change the following settings. You should also be able to follow along with your friendly Lab Leader.
Type "tab" in the search box at the upper-left to minimize the available selections.
Select "Text Editors" on the left. Make sure the "Insert spaces for tabs" check-box is checked.
Check the box "Show print margin" and select 80 spaces.
Check the box "Show line numbers"
When you say OK it will force you to create a name for the profile... you can just say "Mine" or some other cool name.
Great... now let's get on to Java-like programming!
Select New > Java Project from the File menu. Enter the name "last-Lab-02" but replace "last" with your last name. Under Project layout make sure the Create separate folders for sources and class files radio button is selected, then click Finish.
Your project should show up in the Package Explorer on the left (feel free to cheer at this point).
We will be submitting HWs via SVN through the Trac repository workspace that you just setup.
Go back to your file/explorer window, and enter your workspace folder Your project directory should be visible... right-click on it and select TortoiseSVN > Add.... Uncheck all entries, then select the entries for the EclipseWorkspace, the Project folder, the src folder inside of the Project folder, and all files inside the src folder. Click OK, then click OK again, when the action completes.
Right-click the project directory again and select SVN Commit.... Enter a message like "First checkin", then click OK. In general the msage should be meaningful, so that your partner can tell what you were doing when you changed things. After the action completes you now have all you need to submit assignments!
See the HW Handin link off the course webpage for more information and details on HW submission and organization.
Now that you're an Eclipse and SVN expert, download the library we need for running the tests and examples from the lab's index page.
Save it --- but be careful --- on the bottom of the window select Save As All Files not Save As WinArchive --- save it in your EclipseJars directory you have created before. The JAR provides output and testing functionality you saw in the lecture.
Right-click on your project directory in the Package Explorer pane and select Build Path > Add External Archives.... Navigate to your EclipseJars directory and select your tester.jar.
Add the Shapes.java file to your project
Download the file Shapes.java form the lab index page and save it into the src directory within your project directory, in your new workspace. Then right click on your project in the Package Explorer and select Refresh. You can also select the project and hit F5.
Alternatively, you can save it to a temporary directory and import it using File > Import.... Select the General tab, File System, and click Next. Browse to your temporary directory, select it, and find your file. Make sure you put it into your project src directory.
Set up an run configuration
Highlight your project in the in the Package Explorer pane.
In the Run menu select Run Configurations.... In the left pane select Java Application.
In the upper left corner click on the leftmost item (the icon with the plus in the corner). When you mouse over it should show New launch configuration.
Make up a name for this configuration - usually the same as the name of your project, lab, or assignment.
The Project field should be your current project (e.g., MyName-Lab-02), and in the Main class field enter tester.Main.
Click on the tab (x)= Arguments. In the Program arguments text field enter ExamplesShapes. Later, when you define your own program, you will use the name of your Examples class.
At the bottom of the Run Configurations select Apply then Run.
You should see a few messages in the Console, and a display of the ExamplesShapes class with the example instance(s).
If the program does not run and reports that it cannot find java or javac, open your Run Configuration and click on the tab Environment then select New and enter the following information:
Name: PATH
Value: C:\Program Files\Java\jdk1.6.0_23\bin, which is the location of the Java Compiler on the Lab machines, though at home yours will likely be different.
Then click OK and try running again.
View, Edit, and rerun Shapes.java
Unfold the default package under the src directory under your project in the Package Explorer.
You should see Shapes.java; double-click it, and the file should open into an editing tab in the main pane.
Add new examples of Circle and Rect to the Examples class. Make sure there are no errors or warnings.
Now run the file again. make sure Shapes.java is shown in the main pane, then hit the green circle with the white triangle in the top toolbar. You can also click and select your configuration for the drop-down menu to the right of the Run button.
We are building an App that will help us find places in a city. We first need to record addresses of interesting places. Here's a Racket data definition for an address:
;; An Address is: (make-addr String Number String) (define-struct addr (street no city)) ;; Example Addresses: (define a1 (make-addr "Beacon" 150 Boston)) (define a2 (make-addr "Boylston" 150 Boston)) (define a3 (make-addr "Chestnut" 25 Cambridge))
Draw the class diagram for this data definition
Create a new file in your Eclipse Lab project named Address.java and convert the data definition/class diagram into a FunJava class definition.
Create an Examples class, and include instances of Addresss. See Shapes.java for the necessary format(s).
Create a new Run Configuration and run the examples.
We now want to keep track of hotels in the city. For each hotel we need to know its name and its address. (We could include additional information, but for now, this is sufficient. Note that there may be a Hilton hotel at two different addresses --- that is OK.
;; A Hotel is: (make-hotel String Address) (define-struct hotel (name addr)) ;; Example Hotels: (define h1 (make-hotel "Hilton" a1)) (define h2 (make-hotel "Hilton" a2)) (define h3 (make-hotel "Marriot" a3))
Draw the class diagram for these data definitions
Add the Hotel class to your file and add the corresponding data definitions.
Run the examples to make sure everything is correct.
We certainly are interested in more than just hotels. We would like to know about other attractions, for example restaurants (each has a name and the type of food they serve, e.g. French, Mexican, Italian, Vegetarian; we would like to be able to find movie theaters (maybe with the number of show places each has), and other attractions.
Create an interface to represent various kinds of attractions call it IAttraction. The union of classes of IAttraction will be made up of three different FunJava classes... feel as described above. Feel free to add more information to each, or to add another class for your favorite kind of atttration.
If you change the name of the class Hotel to HotelAttr for the hotel data that are a part of the new union, you can use the same java file, just include new examples in your Examples class
Draw a class diagram for the class hierarchy that represents these three types of Attractions
Design data definitions (i.e., classes) for each of the definitions (including the interface)
Add examples of each kind of IAttraction to your Examples class. Be sure to use IAttraction as the type of the example fields.
Remember the ancestor tree example from last semester? Brings back fond memories of recursion doesn't it? Let's re-live a little... here's something like the definitions we had last semester:
;; An Ancestor Tree (IAT) is one of: ;; - 'unknown ;; - (make-at String IAT IAT) (define-struct at (name mom dad)) ;; Example IATs: (define at1 (make-at 'nknown)) (define at2 (make-at "Pete" (make-at "Jan" at1) (make-at "John" (make-at "Mary" at1) at1)))
Draw the class diagram for IATs and the related structures. Hint: rather than using a symbol, use a class without any fields.
Transform the diagram into class definitions
Make examples of IATs and add them to your Examples class. Use references to earlier fields (e.g., this.pete) to build your ancestor trees.
If you have some time left, try to define a list of attractions in a similar way.
Last, but not least, save your file(s), and add them to SVN. Right click on the file and choose TortoiseSVN > Add.... When you're done select Commit for the entire workspace directory.