Com S 362 --- Object-Oriented Analysis and Design EXERCISE: OBJECTS AND CLASSES 1 (File $Date: 2003/09/03 04:49:55 $) The purpose of this exercise is for you to learn about objects in Java and how they implement ADTs. The ideas are similar to C++ but the syntax is slightly different. As with all exercises, this is to be done individually, not in teams. And it is due the day this topic is planned to be discussed in class, unless specified otherwise (see the syllabus at: http://www.cs.iastate.edu/~cs362/syllabus.shtml). As with all exercises, you have two choices for doing the work. You can either: - complete it as specified or - write down questions or problems that you had in trying to complete it. If you write down questions or problems you have, these should be detailed enough so that we can tell that you have read the materials and thought about them. (Don't just write: "I couldn't get it to work; say what you tried and what you didn't understand.) During the class where this exercise is discussed, you should try to get help with these by explaining what you did and what your problems or confusions are. Don't be shy; there will be other people with the same problem, and everyone can learn by discussing these issues. 1. [Java vs. C++] Read section 1.7 and chapter 2 of Ken Arnold, James Gosling, and David Holmes's book The Java Programming Language Third Edition (Addison-Wesley, Reading, Mass., 2000). Answer the following questions. a. Complete the following table of terms: C++ term Java term ----------------------------------------------------- namespace package constructor constructor member function method data member const field non-virtual member function abstract method ----------------------------------------------------- b. Does Java have anything like the "friend" mechanism in C++? If so, what is it? 2. [Vehicle class (TJPL3e, exercises 2.1 and 2.5)] Read section 1.7 and chapter 2 of Ken Arnold, James Gosling, and David Holmes's book The Java Programming Language Third Edition (Addison-Wesley, Reading, Mass., 2000). Write a simple class Vehicle that has fields for (at least) current speed (in km/h), current direction in degrees, and owner name. Include documentation comments (see section 1.3 of TJPL3e) for the class and all of its methods and constructors. Include a "toString" method. Make sure that all of the fields in the class are private. Write a main method for your Vehicle class that creates 3 different Vehicles, and prints out the Vehicles once constructed, using the toString method. Hand in a printout of your code; tell us if it works or if not, what problems you are having with it. We can discuss any problems in class. WHAT TO HAND IN You should have at the beginning of class, written answers to the above questions (or written out questions and problems you encountered for each part). Make sure your name is on these. Attach the printouts, if any, requested above. ADDITIONAL READINGS If you are new to Java you might also want to read the interesting (to you) parts of the "new to Java" section on-line at http://developer.java.sun.com/developer/onlineTraining/new2java/ (If you read that link, I would advise starting with the "step by step programming" step, which is step 3.)