Soe Than

Department of Mathematics and Computer Science

Virginia Military Institute, Lexington, VA 24450


Vending Machine assignments provide good exercise for CS1 students in developing object oriented programs. These assignments have been around for many years, but most of them employ textual interfaces to test the students’ implementations. A version using a graphical user interfaces with animation is presented in this paper. This assignment can be utilized in two different phases.


While students are studying object-oriented programming, they are asked to write three classes: CashHandler – to handle coin deposits and returns, ProductDispenser – to dispense one product, and VendingMachine – to simulate a vending machine consisting of a CashHandler object and a small number of ProductDispenser objects. After these classes have been implemented, students can integrate them with my GUI program that operates the VendingMachine through buttons and displays the action of dispensing with an animation. Later when students are studying Graphical User Interfaces, they are asked to write their own GUI programs with the animation, to simulate their vending machines. Based on my experience, asking students to do textual unit testing of their classes, and/or asking them to display information about the objects in the application helped them in debugging. The assignment and supporting files can be downloaded at



Students write three classes to simulate a vending machine.


OOP in Java, Arrays, GUI and Animation in Java.


CS1 and any course where Java GUI is introduced.


Low to moderate.  As the UML diagrams for these classes are provided, most students can complete each phase in about six hours.


As students integrate their implementations with the realistic looking GUI program, students become engaged.


In this version, CashHandler does not handle different denomination of coins. A better version can be assigned as an extra credit work.


OOP, UML diagram, Arrays (for Phase I), Java GUI (for Phase II)



Notes to Instructors

In this assignment, I asked students to implement three classes which will be integrated with my other classes to simulate a vending machine.  The assignment document is VendingMachineAssignmentDescription.pdf.

Student Files

The files distributed to students are:

            VendingMachineAssignmentDescription.docx, and


The details about the contents of the zip file are explained in the assignment description document.  Source codes of my class files are not distributed to students.  One exception is the driver application class (that contains the main method), because some IDE (like jGrasp) may need it to run the application.

These two files are placed in a folder called StudentFiles and that folder is compressed as

Instructor Files

The source codes of the class files which are distributed to students are placed in a folder named IncompleteVendingMachineWithSource and that folder is compressed in a zip file.  The source codes of the three classes are in that folder; but these classes are not functional. 

The source codes of a completed (working) project are placed in another folder named CompletedVendingMachineWithSource and it is also compressed in a zip file.  These are just for your reference.

These two zip files together with the assignment description document are placed in a folder called InstructorFiles and that folder is compressed as