/* * The purpose of this lab is to acquaint you with several of * ProfessorJ's features that you have seen in lecture and will be * utilizing on the homeworks. * * Before continuing, make sure that the language level is set to * "ProfessorJ - Beginner". */ /* * Here's a example of a basic class: * * A Person is a class that has three fields: a first name (String), a * last name (String), and a birth year (int). * * On a piece of paper, draw the data definition in box form as you've * seen in lecture. */ /* Come up with some examples in English of a Person. For example: * * - John, Adams, 1735 * - Neil, Armstrong, 1930 * - Dan, Aykroyd, 1952 * * Make some more examples below in this comment: * * * */ /* * Now in the space between the two lines below, write a Java class * definition for the Person class. Make sure to also write a purpose * statement for the class in a comment above the class definition! */ /**********************************************************************/ /**********************************************************************/ /* * After hitting the Run button, use the Interactions Window to define * a few instances of the class. Practice using both of the following * formats: * * - new Person("first", "last", 1979) * (note that there's no semicolon at the end!) * - Person p = new Person("first", "last", 1979); * (for definitions, the semicolon is required) * * Some ideas for example data: yourself, a friend, or your TAs/tutor. */ /* * To save your examples in your code, you need to insert them into * a class called Examples which you can then instantiate and test. * Look at the bottom of this file to see a definition of Examples * and to see how to insert your examples into it. */ /**********************************************************************/ /**********************************************************************/ /* * Practicing creating some more classes and examples below. Some * ideas for classes (some of which you've seen in class) might be: * * - Addresses * - Books * - Train stations * - Restaurant menu items * * First think about what type of information you need for each class, * come up with examples of the class (in English), write a data * definition for the class, create the Java class definition, and * then translate your English examples into Java. */ /**********************************************************************/ /**********************************************************************/ /* * Now practice containment: create a class Lecture that has a * lecturer (Person), a building name (String), and a room number * (int). Follow the same format as before (examples in English, data * definition on paper, class definition, examples in Java). */ /**********************************************************************/ /**********************************************************************/ /* * Come up with some more ideas of classes that might contain Persons * (or Lectures, or whatever classes you came up with on your own * above) -- there's space below to work on them. Some examples are * courses (contains Lectures) and the Executive Branch of the US * Government (contains Persons such as the President, VP, etc.). */ /**********************************************************************/ /**********************************************************************/ /* * Now you'll create a union of classes. The main example we'll use * here are Shapes: * * - A Shape has an x (int) and y (int) coordinate. * - A Circle is a Shape with a radius (int). * - A Square is a Shape with a side length (int). * - A Rectangle is a Shape with a width (int) and height (int). * * Shape itself is an abstract class -- we're not interested in creating * instances of Shape directly, but rather of creating instances of its * subclasses. * * Go through the same steps as above. */ /**********************************************************************/ /**********************************************************************/ /* * As before, try coming up with your own examples of unions. Some * examples are types of automobiles or different methods of mass * transit. */ /**********************************************************************/ /**********************************************************************/ /* * That's it! If you've finished everything up to here, here's some * * extra space to try out everything you've learned: */ /**********************************************************************/ /**********************************************************************/ // Class for containing examples: class Examples { Examples() {} // Don't mess with this line! // Examples from above: // Person p = new Person("first", "last", 1979); /* * Run the following code in your interactions window: * * Examples e = new Examples(); * * and then test out your examples like so: * * e.p * */ }