Practical Coding in Java

Learn to write and validate your own code

Darren Kessner, PhD

(revised September 1, 2025)

Previous: Circle

Coding Exercises: Classes and Objects

Person

Write a Person class that includes the following:

Also write a PersonTest class that instantiates some Person objects and demonstrates that the functions are working properly.

ScoreKeeper

Write a ScoreKeeper class that includes the following:

Write a ScoreKeeperTest class that instantiates a ScoreKeeper object and tests its functions.

Magic Eight Ball

Write a MagicEightBall class that includes the following:

Write a MagicEightBallTest class that instantiates a MagicEightBall object and asks it some important questions.

Rectangle

Write a Rectangle class that includes the following:

Be sure to include a test class to demonstrate that your Rectangle class functions all work properly.

Bonus Challenge: Vector

Write a Vector class that represents a two-dimensional vector \(\vec{v} = \left<x, y\right>\). Include the following:

Make sure to write a test class to verify that your functions are all doing what you expect.


Next: