CSIS 3701: Advanced Object-Oriented Programming Programming Assignment 3: Designing Java Classes Due Friday, March 4 Introduction This exercise is meant to introduce you to designing your own Java classes (including constructors and methods). You will be implementing: A simple “guessing game” class that generates a random number between 1 and some limit, and keeps track of whether the player has correctly guessed it, what numbers they have previously guessed, and how many guesses they have made. A very simple main command line application that runs a guessing game for numbers between 1 and 10, prompting the player for guesses until they correctly guess the number, using this class. The GuessApp Application You are to create a simple GuessApp class (stored in the file GuessApp.java). It should run a simple “guessing game” using the above GuessLogic class. More specifically, it should have a main function that does the following: Constructs a GuessLogic object (which will generate the random correct answer). Loops until the player has correctly guessed the answer. Within the loop, prompting the player for their next guess, using a Scanner object to input their guess. Determines whether the user has put in a “legal value” (that is, one between 1 and 10, and one that has not already been guessed). After the loop, printing the number of guesses the player made. Note that “illegal guesses” (numbers not between 1 and 10 or guessed before) do not count towards that total number of guesses). For example: The GuessLogic Class You are to implement a simple support class that controls the logic of the guessing game (stored in the file GuessLogic.java). Note that I am not specifying the methods and constructors for that class (except for the toString method below). These are the main design decisions for this assignment! However, I do have the following requirements: Separating the Logic and the User Interface All of the logic for the game must be handled within GuessLogic class. In other words, the GuessApp class is not to keep track of the correct answer, the number of guesses made, the numbers previously guessed, or whether a guess is legal. On the other hand, the GuessApp class is responsible for all of the I/O. In other words, the GuessLogic class is not to print anything (except possibly for the purposes of debugging). Other Requirements You are to validate that no methods would cause your object to enter an illegal state or to crash in some way. Hint: what could happen if the application were to attempt to pass a number that is not between 1 and 10? Even though the application is for a game with numbers between 1 and 10, your game logic should be expandable to other limits (such as guessing numbers between 1 and 5, 1 and 100, etc.). Hint: consider overloading the constructor for the GuessLogic class. You are to provide a toString method in your GuessLogic class that returns the state of the GuessLogic object (that is, all of its member variables) as a single string. Suggestions I do suggest that you think about providing methods for the following: Allowing the user to “guess” a given number. Finding whether the number has been guessed. Finding the number of guesses made. Finding whether a guess is legal. Finding whether a guess has already been made. However, these just suggestions – there are actually many different ways to design a solution for this problem. Documentation As with any program, your source code should be well documented! For this assignment, this includes the following: For the GameLogic class, make sure that you put a “header” at the top of each method that briefly explains what it does (particularly in terms of the member variables). For the GameApp application, make sure that you explain how it works, particularly in terms of manipulating the GameLogic object. As always, this is a significant part of your grade. What to Turn In Post the source code for the GameLogic and GameApp classes to the Blackboard site for the course. You can find the source code for your classes on your computer under the Documents/NetBeansProjects directory.
© Copyright 2026 Paperzz