This is not a current assignment. If you are currently enrolled in SE1010, do not do this assignment expecting to receive credit for it.

SE-1010 Lab 1: First Java Program

Objectives

  1. Carry out the basic steps required to create a working Java program, using the Eclipse integrated development environment.
  2. Use Eclipse to create a Java program containing a main class with a main method
  3. Write the Java instructions in the main method that send messages to instances of another (pre-written) class
  4. Draw UML class and sequence diagrams illustrating the structure of a Java program

Assignment

Overview

In this lab, you will use the Java program authoring tool Eclipse (already present on your PC) to create a simple Java program. When you use Eclipse, you begin by creating a project that contains the files that constitute your Java program. Eclipse can have many projects open simultaneously, but in this first lab you'll only create and work on a single project called SE1010 Lab 1. You can either read instructions or watch a video on creating a new project in Eclipse.

Recall from lecture that, as a general rule, every Java program must have a main class - that is, a class that contains at least one method named main - in order to be able to run. When you run a Java program - say, by double-clicking on a program icon - the Operating System (Windows, in our case) and the Java Runtime Environment (JRE) send a “run” message to the program by calling the main method in the main class. And remember, the main class can have any reasonable name.

In this assignment, you'll create a program containing a main class and main method, and then write additional Java instructions that create instances - that is, objects - of another class (that has already been written for you) called WinPlotter. The WinPlotter class implements behavior such that, by calling it's methods, you can create a window and draw simple images in that window. The UML Class Diagram of the WinPlotter class is shown below.

winplotterclassdiagram.jpg

Download the WinPlotter class by following this link. Save the file to a location on your directory that is convenient for you. The video shows how to include this class in your project.

Follow the WinPlotter link for online documentation (created with a tool we'll learn about later called JavaDoc) on the WinPlotter class and its various methods. Review this documentation in order to familiarize yourself with the capabilities of the WinPlotter class. Once you setup Eclipse, you'll also be able to view this documentation directly from within the Eclipse environment.

Assignment details

Your assignment is to write a Java application consisting of a main class called Lab1App that contains a main method. Within the main method you are to create three instances (objects) of the WinPlotter class, and send each object various messages such that it draws images into the windows managed by these objects. You can use your mouse to position the window anywhere on your screen, just as you would with any typical window. You cannot, however, size a WinPlotter window by dragging the corner with your mouse; you must resize the window programmatically by inserting Java code in your main class's main method that call the appropriate method of the WinPlotter class object. Start out by creating just one instance of the WinPlotter object, in order to keep things simple at the beginning. For the first WinPlotter window:

  1. Create the first instance of the WinPlotter class. After creation, resize the window to a size of 250×250 pixels.
  2. Set the background color to blue.
  3. Set the title to “SE1010 - lab 1 - window 1”
  4. Use appropriate methods to draw yellow lines that form a triangle on the window screen. The triangle vertices must lie within the boundaries of the window; you will have to experiment with the values in order to get this to look right. Don't draw a triangle so tiny that it looks like a dust speck on your screen.

Demonstrate this to your instructor before moving on to the next step!

For the second WinPlotter window:

  1. Create the second instance of the WinPlotter class. After creation, resize the window to a size of 300×300 pixels.
  2. Set the background color to black.
  3. Set the title to “SE1010 - lab 1 - window 2”
  4. Use appropriate methods to draw a green rectangle in the window.

For the third WinPlotter window:

  1. Create the third instance of the WinPlotter class. After creation, resize the window to a size of 350×350 pixels.
  2. Set the background color to white.
  3. Set the title to “SE1010 - lab 1 - window 3”
  4. Use appropriate methods to display your name at the center of the window (i.e. the first character of your name should start at the center of the window.

A note on writing Java code

Java code may look like English, but it's still a computer language that is primarily designed to be understandable by a computer. When well-written, it is easy for a person to understand what the instructions are doing as well. Good software developers observe certain rules when writing Java code as part of good software development practices - so get started on the right track. Here are some basic rules for writing Java instructions that you should follow for starters:

  • Use logical-sounding identifiers (nouns or noun phrases) for your WinPlotter objects.
  • Put comments inside your Java program more fully explain what you're doing.
  • Indent your code appropriately. Eclipse has an auto-indent command called “Correct Indentation” in the “Source” menu - ask if you have trouble using it.

Finally, test your program and make certain that it works correctly and conforms to all of the requirements stated above.

Additional assignment items

Along with your completed Java program, for this lab you must also:

  • draw the UML Class Diagram that illustrates your main class and its main method
  • draw a UML Sequence Diagram that illustrates your main class calling the methods in the three WinPlotter objects. A partial Sequence Diagram is provided below.

You may draw these diagrams by hand, but be sure they are neat and legible.

lab1sequence.jpg

se1010labs/lab1.txt · Last modified: 2010/03/09 20:55 (external edit)
 

This website is not owned or managed by the Milwaukee School of Engineering.

© 2003-2010 Dr. Christopher C. Taylor, et. al. • Office: L-343 • Phone: 277-7339 • npǝ˙ǝosɯ@ɹolʎɐʇ • -> RSS <-