Due in OWL, 9:00am, Tuesday February 8, 2005.
Extra credit of 5 points if handed in before 11:59pm, Monday February 7, 2005.
Important notes:
There is a great tradition in computer science of starting to learn a new computer language by first writing a small program that does nothing but prints to the screen the message "Hello, world!" Here is a Java program that does just this:
public class MyProgram { public static void main (String[] args) { System.out.println ("Hello, world!"); } }
Type this program into DrJava, click the "Save" button near the top of the window, name the saved file MyProgram (it will actually be saved as MyProgram.java), and press the "Compile All" button also near the top of the window. If you typed it correctly, and it compiled without errors, you can select the "Run Document's main method" menu item from the "Project" menu, and you should see the friendly greeting appear in the interaction pane at the bottom of the window!
For Problem 1, modify this program to print "Hello, UMass!" and hand it in through the OWL system for this assignment.
Here is what the interaction pane should like like after it runs:
Welcome to DrJava.
> java Hello
Hello, UMass!
>
Create a representation for person objects that captures the person's name, height and year of birth. Define a Java class Person with a three-parameter constructor with the following arguments (in this order): a String for his or her name, a real-valued floating point number for height, an integer for birthyear. Also define three query methods to access these values. You must name these query methods name, height, and birthYear.
Although you should create some person objects and interact with them to test out your code, you only need to hand in the code that defines your Person class, not code that would create an manipulate Person objects.
Here are some DrJava interactions with the class:
Welcome to DrJava.
> Person bclinton = new Person ("Bill Clinton", 74.5, 1946); > bclinton.height(); 74.5 > bclinton.name(); "Bill Clinton" > Person arnold = new Person ("Arnold Schwarzenegger", 70, 1947); arnold.birthYear(); 1947 > int bclintonAge = 2005 - bclinton.birthYear(); > bclintonAge 59
Create a representation for movie objects that captures the movie's title, running length in hours, year of first release, and whether or not it is foreign. Define a Java class Movie with a four-parameter constructor with the following arguments (in this order): a String for the movie title, a real-valued floating point number for the running length in hours, an integer for the year it was released, and a boolean for whether or not it is foreign. Also define four query methods to access these values. You must name these query methods title, length, releaseYear, and isForeign.
Although you should create some movie objects and interact with them to test out your code, you only need to hand in the code that defines your Movie class, not code that would create an manipulate Movie objects.
Extra credit (5 points): Add to your Movie class a boolean instance variable that indicates whether or not the movie is currently playing in theaters, and a query method called currentlyPlaying that returns this value. Also include a command method called setCurrentlyPlaying that takes one boolean argument, and sets this instance variable.
Here are some DrJava interactions with the class:
Welcome to DrJava.
> Movie nemo = new Movie ("Finding Nemo", 1.683, 2003, false); > nemo.length(); 1.683 > nemo.title(); "Finding Nemo" > Movie aviator = new Movie ("The Aviator", 2.8, 2004, true); aviator.releaseYear(); 2004 > aviator.currentlyPlaying(); true
And if you implemented the extra credit, an interaction could look like:
Welcome to DrJava. > Movie aviator = new Movie ("The Aviator", 2.8, 2004, true); > aviator.currentlyPlaying(); true > aviator.setCurrentlyPlaying(false);
> aviator.currentlyPlaying(); false