MIT OpenCourseWare
  • OCW home
  • Course List
  • about OCW
  • Help
  • Feedback
  • Support MIT OCW

Labs

Java® Virtual Machine software (automatically installed in most major web browsers) is required to run the .class files in this section. Any number of development toolds, such as JCreator®, can be used to compile and run the .java files in this section. File decompression software, such as Winzip® or StuffIt®, is required to open the .zip files in this section.

This section provides a complete set of lab assignments for this course. All labs are due on the same day they are handed out.

The curriculum for SP.772, specifically the laboratory assignment portion, assumes the use of a free tool called JCreator®, a powerful IDE for Java that does not occupy much disk place (approximately 3 MB). Although this curriculum uses JCreator®, it is possible to complete all of the assignments by simply using a text editor and the command prompt.

Laboratory assignments B9-B17 have their solutions located within .zip files. In order to run the code correctly, the files must be organized in the same manner as within the .zip file.

Java® Labs

day # TOPICS labs solutions
JAVA®
1 L1: Introduction to Java® B0: Hello World (PDF) (PDF)
2 L2: Variables and Data Types

L3: Operators
B1: Variables and Operators (PDF) (PDF)
3 L4: Control Structures B2: Control Structures (PDF) (PDF)
4 L5: Arrays B3: Gradebook 1 (PDF)

B3a: JCreator (PDF)
Gradebook.class (CLASS)
Gradebook.java (JAVA)
5 L6: Methods B4: Gradebook 2 (PDF)

Gradebook.class (CLASS)
Gradebook.java (JAVA)

Supporting Files

EasyReader.class (CLASS)

6 Quiz 1

L7: Classes and Objects I
B5: GradebookOO 1 (PDF)

GBProgram.class (CLASS)
GBProgram.java (JAVA)
GradeBookOO.class (CLASS)
GradeBookOO.java (
JAVA)

Supporting Files

EasyReader.class (CLASS)

7 L8: Classes and Objects II B6: GradebookOO 2 (PDF)

(PDF)

GBProgram.class (CLASS)
GradeBookOO.class (CLASS)
GBProgram.java (JAVA)
GradeBookOO.java (JAVA)

Supporting Files

EasyReader.class (CLASS)

8 L9: Lists and Iterators B7: GradebookOO 3 (PDF)

B7: GradebookOO 3a (PDF)

(PDF)

GBProgram.class (CLASS)
GradeBookOO.class (CLASS)
GBProgram.java (JAVA)
GradeBookOO.java (JAVA)

Supporting Files

EasyReader.class (CLASS)

9 L10: Static and Final B8: Racecar 1 (PDF)

(PDF)

RaceCar.class (CLASS)
RaceCar.java (JAVA)

Supporting Files

EasyReader.class (CLASS)

10 Exam 1
11 L11: Package, Scope and Access B9: Racecar 2 (PDF) (ZIP) (The ZIP file contains: 2 .class files and 2 .java files.)
12 L12: Inheritance B10: Students 1 (PDF) (ZIP) (The ZIP file contains: 6 .class files and 6 .java files.)
13 Quiz 2

L13: Abstract Classes and Interfaces
B11: Students 2 (PDF) (ZIP) (The ZIP file contains: 7 .class files, 7 .java files and 1 .txt file.)
14 L14: Exceptions B12: MyStore 1 (PDF) (ZIP) (The ZIP file contains: 4 .class files and 4 .java files.)
15 L15: IO and Parsing B13: MyStore 2 (PDF) (ZIP) (The ZIP file contains: 14 .class files, 7 .java files, 1 .jsp file and 3 .txt files.)
16 L16: Introduction to Swing B14: Calculator 1 (ZIP) (The ZIP file contains: 5 .class files and 5 .java files.)
17 L17: Swing Event Model B15: Calculator 2 (ZIP) (The ZIP file contains: 5 .class files and 5 .java files.)
18 Quiz 3

L18: Collections I
B16: Card Game 1 (PDF) (ZIP) (The ZIP file contains: 11 .java files, 1 .css file, 1 .gif file, 1 list file and 32 .html files.)
19 L19: Collections II B17: Card Game 2 (PDF) (ZIP) (The ZIP file contains: 11 .java files, 1 .css file, 1 .gif file, 1 list file and 32 .html files.)


JSP™ Labs

Exercise 0 - "Start your Own Store"

For your first exercise, we ask you to build some web pages representing an online store. Your store can have any name you want and sell anything you want at any price. For now, your visitors won't be able to buy anything because we don't know JSP™ yet, but don't worry, we'll get to that in later exercises. There are three main requirements for your site. The first is that it must include at least 3 pages, one of which is a home page and at least 2 pages which are reachable from the home page. You are free to add more pages, of course, and we encourage you to do so. Second, your store must show an image alongside each item it is selling. Third, it must have a uniform look and feel with the top and bottom of every page looking the same across the entire site.

Exercise 1 - "Making Your Store Dynamic"

In this exercise, we're going to continue with the online store you started in Exercise 0. First, you'll have to change all your files ending in ".html" into files ending in ".jsp". Next, every page should show the current date in a nice, easy-to-read format, unlike the examples in class in which the date was complicated to read (hint: take a look at the java.text.DateFormat). The last requirement is that you use at least one JSP™ expression, one JSP™ declaration, one JSP™ scriptlet, and one JSP™ page import directive in your site.

Exercise 2 - "Shopping Spree"

Now it's time to let your visitors buy the items you have for sale. They should be able to start the purchasing process by clicking on an item. This should bring them to a confirmation screen in which they can enter their name and shipping address. We will ignore how they will actually pay for item. The site should warn you if the name or address is invalid in any way.

Exercise 3 - "Making Your Code Modular"

Extract the common code from each of your pages and place it into separate files. These separate files should now be included (either statically or dynamically) from the original pages. Also, have your form validation pages forward to a "success" page if the data is valid, and back to the form otherwise. By a "success" page, we mean a page that indicates the purchase was made successfully.

Exercise 4 - "Keeping a Shopping Cart"

There are currently a few limitations to your online store. They are 1) that users have to purchase each item they want to buy individually, and 2) that they must enter in their name and contact information for every purchase. Fix problem 1 by keeping selected items in a "shopping cart" that you store in the session. The user can then later proceed to the "checkout counter" to buy all the items at once. And fix problem 2 by keeping a cookie that stores the users name and address and automatically fills the name and address HTML form with that information.

Exercise 5 - "The Grand Opening"

Rework your code to ensure a clear separation of the presentation of the pages from the logic driving the pages. In doing so, you must create at least one Java® class that is called from JSP™ pages. Put the finishing touches on your site for the grand opening. When you're done, invite others to sit at your computer and navigate your store.