Home CPSC 330

Singleton Exercise


To get experience using the Singleton pattern.


For this exercise, you will turn a regular class into a singleton class that only allows one instance to be created.

This program contains a class called "Deck" for representing the set of 52 cards. It's possible that we want the same deck of cards to be available to all parts of our program, and that we only want one deck to be created. This would make it a candidate for being a singleton.


  1. Download the SingletonExercise.java file.
  2. Change the Deck class into a singleton using the method discussed in class.
  3. Change the main method to get the Deck instance rather than creating a new object.
  4. The program should simply print all 52 cards in random order.


When your program is done, email the code to ifinlay@umw.edu.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.