Professional Documents
Culture Documents
Smith, 2017
CSCI 114 Programming Fundamentals II
BlueJ homework
BlueJ homework
Purpose
Purpose is to become comfortable using BlueJ to enter and run Java programs. You will
also learn how to unzip and run the example programs, how to install BlueJ onto your
own computer, and how to print programs for grading.
start BlueJ
BlueJ has a large main window which shows the class diagram of the program
you are working on
if necessary, use Project | Close to close an old project that may have opened
when BlueJ started
set Look in: to the place where your folder will be saved. For example, I used
Desktop
set File name: to something appropriate for the name of the new folder. I used
Rectangle
(the stripes mean that the class has not been compiled)
(you can drag the bottom right hand corner of the icon to re-size it)
1
Anthony W. Smith, 2017
CSCI 114 Programming Fundamentals II
BlueJ homework
BlueJ automatically gives you the generic template of a new Java class, to help
get you started. You edit and delete from this template so that it becomes the Java
code you want
heres the (corrected) Rectangle code again, type it in carefully! Be advised that
it continues onto the next page. Delete any parts of the generic template that you
do not use
(all the Java programs your write must look professionally formatted. Layout
your program exactly as shown below)
/**
* This program represents a rectangle.
*
* @author: you must put your own name here!
* @version: put today's date here!
*/
// constructor method
public Rectangle(double len, double w)
{
length = len;
width = w;
}
if you typed everything correctly, youll see Class compiled no syntax errors
in the status window at the bottom
2
Anthony W. Smith, 2017
CSCI 114 Programming Fundamentals II
BlueJ homework
if you made a typing mistake you may have a syntax error, where the rules of
the Java language have been broken. Syntax errors are normal as people learn to
program
the compiler finds syntax errors and tells you what and approximately where they
are
click the ? button in the status window for more help with a syntax error
repeat until all syntax errors are fixed and your program compiles cleanly
run the program by creating Rectangle objects from the Rectangle class
in the main window, right-click the Rectangle class icon to show a pop-up menu
choose new Rectangle(double len, double w) to run the constructor and create a
new Rectangle object
enter some values for your rectangles length and width and click Ok
the new object is shown on the object bench at the bottom of the window
3
Anthony W. Smith, 2017
CSCI 114 Programming Fundamentals II
BlueJ homework
BlueJ allows you to look inside an object, which helps you see more clearly
what is going on!...
click Close
click Project | Close, this clears your project from the class window
click Project | Open Project or Open Recent and navigate your way to your
project
close your project, then exit BlueJ when you are done
Project | Quit
Restart your Rectangle project in BlueJ, create a new Rectangle object, and run the
calculateArea() method to pop-up some output in the Terminal Window.
First, in Terminal Windows Options, set Clear screen at method call so that the
window is cleared every time you run a program. Also set Unlimited buffering, so that
the window can scroll to handle long output.
Then use Terminal Windows Options | Save to file to save the output of the program
into a text file. The file can be named output.txt, and saved inside the Rectangle folder
with the rest of the BlueJ project. (So at File name: you have to type output.txt not
just output the .txt file type is very important)
4
Anthony W. Smith, 2017
CSCI 114 Programming Fundamentals II
BlueJ homework
The example programs are compressed into a .zip file, which must be unzipped before
BlueJ can open the programs.
You must now download, unzip then run the example program named Hello. (Do not
worry yet about Java syntax, that will be explained beginning next week):
in Blackboard, Course Documents, Week 1 folder, find the Example programs item.
Click the down-arrow next to the Examples.zip link and choose Open
I use this to unzip or extract the example programs to a sensible location, for
example the Desktop
you have to find how to unzip the example programs on your own computer
start BlueJ when you have successfully unzipped the Hello example program
use Project | Open Project to open the Hello project from your uncompressed
folder
run the objects sayHello() method, which pops-up the BlueJ Terminal Window
where input/output is displayed
5
Anthony W. Smith, 2017
CSCI 114 Programming Fundamentals II
BlueJ homework
you will print the Hello program source code and output, explained shortly
BlueJ is available as a free download from www.bluej.org. Run the installer appropriate
to your computer.
(If you are unable to install BlueJ, you may not have enough computer experience to be
able to complete this course successfully.)
first, look inside the Rectangle folder to review some of the many files in a BlueJ
project:
Rectangle.java Java source file, for the Rectangle class. Written by the
programmer. Unlike this example, most programs contain many classes. Each
class is saved in its own, separate .java file
output.txt the program output, which you saved in a .txt text file
Rectangle.class Java bytecode file for the Rectangle class. Generated by the
compiler. Each .java file would be compiled into a separate .class file
6
Anthony W. Smith, 2017
CSCI 114 Programming Fundamentals II
BlueJ homework
of these files, you need to print the Java source file that you wrote contained in
Rectangle.java. Open your Rectangle program in BlueJ, then:
double-click the Rectangle icon in the BlueJ class window to display your code
in the editor window
make sure that your full name appears clearly in your source code!
make sure that your Java code looks professionally formatted, exactly like all the
example programs I write. Fix your layout if necessary
you must also print the output of your program, which you saved as the output.txt
text file
always check your output, make sure its correct before you print it!
(note that you cannot print in MD-234. You must print at home instead)
print and hand-in source code and output for both the Rectangle and Hello programs
this is a homework assignment, without a numeric score I just want to see that you
can do the work