Copyright © Cay S. Horstmann 2009, 2012
This work is licensed under a Creative Commons
Attribution-Noncommercial-Share Alike 3.0 United States License.
Lab 1 Fred Foo
(Scribe) / Becky Bar (Driver)
Lab 1 Becky Bar
(Driver) / Fred Foo (Scribe)
Part A
tar xvfz Downloads/jdk-7*-linux-i586.tar.gz mv jdk1.7.0_* jdk1.7.0 echo 'export PATH=~/jdk1.7.0/bin:$PATH' >> .bashrc
Then close the terminal.
java -jar Downloads/bluej-3*.jar
bluej
HelloPrinter
rectangle. Erase all code
in the editor window and paste in this code:
public class HelloPrinter { public static void main(String[] args) { // Display a greeting in the console window System.out.println("Hello, World!"); } }
void
main(String[] args)
from the menu. Click Ok on the next dialog. You
should get this display:
Congratulations: You have just executed your first Java program.
Hello,
your
name!
. What change did you
make?
When the lab instructions ask you a question about what you did, the scribe needs to enter the answer into the lab report. For example, “We double-clicked on the HelloPrinter class and changed the code so that it looks like this: (paste in code). Then we repeated steps 7 and 8.”
System.out.println
with
System.ouch.println
. Click Compile. What happens?
Remember to put the answer into your lab report.
Remember to put the answer ...
public class HelloPrinter { public static void main(String[] args) { // Display a greeting in the console window System.out.println("+---------------+"); System.out.println("| Hello, World! |"); System.out.println("+---------------+); } }
Click Compile. What error do you get? How do you fix it? What does the program print?
Remember to ...
public class HelloPrinter { public static void main(String[] args) { // Display a greeting in the console window System.out.println(+---------------+); System.out.println(| Hello, World! |); System.out.println(+---------------+); } }
Click Compile. What error do you get? How do you fix it?
///// | o o | (| ^ |) | [_] | -----
What is the code of your program?
Part B.
System.out.println
. Now we want to
experience a different kind of Java programs. You will install the Alice
tools from Carnegie Mellon. The tools are still a bit experimental, so the
setup isn't as smooth as we'd like it to be. Ask if you need help!
First, download Alice from http://www.alice.org/index.php?page=downloads/download_alice3.1. Pick the offline installer. The download takes a very long time, so you should do this at home, not in the lab. (It was a part of homework 0.)
hello
directory. Select Run
-> Run project from the menu. What happens?
myFirstMethod
method. (Ignore
all the complicated code above.) Make a change so that the trash can says
something different. What change did you
make?say
command:
trashcan.move(MoveDirection.LEFT, 1);
Run the program. What happens?