CompSci 308
Spring 2025
Advanced Software Design and Implementation

Lab Coding Exercise: Making Classes and Learning OpenJFX

This exercise is intended for you to practice the basic GIT workflow commands (addcommit, and push), get used to OpenJFX, and create a Java class.

Submitting Your Work

There will not be an official submission for this exercise, instead show your progress to the Teaching Team during lab to get feedback.

Specification

Complete as many of the following tasks using your forked version of the lab_bounce project (they will all help prepare you for the Breakout project):

  1. Make the bouncer "bounce" off of the right "wall" by reversing its direction
  2. Make a second bouncer that starts in the same position as the first and moves to the left, at whatever speed you want, and bounces off the left "wall" by reversing its direction
  3. Make both bouncers bounce back and forth off of both walls
  4. Make a Bouncer class (or whatever name you prefer)
    • Give it instance variables (basically whatever variables you copied when creating the second ball to separately keep track of its values)
    • Give it a constructor (basically a way to initialize those instance variables when the object is created)
    • Give it appropriate methods (basically one corresponding to code you wrote that refers to those variables in each method of the Example class)
  5. Make two instances of that class as instance variables in the Example class
    • Replace all instance variables you moved to the new class with just these two variables
    • Replace the code that refers to those variables with calls to the methods you created in the new class
  6. Make each bouncer start at a different place, with a different size, move in different directions (with both X and Y changes), and bouncing off of all the walls (including the corners)
    • change the Bouncer's constructor as needed
    • feel free to use fixed values or use Java's Random class
  7. Make any number of bouncers, with different initial properties, that bounce around
    • definitely use Java's Random class!

For each task, you may make any changes to the code you think are warranted (functional, organizational, or creating new classes). After you think you have completed each task, make a GIT add and commit with an appropriate comment, so there should be at least 6 commits in your project history. After every two commits, push your changes up to Gitlab so your online repository reflects the work you have done today. Don't forget to make sure all of your code is consistently formatted before pushing!

Resources

OpenJFX is a framework for creating Graphical User Interfaces (GUIs) that can run across a wide variety of platforms. As a modern framework, it replaces Java's (very old) Swing GUI framework and uses standard technologies that make it well-suited for creating visually-intensive applications, such as games, simulations, and data visualizations. While it contains many components for organizing and interacting with complex GUIs, for this lab and the first project, you only need to focus on the concepts in this example code: drawing, animating, and interacting with shapes and images (you will learn more with each project). Learning OpenJFX will help you learn any other modern GUI framework, for the web, mobile, or on the desktop.

Version control is a way to manage the many changes that occur to your files over time, but that simple idea changes everything! It allows you to revisit previous versions of your code, work with different versions at the same time, and work in teams and track who made which changes. At its best, version control is like a journal that you use to track major, and minor, events in your project. At its most practical, it is a backup system that prevents you from losing significant work. Knowing how to use a source control system will be an invaluable tool for you going forward, perhaps personally or even potentially for changes in laws, but especially in a team setting.

Using source control well takes practice and a little bit of command-line savvy (we do not suggest using visual GIT tools, even the one built into IntelliJ, until you are confident in your version control skills).