Overview

A ticket machine with two ticket types, built in 2023 to practise the three ideas at the centre of object-oriented programming. You pick Standard (£10) or Student (£5), enter how many, and buy.

It is a small program. It is on this site because of what happened when I came back to it in 2026 and treated it like code someone else had handed me.


What it shows

  • Encapsulation. Ticket keeps its type, price and quantity private. Its setter refuses a quantity below one, so an invalid ticket can’t exist.
  • Inheritance. StandardTicket and StudentTicket extend Ticket and set only their own type and price. Quantity, total price and the text description come from the base class.
  • Polymorphism. The window, the printer and the machine all work with a plain Ticket. Adding a new ticket type needs one new class and no changes anywhere else.

What I found when I came back to it

  • The quantity was ignored. Buying three standard tickets showed “Price: £10.0”. Each subclass stored the quantity, but nothing ever used it.
  • Bad input crashed the button. An empty box or a word like “two” threw a NumberFormatException inside the click handler, and nothing appeared to happen.
  • The jar didn’t open the app. Its entry point printed “Ticket Machine System is running.” and exited.
  • There were no tests.

What changed

  • Quantity moved into Ticket, along with a getTotalPrice() method. That removed the copy in each subclass.
  • TicketMachine.parseQuantity turns what was typed into a number from 1 to 20 or a plain message (“Enter the quantity as a whole number, for example 2.”). An empty box means one ticket, matching its hint.
  • The machine keeps a running total of takings, shown under the button.
  • The jar’s entry point now opens the window.
  • JUnit tests cover the prices, totals, input checks and takings, and run on GitHub Actions on every push.

Brought up to date

  • It now runs on Java 25, the current long-term-support release, with JavaFX 25 and JUnit 6.
  • The window used to pick a ticket class by comparing the drop-down’s text with “Student”. The machine now keeps the list of ticket types and builds the right one, so the window never names a subclass and a new type is one class and one line.
  • 13 tests in all. Dependabot proposes dependency updates once a month.

I made the 2026 review and fixes with Claude, an AI assistant, as a pair programmer. Each logic fix comes with a test.

The demo video on this page shows the 2023 version, before these fixes.


Run it

Needs JDK 25 and Maven; Maven downloads JavaFX.

git clone https://github.com/mcneillium/Ticket-Machine-System.git
cd Ticket-Machine-System
mvn javafx:run   # opens the window
mvn test         # runs the tests

Tech stack

Java 25, JavaFX 25, Maven, JUnit 6, GitHub Actions, Dependabot.