Lab Worksheet 2: Using Github, Download Starter Code, Edit The Code

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ITECH2306 AGILE CODING

Lab worksheet 2
Using GitHub, download starter code, edit the code
The first exercise this week requires you to access the GitHub Classroom to download some starter code. In
today’s exercise, you will modify this code in Eclipse.
1. There are separate handouts available in Moodle titled “Overview of Git and GitHub” and
“Registering for and using a GitHub repository and the GitHub Classroom”. You will find these
resources helpful in order to complete today’s lab worksheet. First thing today, register for
GitHub.
2. In the workshop, the modelling of a Person object was discussed. Based on that discussion
and on the brief partial requirement statement provided below, answer the questions listed.
“A city council is looking for a new computer system in which to keep a register of all rate
payers in the council area. Each rate payer will be one person (i.e. no joint ownership by
multiple people). For each person, the system will store their address within the council
boundaries. The address will be stored in one text field containing the postal address e.g. “75
Boundary street, SomeSuburb”. The postcode will be stored in a separate field. In another
separate field, the council will pre-fill the name of the city. There will be an optional field of the
Person’s telephone number.”
a. List attributes you think would be relevant to add to the Person class that will be used
to model a Person in the new system
b. List methods you think are needed in your Person class. For each method, state
whether that method should be public or private.
3. Enter the GitHub classroom. The assignment link in GitHub classrooms is provided in Moodle
– GitHub classroom invitation for lab 2. This week, you will create an individual repository to
do your lab work. Next week, you will create a team in the GitHub classroom to work with
another student. You may join an existing team or create a new team. (Teams will contain at
most 2 students).
When you enter that URL, you will see something similar to the following screen if you have
already registered with the classroom.

Click to accept the assignment.

CRICOS Provider No. 00103D ITECH2306 Agile Coding Laboratory Exercises Week 2 Page 1 of 3
If you haven’t already registered with the classroom, you need to associate your GitHub
account with your student email address in the classroom. To join the classroom, find your
student email address in the list of students and click on that email address.

You should then receive a message saying “You are ready to go!” with a link to where your
assignment has been loaded into a new repository. The repository is likely to be named
something like https://github.com/ITECH2306FedUni/prefix-lab2-yourname. This is the URI for
your repository.
4. Follow the separate handout (Using Eclipse IDE to interface with GitHub repository) from page
7 to page 11 to download and import the provided starter code from the GitHub classroom and
load it into a new local repository in Eclipse. Then you are ready to start editing your code.
5. Read the following excerpt taken from the requirement statement developed by council:
“Each person who is a rate payer in the council is entitled to register one animal as a Pet. The
person will be registered as the owner of that animal. For each animal, the name of the animal
will be stored in the system as well as the breed and age of the animal. The age will be stored
as a string containing the date of birth in DD MMM YYYY format.”
a. Add a new attribute to the Person class to represent the Animal. Insert the new
variable declaration on a new line to follow the code String address :
Animal pet ; // associate a pet that is an Animal object with the Person
b. List attributes that are needed on an Animal class that will be used to create an
Animal object for each pet owned.
c. List methods that are needed in the Animal class.

CRICOS Provider No. 00103D ITECH2306 Agile Coding Lab 2 updated 202007.docx Page 2 of 3
6. Edit your Person and Animal classes to include the attributes you have listed in 2. And 5.
7. Add a new constructor into your Person class as follows:
Person (String _address, String _name, String _postcode)
{
this.setAddress(_address);
this.setName (_name);
this.setPostcode (_postcode);
}

8. Add a new method to your Person class to add a pet:


void addAPet(Animal _pet) {
this.pet = _pet;
}

9. Edit your main method so that you create a new animal object:
Animal myPet = new Animal(); // create a new Animal object
10. Assign the pet myPet to be owned by Person p. Add the following line of code to your main:
p.addAPet(myPet);

11. Save and run your code to test it. No output is created so there is nothing to confirm it is
working.
12. Run your code in debug mode and check that the variables all have appropriate values.
13. How else could you check that your code is working? (Hint: using toString)
14. Commit your saved code and push the new changes back to your GitHub repository using the
Team> Commit option as described on page 12 of the handout.
15. Make an entry into your online learning journal in Moodle, In that entry, write about 3 things
you have learnt in ITECH2306 so far.

Homework exercises for this week


1. From text book complete ex 4.1 page 54
a. Create a class with a ‘main’ method.
b. In ‘main’, generate a random integer between 1 and 10 (inclusive)
c. Using an ‘if’ statement, work out if the random number is odd or even
d. Write a message to the console that displays both the random integer and whether it is an
odd or an even number
2. Complete the assessable individual online review exercises in Moodle by the end of this week.

CRICOS Provider No. 00103D ITECH2306 Agile Coding Lab 2 updated 202007.docx Page 3 of 3

You might also like