HarshHC / OOP-2020-2021

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DT228/DT282 Object Oriented Programming 2020-2021

Resources

Contact the lecturer

Assessments

  • Assignments

  • Week 11 Lab Test 20%

  • Week 12 Assignment Submission - 30%

  • End of Year exam - 50%

Previous Years Lab Tests

Week 1 - Introduction

Tutorial

Lab

Learning outcomes

  • Set up Java, Visual studio code and the Java Extensions
  • Fork the repo, configure the upstream remotes
  • Write your first Java code using command line tools
  • Test out Visual Studio Code

Part 1 - Installing Java

Install the software you will need for this module and set up your path to the Java Development Kit. This document explains how to do it.

Part 2 - Forking the repo

Firstly fork this repository by clicking the fork button above, so that you get your own copy of the course repo to work on this semester. Now create a new empty folder on your computer somewhere right click on the folder and choose git bash here. Alternatively you can start the bash and cd to the new folder. To clone the repository for your fork:

git clone https://github.com/YOURGITUSERNAME/OOP-2020-2021

Replace YOURGITUSERNAME with your github username. You can also copy the URL to the repo from your browser and paste it into the console. To paste into the bash on Windows is right click. You can use Cmd + C, Cmd + V on the Mac.

Now cd into the repo and check the origin and upstream remotes are set up correctly

cd OOP-2020-2021
git remote -v

You should see something like this:

origin  https://github.com/YOURGITUSERNAME/OOP-2020-2021 (fetch)
origin  https://github.com/YOURGITUSERNAME/OOP-2020-2021 (push)
upstream  https://github.com/skooter500/OOP-2020-2021 (fetch)
upstream  https://github.com/skooter500/OOP-2020-2021 (push)

If you don't see the upstream remote, you can set it up by typing

git remote add upstream https://github.com/skooter500/OOP-2020-2021

You can read more about forking a git repository and setting up the upstream remote in this article

Once the upstream is setup, you will be able to push code to your own repo and also keep it up to date with the master branch of the changes I make each class.

If you already forked the repo before the lab, you may need to update your master branch from my master branch to get the changes I made:

git fetch
git checkout master
git pull upstream master

Part 3 - Compiling & running Java

To compile and run the Java code in the src folder, you should type:

cd java
javac src/ie/tudublin/*.java -d bin
java -cp bin ie.tudublin.Main

You should see

Hello world
Misty
TopCat
Garfield
Garfield

On the terminal. If you do, then congratulations! You have successfully compiled and run your first Java program using the command line tools. Now create a branch to store your changes today. Best not to modify the master branch so you can keep it up to date with my changes:

git checkout -b lab1

Use an editor (like Visual Studio code or notepad++) to open up the files in the folder src/ie/tudublin and study them to see if you can figure out what's happening. Modify the code as follows:

  • Make a private int field on the Cat class called numLives.

  • Write public accessors for the field (see how I did this for the name field on the Animal class)

  • Set the value of this field to 9 in the Cat constructor

  • Write a method (functions are called methods in Java) on the Cat class called kill. It should subtract 1 from numLives if numLives is > 0 and print the message "Ouch!". If numLives is 0, you should just print the message "Dead"

  • Create a new instance of the Cat class like this

    Cat ginger = new Cat("Ginger");
  • In the Main class in a loop, call kill on ginger until ginger is dead.

  • Compile and run your program until you have no bugs and you get the desired output.

Commit and push your changes:

git add .
git commit -m "killing the cat"
git push --set-upstream origin lab1

The "--set-upstream origin lab1" option is only required the first time you commit onto a new branch. After that you can just type "git push"

Part 4 - Hello Processing

Checkout the branch HelloProcessing by typing

git checkout HelloProcessing from the bash

In Visual Studio Code, choose File | Open Folder and open the OOP-2020-2021 folder. Press F5 and if all goes well, you should see something that looks like this:

Hello Processing

If you are done check out the references for classes, packages, constructors and accessors below.

Also! Read the first three chapters of the git manual.

Lecture

Some assignments from previous years:

YouTube

YouTube

YouTube

YouTube

YouTube

YouTube

About

License:MIT License


Languages

Language:Java 66.0%Language:Shell 34.0%