
CSIS 110 – Lecture 3
Open BlueJ, Open my picture project.
Look at the various Picture classes developed by students and discuss them.
Last time we learned about
- two types of comments: single-line and multi-line
- the state of an object
- source code
- return values and return types
- using objects as parameters
[Ask some questions about the above]
Ticket Machines
Let’s think about a ticket machine that might exist in a subway or light rail station.
Tickets cost a certain amount of money, and you can press a button to get a ticket.
Load the ‘naïve-ticket-machine’ project into BlueJ. Remember to do a ‘save as’ to your
M: drive.
Now, create a ticket machine object. Look at the list of methods. Play around with this
for a few minutes to figure out what it does.
How does this ticket machine object differ from what you would expect a real-world
ticket machine to behave?
By playing with this, we’ve figured out that this Java ticket machine only behaves the
way we would expect it to when we enter the exact amount of money.
Parts of a class
The outer wrapper:
public class TicketMachine
{
...
}
The outer wrappers for most classes look similar – the main purpose is to give the class a
name and to enclose the class elements.
The inner parts
Inside the outer wrapper we define the fields, constructors, and methods that give
instances of the class their behavior.