SlideShare a Scribd company logo
1 of 51
Download to read offline
Ticket Machine Project(s)
Produced by: Dr. Siobhán Drohan
(based on Chapter 2, Objects First with Java - A Practical
Introduction using BlueJ, © David J. Barnes, Michael Kölling)
Department of Computing and Mathematics
http://www.wit.ie/
Understanding the basic contents of classes
Topic List
• Data types:
– primitive
– objects
• Demo of naïve ticket machine
• Inside classes:
– fields
– constructors
– methods:
• accessors
• mutators
– assignment statements
• Demo of better ticket machine
• Making choices: conditional statements (if)
Data Types
• Java uses two kinds of types:
– Primitive types
– Object types
• A field’s data type determines the values it
may contain, plus the operations that may be
performed on it.
Primitive Data Types
• Java programming language supports eight primitive data
types.
• A primitive type is predefined by the language and is named
by a reserved keyword.
• A primitive type is highlighted red when it is typed into BlueJ
e.g.
Primitive Data Types (for whole numbers)
Type Byte-
size
Minimum value
(inclusive)
Maximum value
(inclusive)
Typical Use
byte 8-bit -128 127 Useful in
applications
where memory
savings apply.
short 16-bit -32,768 32,767
int 32-bit -2,147,483,648 2,147,483,647 Default choice.
long 64-bit -
9,223,372,036,
854,775,808
9,223,372,036
,854,775,807
Used when you
need a data type
with a range of
values larger
than that
provided by int.
Primitive Data Types (for decimal numbers)
Type Byte-
size
Minimum value
(inclusive)
Maximum value
(inclusive)
Typical Use
float 32-bit Beyond the scope of this
lecture .
There is also a loss of
precision in this data-type
that we will cover in later
lectures.
Useful in
applications
where memory
savings apply.
double 64-bit Default choice.
Primitive Data Types (others)
Type Byte-size Minimum value
(inclusive)
Maximum value
(inclusive)
Typical Use
char 16-bit 'u0000'
(or 0)
'uffff'
(or 65,535).
Represents a
Unicode character.
boolean 1-bit n/a
Holds either true
or false and is
typically used as a
flag.
http://en.wikipedia.org/wiki/List_of_Unicode_characters
Default values
Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char 'u0000'
String (or any object) null
boolean false
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Object Types
• All types that are not primitive are object
types.
Primitive fields
Primitive field
Object Type
Object Types
• Includes classes from standard java library e.g.
String:
private String color;
• Also includes user defined classes e.g. Square,
Circle, etc.
Topic List
• Data types:
– primitive
– objects
• Demo of naïve ticket machine
• Inside classes:
– fields
– constructors
– methods:
• accessors
• mutators
– assignment statements
• Demo of better ticket machine
• Making choices: conditional statements (if)
Ticket machine – an external view
• Exploring the behavior of a typical ticket
machine (e.g. the naive-ticket-machine):
– Machines supply tickets of a fixed price.
• How is that price determined?
– How is ‘money’ entered into a machine?
– How does a machine keep track of the money that
is entered?
Demo
Exploring the behaviour of the
naïve ticket machine
Ticket machines – an internal view
Interacting
with an object
gives us clues
about its
behavior.
Ticket machines – an internal view
Returns a whole number (int) representing
the balance or price of the ticket. Both
methods have no parameters; they don’t
need any information to do their task.
Allows the user to insert money
(an int value parameter) into the
ticket machine. Doesn’t return
anything (it is void).
Prints the ticket to the console window.
Doesn’t return anything (it is void).
Topic List
• Data types:
– primitive
– objects
• Demo of naïve ticket machine
• Inside classes:
– fields
– constructors
– methods:
• accessors
• mutators
– assignment statements
• Demo of better ticket machine
• Making choices: conditional statements (if)
Ticket machines – an internal view
• Looking inside allows
us to determine how
that behavior is
provided or
implemented.
• All Java classes have a
similar-looking
internal view.
Basic class structure
public class TicketMachine
{
//Inner part of the class omitted.
}
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
The outer wrapper of
TicketMachine
The contents of a class
Instance fields
• Variables store values for an
object.
• These variables are typically
called instance fields /
instance variables.
• Instance fields define the
state of an object i.e. the
values stored in the instance
fields.
public class TicketMachine
{
private int price;
private int balance;
private int total;
//Further details omitted.
}
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Instance fields
In BlueJ, you can view the
object state by either:
• right clicking on the
object and selecting the
Inspect option OR
• double clicking on the
object.
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Instance fields
public class TicketMachine
{
private int price;
private int balance;
private int total;
//Further details omitted.
}
private int price;
visibilityaccess modifier
type
variable name
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Constructors
• A constructor builds an
object and initialises it to a
starting state.
• They have the same name
as their class.
• Their access modifier is
public.
• They store initial values in
the instance fields; they
often receive external
parameter values for this.
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Methods
• Methods
implement the
behaviour of
objects.
• Java uses methods
to communicate
with other classes.
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Method signature
The method signature consists of a method name and
its parameter type list e.g.
getPrice()
insertMoney(int amount)
The method body encloses the method’s statements
i.e. the code block for the method
Method Body
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Method return types
Methods can return
information about an
object via a return value.
The void just before the
method name means that
nothing is returned from these
methods.
void is a return type and must
be included in the method
signature if your method
returns no information.
The int before the method
names mean that a whole
number is returned from
these methods. A method can
only have one return type.
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Return types
In BlueJ, when you
call a method that
returns data, a screen
will pop up with the
returned data e.g.
• the getPrice()
method returns the
whole number, 30.
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Types of Methods
Now that we have
covered method
signature and return
types, we are going
to look at two
specific “types” of
methods i.e.
• Accessor methods
• Mutator methods
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Accessor methods
• Accessor methods
return information
about the state of an
object.
• Typically they:
– contain a return
statement (as the
last executable
statement in the
method).
– define a return type.
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Accessor/getter methods
• ‘Getter’ methods are a specific type of
accessor method.
public int getPrice()
{
return price;
}
return type
method name
parameter list
(empty)
start and end of method body (block)
return statement
visibility modifier
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Mutator methods
• Mutator methods
change (i.e. mutate!)
an object’s state.
• Typically they:
– contain an
assignment
statement
– take in a parameter
to change the object
state.
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Mutator/setter methods
• ‘Setter’ methods are a specific type of
mutator method.
public void insertMoney(int amount)
{
balance = balance + amount;
}
return type
method name parameter
visibility modifier
assignment statementfield being mutated
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Getters/setters
• For each instance field in a class, you are
normally asked to write:
– A getter
– A setter
• However, depending on the design of your app,
you may wish to not provide getters/setters for
specific fields (more on this later!)
public class ClassName
{
//Instance Fields
//Constructors
//Methods
}
Assignment Statement
Values are stored in
instance fields (and
other variables) via
assignment
statements.
Assignment Statement
• A variable stores a single value, so any previous value
is lost.
• Assignment statements work by taking the value of
what appears on the right-hand side of the operator
and copying that value into a variable on the left-
hand side.
Syntax variable = expression;
Example price = ticketCost;
Topic List
• Data types:
– primitive
– objects
• Demo of naïve ticket machine
• Inside classes:
– fields
– constructors
– methods:
• accessors
• mutators
– assignment statements
• Demo of better ticket machine
• Making choices: conditional statements (if)
Reflecting on the naïve ticket machine
• The behavior is inadequate in several ways:
– No checks on the amounts entered.
– No refunds.
– No checks for a sensible initialisation.
• How can we do better?
– We need more sophisticated behavior.
demo
Briefly explore the more sophisticated
behaviour of the:
better ticket machine
Note: we will look at this in more detail
a subsequent lecture.
Topic List
• Data types:
– primitive
– objects
• Demo of naïve ticket machine
• Inside classes:
– fields
– constructors
– methods:
• accessors
• mutators
– assignment statements
• Demo of better ticket machine
• Making choices: conditional statements (if)
Adding checks by making choices
Naïve ticket machine
Better ticket machine
Adding checks by making choices
Naïve ticket machine
Better ticket machine
Conditional Statement Syntax (1)
if(perform some test)
{
Do these statements if the test gave a true result
}
‘if’ keyword
boolean condition to be tested
actions if condition is true
Conditional Statement Syntax (2)
if(perform some test) {
Do these statements if the test gave a true result
}
else {
Do these statements if the test gave a false result
}
‘if’ keyword
boolean condition to be tested
actions if condition is true
actions if condition is false
‘else’ keyword
Conditional Statement Syntax (3)
if(condition1…perform some test)
{
Do these statements if condition1 gave a true result
}
else if(condition2…perform some test)
{
Do these statements if condition1 gave a false
result and condition2 gave a true result
}
else
{
Do these statements if both condition1 and
condition2 gave a false result
}
Some notes on the if statement
• An if statement IS a statement; it is only
executed once.
• When your if statement only has one
statement inside it, you do not need to use
the curly braces.
• For example, both of these are the same:
if (balance >= price)
{
System.out.print(“Sufficient funds”);
}
if (balance >= price)
System.out.print(“Sufficient funds”);
if (balance >= price)
{
System.out.print(“Sufficient funds”);
}
Some notes on the if statement
• The semi-colon (;) is a statement terminator.
• One is circled in the code example below:
• Your if statement does not need a statement
terminator.
public TicketMachine(int ticketCost)
{
price = ticketCost;
balance = 0;
total = 0;
}
Improving the constructor
public TicketMachine(int ticketCost)
{
if (ticketcost > 0)
{
price = ticketCost;
}
else
{
price = 20;
}
balance = 0;
total = 0;
}
Note: in the constructor
set the field to a default
value if invalid data was
entered…maybe our
tickets will have a default
cost of 20 if an invalid
ticketCost is entered.
Improving the setter / mutator
public void setBalance(int amount)
{
if (amount > 0) {
balance = amount;
}
}
Note: The validation done at constructor level
must be repeated at setter level for that field.
However, in setter methods do not update the
field’s value if invalid data was entered (notice
how the “else” part of the “if” is not there).
Study aid: can you answer these questions?
• Java has two kinds of types…what are they?
• How many primitive types does Java have? Can you
name them?
• Can you give an example of an object type?
• What are instance fields? What does object state
mean?
• What is the job of a constructor? How do you
recognise one i.e. method signature?
• What is a method signature? What is a method
body?
Study aid: can you answer these questions?
• What are accessor methods and how would you
recognise them in your source code?
• What are mutator methods and how would you
recognise them in your source code?
• What are assignment statements? Can you write a
statement that declares a String variable called
name and updates its contents to Joe Soap?
• What are if statements? How do you write them?
• What are boolean expressions?
Questions?
Department of Computing and Mathematics
http://www.wit.ie/

More Related Content

What's hot

Advanced c#
Advanced c#Advanced c#
Advanced c#saranuru
 
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITKPankaj Prateek
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKPankaj Prateek
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed OverviewBuddha Tree
 
Unidad o informatica en ingles
Unidad o informatica en inglesUnidad o informatica en ingles
Unidad o informatica en inglesMarisa Torrecillas
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphismmcollison
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS ImplimentationUsman Mehmood
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOPMuhammad Hammad Waseem
 

What's hot (13)

SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
 
Unidad o informatica en ingles
Unidad o informatica en inglesUnidad o informatica en ingles
Unidad o informatica en ingles
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphism
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP
 
Aspdot
AspdotAspdot
Aspdot
 
Lecture 1 - Objects and classes
Lecture 1 - Objects and classesLecture 1 - Objects and classes
Lecture 1 - Objects and classes
 

Similar to O flecture 03

Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in javaagorolabs
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
 
Learning core java
Learning core javaLearning core java
Learning core javaAbhay Bharti
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_typesAbed Bukhari
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4dplunkett
 
C++ training
C++ training C++ training
C++ training PL Sharma
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3Sónia
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Code and Design Smells. Are They a Real Threat?
Code and Design Smells. Are They a Real Threat?Code and Design Smells. Are They a Real Threat?
Code and Design Smells. Are They a Real Threat?GlobalLogic Ukraine
 
implementing oop_concept
 implementing oop_concept implementing oop_concept
implementing oop_conceptAmit Gupta
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4sotlsoc
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 

Similar to O flecture 03 (20)

Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Ch03
Ch03Ch03
Ch03
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Classes
ClassesClasses
Classes
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 
C++ training
C++ training C++ training
C++ training
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Session 09 - OOPS
Session 09 - OOPSSession 09 - OOPS
Session 09 - OOPS
 
Code and Design Smells. Are They a Real Threat?
Code and Design Smells. Are They a Real Threat?Code and Design Smells. Are They a Real Threat?
Code and Design Smells. Are They a Real Threat?
 
Classes1
Classes1Classes1
Classes1
 
implementing oop_concept
 implementing oop_concept implementing oop_concept
implementing oop_concept
 
17515
1751517515
17515
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 

More from Fajar Baskoro

Generasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxGenerasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxFajar Baskoro
 
Cara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterCara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterFajar Baskoro
 
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanPPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanFajar Baskoro
 
Buku Inovasi 2023 - 2024 konsep capaian KUS
Buku Inovasi 2023 - 2024 konsep capaian  KUSBuku Inovasi 2023 - 2024 konsep capaian  KUS
Buku Inovasi 2023 - 2024 konsep capaian KUSFajar Baskoro
 
Pemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxPemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxFajar Baskoro
 
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
Executive Millennial Entrepreneur Award  2023-1a-1.pdfExecutive Millennial Entrepreneur Award  2023-1a-1.pdf
Executive Millennial Entrepreneur Award 2023-1a-1.pdfFajar Baskoro
 
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptxFajar Baskoro
 
Executive Millennial Entrepreneur Award 2023-1.pptx
Executive Millennial Entrepreneur Award  2023-1.pptxExecutive Millennial Entrepreneur Award  2023-1.pptx
Executive Millennial Entrepreneur Award 2023-1.pptxFajar Baskoro
 
Pemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxPemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxFajar Baskoro
 
Evaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimEvaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimFajar Baskoro
 
foto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahfoto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahFajar Baskoro
 
Meraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaMeraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaFajar Baskoro
 
Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetFajar Baskoro
 
Transition education to employment.pdf
Transition education to employment.pdfTransition education to employment.pdf
Transition education to employment.pdfFajar Baskoro
 

More from Fajar Baskoro (20)

Generasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxGenerasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptx
 
Cara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterCara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarter
 
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanPPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
 
Buku Inovasi 2023 - 2024 konsep capaian KUS
Buku Inovasi 2023 - 2024 konsep capaian  KUSBuku Inovasi 2023 - 2024 konsep capaian  KUS
Buku Inovasi 2023 - 2024 konsep capaian KUS
 
Pemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxPemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptx
 
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
Executive Millennial Entrepreneur Award  2023-1a-1.pdfExecutive Millennial Entrepreneur Award  2023-1a-1.pdf
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
 
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
 
Executive Millennial Entrepreneur Award 2023-1.pptx
Executive Millennial Entrepreneur Award  2023-1.pptxExecutive Millennial Entrepreneur Award  2023-1.pptx
Executive Millennial Entrepreneur Award 2023-1.pptx
 
Pemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxPemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptx
 
Evaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimEvaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi Kaltim
 
foto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahfoto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolah
 
Meraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaMeraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remaja
 
Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan Appsheet
 
epl1.pdf
epl1.pdfepl1.pdf
epl1.pdf
 
user.docx
user.docxuser.docx
user.docx
 
Dtmart.pptx
Dtmart.pptxDtmart.pptx
Dtmart.pptx
 
DualTrack-2023.pptx
DualTrack-2023.pptxDualTrack-2023.pptx
DualTrack-2023.pptx
 
BADGE.pptx
BADGE.pptxBADGE.pptx
BADGE.pptx
 
womenatwork.pdf
womenatwork.pdfwomenatwork.pdf
womenatwork.pdf
 
Transition education to employment.pdf
Transition education to employment.pdfTransition education to employment.pdf
Transition education to employment.pdf
 

Recently uploaded

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Recently uploaded (20)

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

O flecture 03

  • 1. Ticket Machine Project(s) Produced by: Dr. Siobhán Drohan (based on Chapter 2, Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling) Department of Computing and Mathematics http://www.wit.ie/ Understanding the basic contents of classes
  • 2. Topic List • Data types: – primitive – objects • Demo of naïve ticket machine • Inside classes: – fields – constructors – methods: • accessors • mutators – assignment statements • Demo of better ticket machine • Making choices: conditional statements (if)
  • 3. Data Types • Java uses two kinds of types: – Primitive types – Object types • A field’s data type determines the values it may contain, plus the operations that may be performed on it.
  • 4. Primitive Data Types • Java programming language supports eight primitive data types. • A primitive type is predefined by the language and is named by a reserved keyword. • A primitive type is highlighted red when it is typed into BlueJ e.g.
  • 5. Primitive Data Types (for whole numbers) Type Byte- size Minimum value (inclusive) Maximum value (inclusive) Typical Use byte 8-bit -128 127 Useful in applications where memory savings apply. short 16-bit -32,768 32,767 int 32-bit -2,147,483,648 2,147,483,647 Default choice. long 64-bit - 9,223,372,036, 854,775,808 9,223,372,036 ,854,775,807 Used when you need a data type with a range of values larger than that provided by int.
  • 6. Primitive Data Types (for decimal numbers) Type Byte- size Minimum value (inclusive) Maximum value (inclusive) Typical Use float 32-bit Beyond the scope of this lecture . There is also a loss of precision in this data-type that we will cover in later lectures. Useful in applications where memory savings apply. double 64-bit Default choice.
  • 7. Primitive Data Types (others) Type Byte-size Minimum value (inclusive) Maximum value (inclusive) Typical Use char 16-bit 'u0000' (or 0) 'uffff' (or 65,535). Represents a Unicode character. boolean 1-bit n/a Holds either true or false and is typically used as a flag. http://en.wikipedia.org/wiki/List_of_Unicode_characters
  • 8. Default values Data Type Default Value (for fields) byte 0 short 0 int 0 long 0L float 0.0f double 0.0d char 'u0000' String (or any object) null boolean false http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
  • 9. Object Types • All types that are not primitive are object types. Primitive fields Primitive field Object Type
  • 10. Object Types • Includes classes from standard java library e.g. String: private String color; • Also includes user defined classes e.g. Square, Circle, etc.
  • 11. Topic List • Data types: – primitive – objects • Demo of naïve ticket machine • Inside classes: – fields – constructors – methods: • accessors • mutators – assignment statements • Demo of better ticket machine • Making choices: conditional statements (if)
  • 12. Ticket machine – an external view • Exploring the behavior of a typical ticket machine (e.g. the naive-ticket-machine): – Machines supply tickets of a fixed price. • How is that price determined? – How is ‘money’ entered into a machine? – How does a machine keep track of the money that is entered?
  • 13. Demo Exploring the behaviour of the naïve ticket machine
  • 14. Ticket machines – an internal view Interacting with an object gives us clues about its behavior.
  • 15. Ticket machines – an internal view Returns a whole number (int) representing the balance or price of the ticket. Both methods have no parameters; they don’t need any information to do their task. Allows the user to insert money (an int value parameter) into the ticket machine. Doesn’t return anything (it is void). Prints the ticket to the console window. Doesn’t return anything (it is void).
  • 16. Topic List • Data types: – primitive – objects • Demo of naïve ticket machine • Inside classes: – fields – constructors – methods: • accessors • mutators – assignment statements • Demo of better ticket machine • Making choices: conditional statements (if)
  • 17. Ticket machines – an internal view • Looking inside allows us to determine how that behavior is provided or implemented. • All Java classes have a similar-looking internal view.
  • 18. Basic class structure public class TicketMachine { //Inner part of the class omitted. } public class ClassName { //Instance Fields //Constructors //Methods } The outer wrapper of TicketMachine The contents of a class
  • 19. Instance fields • Variables store values for an object. • These variables are typically called instance fields / instance variables. • Instance fields define the state of an object i.e. the values stored in the instance fields. public class TicketMachine { private int price; private int balance; private int total; //Further details omitted. } public class ClassName { //Instance Fields //Constructors //Methods }
  • 20. Instance fields In BlueJ, you can view the object state by either: • right clicking on the object and selecting the Inspect option OR • double clicking on the object. public class ClassName { //Instance Fields //Constructors //Methods }
  • 21. Instance fields public class TicketMachine { private int price; private int balance; private int total; //Further details omitted. } private int price; visibilityaccess modifier type variable name public class ClassName { //Instance Fields //Constructors //Methods }
  • 22. Constructors • A constructor builds an object and initialises it to a starting state. • They have the same name as their class. • Their access modifier is public. • They store initial values in the instance fields; they often receive external parameter values for this. public class ClassName { //Instance Fields //Constructors //Methods }
  • 23. Methods • Methods implement the behaviour of objects. • Java uses methods to communicate with other classes. public class ClassName { //Instance Fields //Constructors //Methods }
  • 24. Method signature The method signature consists of a method name and its parameter type list e.g. getPrice() insertMoney(int amount) The method body encloses the method’s statements i.e. the code block for the method Method Body public class ClassName { //Instance Fields //Constructors //Methods }
  • 25. Method return types Methods can return information about an object via a return value. The void just before the method name means that nothing is returned from these methods. void is a return type and must be included in the method signature if your method returns no information. The int before the method names mean that a whole number is returned from these methods. A method can only have one return type. public class ClassName { //Instance Fields //Constructors //Methods }
  • 26. Return types In BlueJ, when you call a method that returns data, a screen will pop up with the returned data e.g. • the getPrice() method returns the whole number, 30. public class ClassName { //Instance Fields //Constructors //Methods }
  • 27. Types of Methods Now that we have covered method signature and return types, we are going to look at two specific “types” of methods i.e. • Accessor methods • Mutator methods public class ClassName { //Instance Fields //Constructors //Methods }
  • 28. Accessor methods • Accessor methods return information about the state of an object. • Typically they: – contain a return statement (as the last executable statement in the method). – define a return type. public class ClassName { //Instance Fields //Constructors //Methods }
  • 29. Accessor/getter methods • ‘Getter’ methods are a specific type of accessor method. public int getPrice() { return price; } return type method name parameter list (empty) start and end of method body (block) return statement visibility modifier public class ClassName { //Instance Fields //Constructors //Methods }
  • 30. Mutator methods • Mutator methods change (i.e. mutate!) an object’s state. • Typically they: – contain an assignment statement – take in a parameter to change the object state. public class ClassName { //Instance Fields //Constructors //Methods }
  • 31. Mutator/setter methods • ‘Setter’ methods are a specific type of mutator method. public void insertMoney(int amount) { balance = balance + amount; } return type method name parameter visibility modifier assignment statementfield being mutated public class ClassName { //Instance Fields //Constructors //Methods }
  • 32. Getters/setters • For each instance field in a class, you are normally asked to write: – A getter – A setter • However, depending on the design of your app, you may wish to not provide getters/setters for specific fields (more on this later!) public class ClassName { //Instance Fields //Constructors //Methods }
  • 33. Assignment Statement Values are stored in instance fields (and other variables) via assignment statements.
  • 34. Assignment Statement • A variable stores a single value, so any previous value is lost. • Assignment statements work by taking the value of what appears on the right-hand side of the operator and copying that value into a variable on the left- hand side. Syntax variable = expression; Example price = ticketCost;
  • 35. Topic List • Data types: – primitive – objects • Demo of naïve ticket machine • Inside classes: – fields – constructors – methods: • accessors • mutators – assignment statements • Demo of better ticket machine • Making choices: conditional statements (if)
  • 36. Reflecting on the naïve ticket machine • The behavior is inadequate in several ways: – No checks on the amounts entered. – No refunds. – No checks for a sensible initialisation. • How can we do better? – We need more sophisticated behavior.
  • 37. demo Briefly explore the more sophisticated behaviour of the: better ticket machine Note: we will look at this in more detail a subsequent lecture.
  • 38. Topic List • Data types: – primitive – objects • Demo of naïve ticket machine • Inside classes: – fields – constructors – methods: • accessors • mutators – assignment statements • Demo of better ticket machine • Making choices: conditional statements (if)
  • 39. Adding checks by making choices Naïve ticket machine Better ticket machine
  • 40. Adding checks by making choices Naïve ticket machine Better ticket machine
  • 41. Conditional Statement Syntax (1) if(perform some test) { Do these statements if the test gave a true result } ‘if’ keyword boolean condition to be tested actions if condition is true
  • 42. Conditional Statement Syntax (2) if(perform some test) { Do these statements if the test gave a true result } else { Do these statements if the test gave a false result } ‘if’ keyword boolean condition to be tested actions if condition is true actions if condition is false ‘else’ keyword
  • 43. Conditional Statement Syntax (3) if(condition1…perform some test) { Do these statements if condition1 gave a true result } else if(condition2…perform some test) { Do these statements if condition1 gave a false result and condition2 gave a true result } else { Do these statements if both condition1 and condition2 gave a false result }
  • 44. Some notes on the if statement • An if statement IS a statement; it is only executed once. • When your if statement only has one statement inside it, you do not need to use the curly braces. • For example, both of these are the same: if (balance >= price) { System.out.print(“Sufficient funds”); } if (balance >= price) System.out.print(“Sufficient funds”);
  • 45. if (balance >= price) { System.out.print(“Sufficient funds”); } Some notes on the if statement • The semi-colon (;) is a statement terminator. • One is circled in the code example below: • Your if statement does not need a statement terminator.
  • 46. public TicketMachine(int ticketCost) { price = ticketCost; balance = 0; total = 0; } Improving the constructor public TicketMachine(int ticketCost) { if (ticketcost > 0) { price = ticketCost; } else { price = 20; } balance = 0; total = 0; } Note: in the constructor set the field to a default value if invalid data was entered…maybe our tickets will have a default cost of 20 if an invalid ticketCost is entered.
  • 47. Improving the setter / mutator public void setBalance(int amount) { if (amount > 0) { balance = amount; } } Note: The validation done at constructor level must be repeated at setter level for that field. However, in setter methods do not update the field’s value if invalid data was entered (notice how the “else” part of the “if” is not there).
  • 48. Study aid: can you answer these questions? • Java has two kinds of types…what are they? • How many primitive types does Java have? Can you name them? • Can you give an example of an object type? • What are instance fields? What does object state mean? • What is the job of a constructor? How do you recognise one i.e. method signature? • What is a method signature? What is a method body?
  • 49. Study aid: can you answer these questions? • What are accessor methods and how would you recognise them in your source code? • What are mutator methods and how would you recognise them in your source code? • What are assignment statements? Can you write a statement that declares a String variable called name and updates its contents to Joe Soap? • What are if statements? How do you write them? • What are boolean expressions?
  • 51. Department of Computing and Mathematics http://www.wit.ie/