Comp 170 Lab 0 - Hello World / shapes
Goals
- Login and start BlueJ
- Create a simple BlueJ project
- Compile and run it
- Download the Shapes project, and try some things
Part 1: The Hello, World! project.
Login to windoze and start BlueJ. It should be somewhere reachable from the start
menu. Select Project => New_Project. Now comes the hard part:
figure out where to save your project. There's some temp space
somewhere on those machines, but it won't be yours for long.
You can fit BlueJ projects on a floppy, but that's obsolete.
Your best bet is to use a USB drive,
at least if, unlike me, you're not the kind
of person to leave it behind in the machine.
Wherever you save your project, put it in its own folder!.
You should see a BlueJ screen with one text icon. Click on the
new class button at the left, and after entering a name
you should see an orange "class box". Doubleclick on that,
and edit the text (or copy-paste it from this window) so that it looks something like this:
public class Hello {
public void hi() {
String s = "Hell";
System.out.print(s + 'o' + ' ');
System.out.println("World!");
}
}
Edit the source to add a comment expressing the importance of not leaving out the 'o'.
Click the Compile button to compile. Then go to the main
project window, rightclick on your orange program icon, and choose
the new Hello() menu option to create an instance on the object bench.
Then, on that red instance icon, rightclick and choose the hi() method;
if all goes well you should get some output.
You can also print numbers in addition to strings. Try printing out the following,
and be able to explain what happens:
System.out.println("333 + 444 is " + 333 + 444);
System.out.println("multiplication: " + (2000000 * 3000000));
Show your project to either me or the TA.
Be sure we make a note of it!
Part 2: Shapes
Click here to get the shapes.zip file. Save it
(somewhere), unzip it (somehow) into its own folder,
and use BlueJ to open the project.
This project is from Chapter 1 of the book.
Create one instance of each shape and at least two of one of the shapes,
and make them all visible, and move them around. Your shapes do not have to
relate to one another or form a picture (that's the following lab).
Be sure to try
- moveHorizontal(int)
- slowMoveHorizontal(int)
- changeColor(String)
- changeSize(int,int)
Think about the difference bewteen classes (the orange boxes above)
and instances (the red round-cornered boxes below). Also think
about what happens if you don't supply the right parameters,
such as moveHorizontal("xyzzy") or changeColor("xyzzy").
Note that there is a major difference between these last two; what is it?
Again, show your shapes on the screen to either me or the TA.