CSC 207 Grinnell College Spring, 2012
 
Algorithms and Object-Oriented Design
 

Getting Starting with Java and Eclipse

Shifting from Scheme and MediaScript to Java and Eclipse

Summary

This laboratory begins a transition from working with the Scheme or C programming language to programming in Java within the Eclipse Integrated Development Environment (IDE).

Background Reading

Before working on this lab, be sure you have read the readings on An Introduction to Objects, Files in Java, and Getting Starting with Eclipse

A Simple Course Class in Scheme

Consider a simple class that would maintain information about a course. Each object in the class might have the following characteristics:

The reading on An Introduction to Objects describes two Scheme implementations of a course class in Scheme. These programs are available as course-1.ss and course-2.ss.

  1. Experiment with program course-1.ss:

    1. Load the program into Scheme.
    2. Test course.ss with the following sequence of commands:
      (define myCourse (course "CSC"  207  4  "Algorithms and Object-Oriented Design"))
      (define yourCourse (course "Math"))
      
      ;; test of initialization, toString, and extractor methods
      (myCourse 'toString)
      (yourCourse 'getSubject)
      (yourCourse 'getNumber)
      (yourCourse 'getTitle)
      (yourCourse 'getCredits)
      
      ;; set fields
      (yourCourse 'setNumTitle 131 "Calculus I")
      (yourCourse 'setCredits 4)
      
      ;; print results of modification
      (yourCourse 'toString)
      
    3. Explain in a paragraph or two how program course-1.ss works.
  2. Repeat Step 1 with program course-2.ss.

  3. Be sure you understand how this code works. In particular, answer the following questions.

The Course Class in Java

Program Course.java provides a translation of the Scheme code (particularly course-2.ss) to Java.

  1. Experiment with program Course.java, calling this program Course1.java, as you register it with Eclipse:

    1. Follow the steps outlined in the reading, An Introduction to Eclipse to start Eclipse, copy-and-paste Course.java into Eclipse, and run the program.
    2. Be sure you understand how this code works by answering the questions of Step 3 for this Java program.
  2. Explore some of the Eclipse environment by introducing several typographical errors in Course.java. Then try compiling and running the program, and record what happens.

  3. Create a new copy of Course.java in Eclipse by importing the full program, following the instructions in the reading, An Introduction to Eclipse After importing the program, compile and run it.

  4. Within main, create a new object for a 1-credit computer science course, CSC 299, "Computing and Health Care" (the name of a special topic course last semester). Also add print/println statements to print out information for this additional course.

  5. Following the style of the Modifier methods in Course.java, add new methods setNumber and setTitle. Then add testing code to main for these new methods.


This document is available on the World Wide Web as

http://www.walker.cs.grinnell.edu/courses/207.sp12/labs/lab-intro-java.shtml

created 3 April 2001
last revised 22 January 2012
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.


Copyright © 2011-2012 Henry M. Walker.
CC-BY-NC-SA
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License .