You are on page 1of 5

ITECH2306 AGILE CODING

Lab worksheet 1
A. Our first Java Program
The first exercise this week requires you to start Eclipse the Integrated Development Environment (IDE) in
which you will develop your Java code.
1. There is a separate handout available in Moodle titled “Using Eclipse IDE for Java”. Guided by
this resource, open Eclipse.
2. Create a workspace in an area of disk space where you have authority to save files and these
files will not disappear when you log off the computer (use a student network drive or a USB
drive)
3. Create a new project named “MyJavaProject” as shown in the text book on page 22.
4. Create a new package in that project named “lab1”.
5. Create a new class named “MyFirstProgram”. Select modifiers : public and tick to create
method stub “public static void main(String[] args). Tick to generate comments

6. Following the examples in the text book from page 24, edit your class so that it contains code
as follows, in addition to comments generated by Eclipse:
Package lab1;
public class MyFirstProgram
{
public static void main(String[] args)
{
System.out.println("My Java Program Running!");
}
}

CRICOS Provider No. 00103D ITECH2306 Agile Coding Laboratory Exercises Week 1 Page 1 of 5
7. Run your program and observe the console output.

8. Edit your code so that the console output is changed to read “My Java Program is running well
today”. Save and run your program to test it.
9. Add in the following line of code:
System.out.println(“My name is yourname);

10. Note the compiler error, the red circle with a x indicates that you have an error on the line
entered.

Add in the missing double quote “ after yourname


Save and run your program.

11. Work through exercise 3.1 in your text book, page 35. Enter the code as shown on page 36
into your program. (Note: your package name will be lab1 not com.introjava.chapter3)

CRICOS Provider No. 00103D ITECH2306 Agile Coding Lab 1.docx Page 2 of 5
12. Add the following code into your program and note the results:
int a = 5;
int b = 8;
float f = 8.0f;
boolean c = true;
boolean d = false;

System.out.println("b value is " + b);


System.out.println("b/2 value is " + b/2);
b++;
System.out.println("b value is " + b);
System.out.println("b/2 value is " + b/2);
System.out.println("f value is " + f);
System.out.println("f/2 value is " + f/2);
f++;
System.out.println("f value is " + f);
System.out.println("f/2 value is " + f/2);

13. In the eclipse editor, similar to shown below, double click in the left margin next to one of the
lines of code beginning with System.out.println. A blue dot will appear as shown in line 26 and
28 below.

14. Now run the program again in debug mode by clicking on the bug

The program when it runs will load in debug mode and when it executes, it will pause on the
line that has the blue dot (a break point).

CRICOS Provider No. 00103D ITECH2306 Agile Coding Lab 1.docx Page 3 of 5
Below is a screen shot of eclipse in debug mode. Each variable is shown and it’s value. Using
the “step into” option (F5) you can execute step by step each line of code.

The screenshot below shows the eclipse window at the time just after the line f++; was
executed. The value of f changed and is shown (highlighted in yellow). The debugger gives us
insight into variables during execution of the program. It is very useful when you are trying to
find run-time errors in your code.

CRICOS Provider No. 00103D ITECH2306 Agile Coding Lab 1.docx Page 4 of 5
15. Read http://blog.thefirehoseproject.com/posts/best-team-tactics-to-write-software/
16. Read https://www.agilealliance.org/agile101/the-agile-manifesto/
17. https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
18. Make an entry into your online learning journal in moodle, In that entry, write about 3 things
you have learnt in ITECH2306 so far.

B. Learning about GitHub


1. Complete the Hello World GitHub Guide - https://guides.github.com/activities/hello-world/
2. Complete the example in GitHub How to avoid a merge conflict tip sheet available in Topic one
section of Moodle.

C. Homework exercises for this week


1. From text book complete ex 3.2 page 42
a. Create a class with a ‘main’ method.
b. In ‘main’, calculate the fuel consumption of a car that just cost $72.00 to fill up at $1.80 a
litre after going 390 km since it was last filled with fuel. Use variables to store the fillCost,
the pricePerLitre and kmTravelled.
Use the calculations:
litresUsed = fillCost / pricePerLitre
kmPerLitre = kmTravelled / litresUsed.
c. Display the number of kilometres travelled per litre.

CRICOS Provider No. 00103D ITECH2306 Agile Coding Lab 1.docx Page 5 of 5

You might also like