Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Object-oriented programming A practical homework that is solved in the application Eclipse IDE for java developers. Code in Java. Please explain how the code was

Object-oriented programming

A practical homework that is solved in the application Eclipse IDE for java developers.

Code in Java. Please explain how the code was written

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Specification For this assignment you will write a program that plays a rather simplistic Lucky Vending Machine. This section specifies the required functionality of the program. Only a text interface is required for this program; however, more marks will be gained for a game that is easy to follow with clear information/error messages to the player. The aim of the Lucky Vending Machine is to simulate a physical vending machine commonly found in shopping malls, where a player inserts some coins, pulls a handle and wins a random prize (or no prize). You program will display a menu which allows the player to select various options to simulate the various vending machine operations. The "prizes" are decided by the computer (the vending machine) generating a random number between 1-5, with each number representing a particular prize (see prize table in the Program Logic section below). To "win" a prize, the player will need to guess correctly the number generated by the computer. The prizes are worth between $1050, and each guess will cost the player between $15. Each time the player chooses to play (ie. doing a "Guess A Prize"), he ** is charged between $15, depending on what he wants to win (see prize table). The program will keep a record of all the prizes he has won, the total worth of the prizes, and how much money he has spent. At any point, the program can print out these statistics. For this assignment, the program will only handle ONE player at any one time. However, the player can be changed while the program is executing. ** for the rest of the document, "he" will be taken to mean "he/she". Program Logic The Lucky Vending Machine begins with a welcome message followed by a menu with the following options : \begin{tabular}{l} Welcome to the Lucky Vending Machine \\ ========================= \\ (1) Set Up New Player \\ (2) Guess A Prize \\ (3) What Have I Won So Far? \\ (4) Display Game Help \\ (5) Exit Game \\ Choose an option: \\ \hline \end{tabular} Option (1) asks the user to enter a name for the "player". The player's name must not be blank. If this option is chosen again after a player has already been set up, a "new" player is created (ie. with a new name, no prizes, $0 spent). Note that the "new" player replaces the "old" player - ie. there is only ever one player at any one time. Option (2) simulates a lucky guess operation. The computer generates a random number between 1-5. It then asks the player what prize he would like to win by trying to guess that number. The rules are : If the player guesses wrongly, he wins nothing and loses the money (\$1-5). For the purpose of this assignment, the "prizes" are simply implemented as Strings. After each play, the computer records the prize, its worth, and the player's spending. If the user enters a number which is less than 1 , or more than 5 , it should be rejected, and he does not lose any money. Examples of some typical inputs/outputs (including some invalid inputs) for Option (2) : Option (3) displays some statistics about the current player's prizes (and worths) and total amount spent, such as : Option (4) displays some brief instructions regarding game play. It must at least inform the player of the rules of play (see prize table under Option (2) above) Option (5) exits the program. All player statistics should be cleared. Additional Notes : The menu should be displayed repeatedly, until the user chooses Option (5). Inputs other than 1-5 should be rejected, and an error message printed. If the user chooses Options (2) or (3), before a player has been set up, an appropriate error message should be printed. Your program must deal with invalid values entered by the user in a sensible manner. For both Options (2) \& (3), the outputs can be formatted in many different ways. Discuss with your tutor regarding how you should implement these in your program. Program Design Your program must demonstrate your understanding of the object-oriented concepts and general programming constructs presented in the unit. The data type of each field must be chosen carefully with reference to the requirements of the program described in the preceding sections and you must be able to justify the choice of the data type of the fields. You may want to include comments in the class to explain any assumption made. Basic validation of values for fields and local variables should also be implemented. You should not allow an object of a class to be set to an invalid state. You should include appropriate constructor(s) for each class, and accessor/mutator methods for all the attributes. You class design should include at least these classes (or some similar classes) : Game Player LuckyGuessGenerator Discuss with your tutor what attributes/behaviours are suitable for these classes, and how they interact with each other. You may make the following assumptions: - a Game object will be responsible for displaying the menus, accepting user responses, and performing the requested operations. It will make use of 1 Player object and 1 LuckyGuessGenerator object. - a Player object will remember his own name, what prizes he has won (\& their total worth), and how much he has spent. For the purpose of the assignment, you can just store all the prizes as a string containing all their names, separated by spaces, eg. "Book DVD Mouse Book DVD Book" - these mean he has won 6 prizes so far - a LuckyGuessGenerator object will be used to generate a number between 1-5. This is used by the program to generate the random number for the player to guess

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Evolution Of Audit Thought And Practice

Authors: T. A. Lee

1st Edition

0367502097, 978-0367502096

More Books

Students also viewed these Accounting questions