Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: IB Computer Science HL Option D - OOP Notes
Description: Notes for IB Comp Sci Option D, including SL/HL..

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


Outline
Tuesday, 4 October 2016

6:44 PM

D—Object-oriented programming
D
...
2 Features of OOP (4 hours)
D
...
4 Advanced program development (15 hours)

OOP Page 1

General Notes
Thursday, 20 October 2016

10:00 AM

20/10/16
Package - group of classes
Java has libraries and packages (e
...
Swing which then contains a series of classes to do something)
Standardised version of Java design
MVC -> Model View Controller Package System Design Method
Model

View

Controller

Data
-> Underlying information which the
product uses
-> Class(es)
Create objects
• Attributes (Variables)
• Behaviours (Methods)

UI
-> User Interaction with product
-> Deals with displaying output &
accepting input

Backbone
-> The class(es) which do the work
-> Contains algorithms to deal with the user input &
output

Model says how to display

The actual display

Controller does calculation then sends to model

Java allows to store variables about a particular object and only allows a particular class to have access
Data is anything you can change, add to, remove, etc
...
dot notation (e
...
substring)
name
...
java -> addBooking()
Customers
...
java
CustomersForm
...

Controller
Application
...
java

The class which runs the rest of the product
...
main method)

View

Mainform
...
app
...
setvisible(true)
Open
...
secondform
...
setvisible(false) (this - current class)

26/10/16

...
getText()

...
setText("" + var);

27/10/16
D
...
variablename

1/11/16
D
...
2
Constructor method - exact same name as class (Customer)
Attributes of customer - age, name, (variables)
Making customer object
Customer Cus1 = new Customer();
Class Name, Object Name, Assignment, Reserved Word, Constructor Method (in order from L to R)
To get the age would use getAge()
To set the age would use setAge() (known as accessors and mutators)
Customers
|
Cus 1
Cus 2
Cus 3
Cus 4
Each customer has an age and name
In order to construct object a constructor is needed
To create multiple instances of same object - put it in a loop
Polymorphism

2/11/16
Customer
Name: JTextField
Gender: Jradio or JCombo
Date of Birth: 3JCombo
Email: J TextField
Re-Enter Email: J TextField
Phone No: JTextField
Address: JTextField
Username: JTextField
Password: JPassword
Re-enter Password: JPassword
Model

View

Controller

Customer RegisterForm Open
Application
Customer Class
String username
String password
String firstName
String lastName
String email
String gender
byte dobDay
byte dobMonth
short dobYear
String phone
String address
Question on exam to construct MVC
constructor method - method that is called when creating a new instance
public class Customer {
variables (private)
public Customer (String username, String password, String firstName…)
this
...
password = password;

OOP Page 3

Formal parameters are required to be in particular
orders (in same order as GUI and written)

public setUsername (String Username) {
this
...
username = username;
}
public String getUsername() {
return username;
}

this
...
toString()
ArrayList

8/11/16
Array - static (fixed length)
ArrayList - dynamic (no length)
Serial - A stream of data
Serialisation
Import first, then serialise/deserialise

9/11/16
Literal String - double quotations
Use it when you want words, sentences, parts of sentences
Whole group of methods for strings because its an object
Initialising - variables
Instantiation - Objects
Invoking - Methods
Model -> Customer data (Customer class)
Inside customer class, created private variables
Controller contains two classes
Open contains main method and creates instance of application
Application -> created forms we needed
Array contains indices - can say customer ID is a certain number
CustomerForm
Find
Input int
Pass to Application -> findCust
-> customerList
...
g
...
getFirstname();
Then setText() to CustomerForm

10/11/16
For loop each time check to see if username and password are the same and logged in as
Validation & Verification
Validation - checking if 2 values match
Verification - checking a value with a value that is already stored
Question ON EXAM

28/02/17
Simple
Self-explanatory
Specific
On the board:
Structured
Efficient
Fast
Useful

OOP Page 4

Useful
Competent
Consistent
Resourceful
Concise
Predictable
Understandable
Mr Madigan:
Code should be robust (tough or hard to break)
(e
...
if you put in wrong values it doesn't break)
Code must deal with unexpected inputs
Code should be adaptable
Changeable
Code must be able to change overtime to meet changing needs
Related: portable
Code should be reusable
The same code is usable in different contexts
OOP achieves these things through:
Encapsulation
Class WaitingRoom {
Patient[] waitinglist;
}

Class Patient {
private int priority;
private int arrivalTime;
}
private void reorder() {
waitinglist[i]
...
getPriority;
}
public int getPriority() {
return this
...

There are two methods in the boss object
...
That is, the characters of
output string alternate between the two input strings
...


3/10/17
Task: Write a method in java which takes a linked list as a parameter and returns a linked list which is the reverse

14/11/17
C is a collection containing (in order):
1, 17, 42, 3, 9, 16, 6, 8, 11
What is the output of the algorithm?
17
42
9
16
8
11

OOP Page 5

Write a method in your java LinkedList class which:
has a precondition that the Linked List is SORTED
...

(In other words, your post-conditions is that 'data' is in the list, and the list is still sorted
...


Create an instance of class or object - instantiation
String name = new String
LHS - Creating an instance of string called name (object of type string)
RHS - instantiates it and tells what object it instantiates (instantiation)

Delegate package
...
java

Open
...
Contains all algorithms to run
the product and to open the GUI
...
java
The first GUI form which
opens in the product

If it contains main method, it is static (therefore class is static)
Create instance of static class called application
Application will contain everything else

OOP Page 7

D
...
1
...

• Class is template of objects

• An object is an abstract entity that contains attributes (variables) and behaviours (methods)
...


D
...
2 Distinguish between an
object (definition, template or
class) and instantiation
...
The object can then be run anywhere in the program
...

• On the Right Hand Side, it instantiates the object and tells the program what object to instantiate
...
An object can be a
variable, function, or data structure
...

• Instantiation is the creation of a real
instance or particular realization of
an abstraction or template such as a
class of objects or a computer
process
...
wikispaces
...
1
...
1
...


• You need class
• Attributes
• And Actions/Methods
• Has a/ is a/ uses


How to make UML diagrams:

Class Name
-variablename: variable type
-partners: ArrayList
+methodname (parsename: variabletype): returntype
+Airline (data : String[]) : void
- private
+ public

D
...
4 Interpret UML diagrams
...
1
...


An object can be decomposed into a bunch of smaller objects
...


D
...
6 Describe the relationships
between objects for a given
problem
...
1
...


Dependencies occur when one object uses another object
...

This can increase maintenance for the programmer because if one object updates, then they will have to
update the other objects that interdepend on the object
...
1
...

D
...
9 Explain the need for
different data types to represent
data items
...
1
...


A parameter is the name of the information that is used in a method, function or procedure
...


OOP Page 8

D
...

Topic

Class Notes

Organised Notes

D
...
1 Define the term
encapsulation
...
The scope of data
should be confined to the object
which stores that data
...
The variables can only be
accessed from other classes by using the get and set methods
...


D
...
2 Define the term
inheritance
...
The subclass extends the
on another class it can inherit its
superclass
...
We say that the
• Extends is a keyword that creates a subclass
subclass extends the superclass
...
g
...
2
...


• A variable is polymorphic if it can
• Polymorphism is the ability to create a variable, a function, or an object that has more than one form
...
The different
when the method is called by other code (or even the super class's code) your method is executed instead
...

• Doesn't need to worry about if…

D
...
4 Explain the advantages of
encapsulation
...

• A class can have total control over
what is stored in its fields
...
A class
can change the data type of a field
and users of the class do not need
to change any of their code
...
tutorialspoint
...
htm

• Advantages of private variables:
Only allows access to methods
that access it (other classes
don't have access)
The variables can't be
changed from other classes
• Encapsulation limits dependencies
in code
...

D
...
5 Explain the advantages of
inheritance
...
2
...


• Key benefit inheritance minimize
the amount of dupe code in
application sharing common codee
amongst several subclasses
...

• Reusability
• Inheritance allows for similar classes
to reuse the same methods without
retyping the same code
...
The code in the class
does not have to be changed
...
Other classes that may conflict with it can't access
it
...


Advantages of inheritance
• Inheritance minimizes the amount of duplicate code by sharing the same code with several subclasses
• Inheritance makes the code more flexible because multiple classes can inherit from a common superclass
and the code can be used wherever
...


• Polymorphism allows external code Advantages of polymorphism:
- Polymorphism allows external code to call the methods of the superclass without needing to know the
to call the methods of the
superclass without needing to know
implementation details of a method
- Allows methods that perform similar or closely related functions to be accessed through a common name
the implementation details of the
method
...
2
...

objects
• Saves time by copy/pasting already
made code to the program
• Restricts certain methods and
actions if you're not using them
• Examples of java libraries
Java
...
lang
...
math
Java
...
awt
Many more…

D
...
8 Describe the
disadvantages of OOP

Advantages of encapsulation
• The variables of a class can be made read-only or write-only

• It can be difficult to initially
comprehend concepts such as
inheritance and polymorphism
• It can be difficult and unnecessary

OOP Page 9

Advantages of libraries of objects
• Using libraries provide an easy method of reusing objects
...

IB Question:
Explain why it is convenient to store data as objects
...
g
...

- It can be difficult and unnecessary to use objects to solve particular problems
- For some problems, the amount of code necessary is much larger with OOP
...
See toy example to compare
Java and Python
...

- Risk of object dependencies

D
...
9 Discuss the use of
programming teams
...
Everyone needs to know exactly what their
development of narrow
narrow expertise
methods/classes must do and how they interact with other
expertise
- It works well with object oriented
classes and methods
...
Everyone
needs to know exactly what
their methods/classes must
do and how they must
interact with other classes and
methods
...
2
...


https://www
...
com/techno
logy/blog/4-benefits-of-objectoriented-programming
• Modularity - breaking something
down to bits
• Easier debugging because each
small part can be debugged and
perfected separately
...

• Independent testing!
• Allows the same code to be reused
many times without retyping it
• Several programmers can be
working on separate
modules/methods/classes at the
same time
Explain why modularity allows
____ and why it's a good thing

OOP Page 10

Modularity is breaking something down into bits
...


D
...
3
...


• Class - a template for objects

• A class is a template for objects which defines the attributes and behaviours of objects within the
class
...

• An identifier is a name that refers to a variable, method, class, package
...
It can only be used
within a method
...


Anything called
...
)

• Without an object, class can't be
used
• Can have multiple objects in
class but cannot have the
same identifier
• Class is a template that outlines
things about an object and thing
that object can do

...

• Another logical error is dividing by 0
• Identifier
• Label for a variable, object, method,
class
• Anything that has a name that can
be referenced has an identifier
• Identifier are ways in which
something can be referenced (class,
object, variable, method, all need
identifiers)
• Need to be able to understand what
that thing is
• Primitive - the simplest form of data
(storing)
• 8 primitive data sizes with bit sizes
Boolean - 1 bit

Byte - 8 bit
Char - 16 bit or 7/8 bit (code in java
and have ability to have multiple
languages to code in)

Short - 16 bit (whole number)
Int - 32 bit
Float - 32 bit
Long - 64 bit
Double 64 bit

• Parameter variable - variable used
within a method's parameters
• Formal parameter - data type that is
expected within method signature
• Public void Customer (String name)
{ } Customer ("Hello");
• Parameter - data types and names
that are used within methods
D
...
2 Define the terms: method, • Method - behaviour of object
accessor, mutator, constructor, • Algorithm that is called upon an
signature, return value
...

• Constructor
• Accessor - method that retrieves a
variable's value (e
...
getAge())
• Mutator - sets the value (e
...
setAge())
• Signature
Method signature is method name
and formal parameters combined

• A method is an algorithm that is invoked on an object which causes an object to do something
• A constructor method is method that is invoked when creating a new instance of an object
...

• An accessor is a method that retrieves a variable's value
• A mutator is a method that sets a variable's value
• A signature is a method name and formal parameters combined
• A return value is a value that is returned after a method is called
• Validation is checking if two values match
• Verification is checking a value with another value that is already stored
Accessor:

• Return value
Value that is returned after a method
is called
Uses key word return

OOP Page 11

Mutator:

Mutator:

D
...
3 Define the terms: private,
protected, public, extends,
static
...
3
...


• Modifier: reserved word shown
before a method name
• Modifiers proceeds both variables
and methods
• Can be used for both variables and
methods
• Public, private, protected, static
• Public
-> Accessible anywhere in the
product
• Private
-> Accessible only in the class it has
been created in
• Protected
-> Only accessible within package it
has been created in
• Static
-> Cannot be changed
-> Doesn’t have to be instantiated
MainForm() mainform = new
mainform()
• Extends - key word that is used to
signify the class that is inheriting

• Public is when a variable or method is accessible anywhere in the product
• Private is when a variable or method is accessible only in the class it has been created in
• Protected is when a variable or method is only accessible within the package it has been created
in
...
It does not have to be instantiated
• Extends is a key word that is used to signify the class that something is inheriting

• (Byte) 8 Bits -> 28 -> 256 -> (-128 +
127)
• IB Question: Why do we use
unicode?

• ASCII is a character encoding scheme that represents English characters as numbers
...

• Unicode uses 16 bits and has code written in most of the languages of the world
...
[3 marks]
- Static means that the variable is declared once only;
- Static variable is a class variable not re-declared in each object;
- And not each time an object is created
- The variable represents the number of times an object is created;
- And hence is a total of what the object represents

• In IB Exam
ASCII and Unicode are two different formats used for representing characters
...
Outline the principal difference between ASCII and Unicode in representing characters
...
Discuss the social significance of providing Unicode instead of ASCII code for representing
characters in different software
...
3
...
3
...
3
...

D
...
6 Construct code examples
related to selection statements
...
3
...


Repetition (or reiteration) is implemented in code in the form of loops
...


D
...
8 Construct code examples
related to static arrays
...

• For example: integer array, string array
• Can also consist of objects

Characteristics of static arrays:
• Fixed length/size which is determined upon initialization of the array
• Size will not change during the execution of the program
• Memory allocated to array cannot be increased or reduced
• If more memory allocated than requirement, memory space will be wasted
...
3
...


Internationalization is enabled by:
• Support for the display of international fonts and text
• Support for language and local specific needs, such as data and time formatting
• Support for different keyboard layouts, as well as complex characters and symbols
• Support for a variety of written languages with the use of Unicode, allowing the
representation and handling of text in most languages
• Support for user language auto detection and tailoring of the user experience according to it
• Support for global deployment of software that includes localized content

D
...
10 Discuss the ethical and
moral obligations of
programmers
...
4 Advanced program development
7:47 PM

Topic

Class Notes

Organised Notes

D
...
1 Define the term recursion
...
This allows the function to be repeated
several times, since it calls itself during its execution
...
4
...


Advantages and disadvantages of recursion:
Recursive versions of many methods may execute more slowly than the iterative equivalent
because of the added layers of the additional method calls
...
Because storage for parameters
and local variables is needed, it is possible that the stack could be exhausted
...

The main advantage to recursive methods is that they are clearer and simpler than their
iterative counterparts
...

Students should also understand that recursive algorithms are rarely used in practice
...
4
...

D
...
4 Trace recursive algorithms
...
4
...


A reference is an address that indicates where an object's variables and methods are stored
...


D
...
6 Construct algorithms that
use reference mechanisms
...
4
...

D
...
8 Describe applications of
lists
...
4
...

D
...
10 Construct list algorithms
using object references
...
4
...


JETS (Java Examination Tool Subset) is a subset of the Java language used for IB Option D
Computer Science Examinations
...

The IB wants students to become better at algorithmic thinking and not become expert coders
at java
...


D
...
12 Trace algorithms using
the implementations described
in assessment statements D
...
9–
D
...
11
...
4
...



- Libraries provide implementations of common algorithms and data structures
...

- They avoid the need to re-invent or re-implement things which have already been done by
someone else
...
4
...


Stack:
- LIFO structure
...

- The element removed is always the one that has been on the stack for the shortest time
...
First In, First Out
- The item removed will be the one that has been in the queue for the longest
...

- Nodes with 0 children are called leaves
...

The data in every node in the right subtree of ‘ ’ is greater than or equal to the
data in ‘ ’
...


OOP Page 14

This allows for extremely efficient storage and retrieval of data
...
4
...


Meaningful Identifiers
Comments
Indentation and other whitespace
All of these conventions make code more READABLE for humans
...


OOP Page 15

Glossary
Variable scope refers to the accessibility of a variable
...

A Runtime Error is an error that causes the program to crash when there appears to
be nothing wrong with the program
...


OOP Page 16

IB Questions
Explain two ethical issues which should be taken into account when working on a project
...

(In White) One ethical issue is that the code needs to function correctly
...

Another ethical issue is that code that has been taken or modified from another source needs to be
acknowledged
...


OOP Page 17

Algorithms in Java
BubbleSort:
public static void bubbleSort(int[] arr) {
int n = arr
...
out
...
out
...
out
...
out
...
out
...
out
...
addHead(item);
}

pop()
public int pop() {
int item = peek();
list
...
peek();
}

isEmpty()
public boolean isEmpty() {
return list
...
addHead(item);
}

dequeue()
public void dequeue() {
list
...
size());
}

isEmpty()
public boolean isEmpty() {
return list
Title: IB Computer Science HL Option D - OOP Notes
Description: Notes for IB Comp Sci Option D, including SL/HL..