INFO322/IAPP001
Applications
Programming
Tracy Quick Tracy.Quick@insearch.edu.au
Introduction
About IAPP001
Subject Outline, Attendance, Assignments, Misconduct
Basic Concepts
Object, Class, Abstraction, Encapsulation
Feature Visibility
Additional Concepts
Attributes, Methods
Accessors and Mutators
OO Reuse
Method
Object
Class
Style Guide
About IAPP001
Subject Outline
Event
Weighting
Assignment 1
30%
Due
Weeks 5-11
PartA(10%), Part B(10%), Part C(10%)
Prac Tests
(2 hour)
30%
Weeks 7,9
40%
Exam Week
Week 7(20%), Week 9 (10%)
Exam
(3 hour)
Assignments
Assignments are due on the date specified
No late submissions are accepted for ANY
assignment
As a rule, extensions are only given for exceptional
circumstances, general sickness is not grounds for
an extension assignments are given 2 weeks
before they fall due finish your assignments well
before they are due to avoid DNS grades
A maximum of 5 days are given as an extension,
usually, extensions granted are no more than 2
days.
Assignments
All assignments must be all your own work
Any copy and paste code will be viewed as
plagiarism, which will receive a DSN result
Most code on the internet is JavaScript. It does not
satisfy the OO requirements of this subject. It will
be viewed as plagiarism. This will result in a DNS
for all assessments.
If you engage a tutor to help you write your
assignment this is plagiarism. The assignment will
receive a DNS result.
About IAPP001
This course is very difficult
It builds on material from IPRG001 & IBRM001
It requires you to read material from text books
Missing lectures and tutorials will lead to
failure in this subject
If you are experiencing difficulties before week
6 you need to contact me ASAP!!
I am here to help you, but I cant help if you
dont do the work
Independent Study
This subject requires 4 hours per week
additional study (not including lectures &
tutorials)
OO Programming requires analysis, synthesis
and evaluation skills can only be learnt
through practice.
Put in the effort each week, learn the concepts,
apply them in the examinations/assignments
to pass the subject.
Missing Lectures & Tutorials
If you do miss a lecture you must read the
lecture notes and catch up ASAP contact me
if you have difficulties
If you do miss a tutorial you must complete the
tutorial work in your own time before the next
tutorial
Each tutorial builds on material from previous
tutorials and in some cases uses solutions from
previous tutorials as a launch point
Plagiarism
MOSS will be used to detect any misconduct
Used by most universities to detect plagiarism in
programming courses since 1994
DO NOT look at other students code, or
possess a copy of another students code.
Be careful when discussing the assignment with
other students
Discussing your solution (or approach) with another
student can lead to plagiarism
up to 10% of students receive misconduct hearings
because of illegal collaboration in this subject
Misconduct
Assignments must only use patterns and API
classes covered in this subject
Assignments that use other patterns or Java
classes will be scrutinised for misconduct
Dont try to buy assignments or get help from
external sources you will be caught.
All code must be written using BlueJ only
Dont use Eclipse or JBuilder unless you want to be
reported for misconduct
Alternative Assessment Test
Where an assignment is of questionable origin,
the student may be given an alternative
equivalent test under exam conditions.
The result of the alternative assessment test
will determine the grade given for that
assessment.
Failure to attend the alternative assessment
test will result in a DNS grade given for the
assessment.
Assignments
The assignment is your code, it is your
responsibility.
You must write every line yourself
do not use code from the internet
Keep it safe from prying eyes, dont lend your
usb or leave your computer unattended.
Please dont ask me to pre-mark your
assignment or critique your code.
Follow the rules and principles given
throughout the subject.
Review of Basic Concepts
Learning Outcomes
Students should be able to:
Describe the differences between an Object and a
Class
Describe how to use default and alternate
constructors
Describe how to use procedures and methods
Describe the 3 types of reuse in OO
Basic Concepts
Object
An object is the building block of 00 programming
An object can be a tangible thing in the real world
Examples: a pc, a desk, a pen, a student
Or a concept
Example: A student loan
It has attributes (state) and methods (behaviour)
A student has a name (state), a student ID (state), a sex
(state)
A student can take notes (behaviour), study (behaviour)
An object is a specific entity the student with ID
2113455 is an object
An object is also an instance of a class
Basic Concepts
Class
A class is like a template a framework.
It defines the properties and behaviour of its objects.
A student class describes the properties and behaviour of all
instances (objects) of the class ie a student object.
The Student class provides the variables (properties)
name
id
sex
wam
The Student class also provides the functions (behaviour)
takeNotes()
study()
Naming a Class
A class always starts with a Capital Letter eg
House, Student, Desk
If a class has a compound name then it is letter
cased eg BrickHouse, ComputerDesk,
LocalStudent
This allows us to always recognise a class in our
code
This is a Java convention and must be followed
Basic Concepts
Class Features:
A class has
constructor(s) - a way to create instances (objects)
Class ClassName() default constructor
Class ClassName(arg, arg) class constructor
attributes properties which contain an objects state
Type variableName
methods functions which determine an objects
behaviour using logic eg.
ReturnType methodName(arg, arg)
Type and ReturnType can be int, float, double, boolean,
String etc
Basic Concepts in OOP
Abstraction
Abstraction is the reduction of information
back to a basic concept.
A class is an abstraction of an object
Encapsulation
Encapsulation is the grouping of data and
behaviour together into distinct bundles
Data and behaviour is captured and held
(encapsulated) by an object.
Encapsulation/Abstraction Example
I had a white Maltese Terror called Billy, he was
desexed and was 11 years old.
Billy is an object - encapsulating the following:
State (or data):
Name: Billy
Sex: Male
Colour: White
Breed: Maltese Terrier
Age: 11
Spayed: Yes
Behaviour:
Bark he did lots of this !!!!
Eat
Sniff
Sleep he did lots of this too !!!
Abstraction Example
Here is the abstraction of Billy to the class Dog
Properties:
String name
String sex
String colour
String breed
int age
boolean spade
Behaviour:
bark()
eat()
sniff()
sleep()
Quick Quiz
Using Dog Code Example
What line number(s) contain:
The Class name
The default constructor
Another class constructor
The variable definitions for the class
Feature Visibility (Modifiers)
An attribute or method may be Public, Private
or Protected.
Private features are only visible to the class they
belong to and cannot be inherited.
Public features are visible to all classes and can be
inherited.
Protected features are visible to the class they
belong to and all its subclasses and can be
inherited more later.
Additional Concepts
Attributes
Instance variables defined by the class
Hold property states ie data for an object
The value of an attribute can change for each object
An attribute is created when the object is created.
Its scope is the class: it is visible anywhere in the class.
You can initialise the attribute (give it a value) in the
declaration; if you do not, Java gives it a default value.
Attribute declarations are executed before the
constructor.
Rule: Naming attributes
An attribute always starts with lowercase eg
height, name
A compound name is camelCased eg
familyName
Compound names should be used sparingly,
most attributes should have a single word
name
This is a Java convention and must be followed
Additional Concepts
Methods
Functions and procedures defined by the class
Contain repeatable steps to perform a task
Methods define behaviour of the objects of a
class
Functions return values, either by performing
calculations or they can just return the value of
an attribute they do not change anything
Procedures are used to change the value of an
attribute
Rule: Naming methods
A method always starts with lowercase eg
area(), volume()
A compound name is camelCased eg
familyName()
Compound names should be used sparingly,
most methods should have a single word name
(except accessors & mutators more later)
This is a Java convention and must be followed
Designing Methods
What does it do?
Method name
return type
structure sequence, selection, iteration
What do we have?
Attributes
other methods
What do we need?
parameters
Quick Quiz
Using Dog Code Example
How many attributes are there?
How many methods are there?
What is the signature of the first method?
What is the return type of the first method?
10
Accessors and Mutators
Special types of methods which either
return the value of an attribute (unchanged) Accessor
or change the value of an attribute Mutator
Accessor Example
Public String getName()
{ return name;}
where the name attribute is a String
Mutator Example
Public void setName(String newName)
{ name = newName;}
where name attribute is a String
Accessors and Mutators
What accessors could we have for the Dog
class?
What mutators could we have?
Quick Quiz
Using Dog Code Example
How do you create a dog object using the class
constructor
public Dog(String iSex, String iColour, String iBreed, int iAge, boolean iSpayed) ?
How do you call the bark() method?
11
OO Reuse
There are 3 types of reuse:
Method Reuse a method can be called
with different variables
Object-based Reuse an instance of a class
(an object) can be created many times
Class-based Reuse a parent class can be
inherited by many child classes more
later
Method Reuse
A method can be called many times
Dog billy = new Dog (M", "White", "Maltese Terrier", 11,
true);
System.out.println(billy.sleep());
System.out.println(billy.bark());
System.out.println(billy.sleep());
System.out.println(billy.eat());
System.out.println(billy.sleep());
sleep() method reused
Object Reuse
Many objects can be created from a class
Dog macca = new Dog ("M", "Tan", "Boxer", 4,
false);
System.out.println(macca.bark());
System.out.println(macca.eat());
System.out.println(macca.sleep());
macca and billy objects both created from
the Dog class
12
Data Types
So far you have seen a few data types in
IPRG001
Primitive data types eg int, double, boolean,
char etc
They are maroon in BlueJ, these are keywords
Class data types eg String, Scanner, Double
These are classes defined in the API (Java Class
Library)
When you create a new class in Java, you are
creating a new data type.
Classes and Data Types
The class name is the data type of an object
Dog is the data type of the Dog object macca
String is the data type of a String object
Scanner is the data type of a Scanner object
Eg Scanner in = new Scanner(System.in);
String entry = in.nextLine();
Objects Review
An object is an instance of a class
A constructor (default and/or class) creates an object
of a class
Here is an example of a constructor:
public Rental(int id, Customer customer)
{}
It takes an int and a Customer object as parameters
We call it like this:
Rental newRental = new Rental(1, newCustomer);
Where newCustomer is a Customer object, created by
a Customer constructor
13
Assigning Attributes
Parameters to a constructor usually set the
values of attributes for an object
It is done inside the constructor
public Rental(int id, Customer customer)
{ this.id = id;
this.customer = customer; }
this is a keyword in Java that refers to the
current object ie the object with datatype
Rental that is being created by the constructor
Assigning Attributes
We could have also done this
public Rental(int newId, Customer newCustomer)
{
id = newId;
customer = newCustomer;
}
Note: the parameters have different names to
the attributes, so we do not need to
differentiate between the attribute (of the
object) and the constructor parameter.
A format function
A common way to format a double to 2
decimal places is to use DecimalFormat
private String formatted(double amount)
{
DecimalFormat formatter =
new DecimalFormat("###,##0.00");
return formatter.format(amount);
}
DecimalFormat class belongs to java.text package, so
you need to use import java.text.*;
14
Style Guide
A ClassName starts with a capital letter eg Dog
A constant is capitalised eg RATE
A variable starts with a lowercase eg name
A method name starts with a lowercase eg sleep()
Names should be simple
Use real words not abbreviations
Add useful inline comments to methods, if needed
Attributes, variables and methods are camelCased
eg firstName
Homework
Download the revision exercises from the
Course Documents section on UTSOnline.
Unzip the file and complete the exercises by
writing the required code in the Exercise class.
A sample solution is given in the Solution class,
so that you can check how well you did.
Complete the Week 1 Revision Test before the
week 2 tutorial this will give you an idea of
how well prepared you are for IAPP001.
15