| CSC 207 | Grinnell College | Fall, 2018 |
| Algorithms and Object-Oriented Design | ||
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).
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
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.
Experiment with program course-1.ss:
(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)
Repeat Step 1 with program course-2.ss.
Be sure you understand how this code works. In particular, answer the following questions.
Program Course.java provides a translation of the Scheme code (particularly course-2.ss) to Java.
Experiment with program Course.java, calling this program Course1.java, as you register it with Eclipse:
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.
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.
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 a few semesters back). Also add print/println statements to print out information for this additional course.
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.fa14/labs/lab-intro-java.shtml
|
created 3 April 2001 revised 22 January 2012 last revised 1 September 2014 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |