Sunday
December 21, 2014

Homework Help: Computers(Java Programming)

Posted by Elaine on Tuesday, September 8, 2009 at 12:35am.

Service Class:

Lottery

Write a Lottery class that simulates a lottery. The class should define an array of five integers named lotteryNumbers. The constructor should use the Random class (see the Java API) to generate a random number in the range of 0 to 50 for each element on the array such that each element contains a unique value. The class's match method should accept an array of five integers that represents a person's lottery picks and compares the array elements to the lotteryNumbers array. The method is to return the number of matching digits. For example, the following shows a randomly generated lotteryNumbers array and the user's array with sample numbers stored in each.

lotteryNumbers array

17 24 19 21 33

When the user's picks are

24 20 19 17 6

the match method returns 3 since 24, 19, and 17 are found within the lotteryNumbers array.

When the user's picks are

33 17 5 2 8

the match method returns 2 since 33 and 17 are found within the lotteryNumbers array.

When the user's picks are

11 6 15 24 0

the match method returns 1 since only the number 24 was found within the lotteryNumbers array.

In addition, the class should define a toString method which returns a copy of the lotteryNumbers array in an easy to understand String format.

Class UML diagram:

Lottery

- lotteryNumbers : int[]
+ match(int []) : int
+ toString() : String



Client Application:

Demonstrate the Lottery class in an application that generates an instance of the Lottery class and then allows the end user to check one or more tickets against the generated lottery numbers. The client application should allow the end user to enter five numbers, which are stored in an array; there is no need to verify the input values. The program should display the lottery numbers and the number of digits of the end user's ticket that matched. If all of the digits match, display a message proclaiming the user a grand prize winner. Any number of lottery tickets may be checked.

Sample run of the application:

Enter your lottery ticket numbers:
24
20
19
17
6


The lottery numbers were 17, 24, 19, 21 and 33.

You matched 3 numbers!

Do you have another ticket to check? (Y or N): Y

Enter your lottery ticket numbers:
11
6
15
24
0


The lottery numbers were 17, 24, 19, 21 and 33.

You matched 1 numbers!

Do you have another ticket to check? (Y or N): Y

Enter your lottery ticket numbers:
21
19
24
33
17


The lottery numbers were 17, 24, 19, 21 and 33.

You matched all 5 numbers! You're the winner of the Grand Prize ... An exclusive, all expense paid trip to AACC. This trip includes a walking tour from east campus to west campus, a tour of the CALT building, and a front row parking space for an entire day!!! Congratulations!

Do you have another ticket to check? (Y or N): N






NOTES:

1.You will be developing TWO classes: the Lottery class and the Client class. The Client class contains the main method and should be named Lab1.
2.There should be no I/O performed in the Lottery class. All interaction with the end user should be done in the Client class.
3.Since the data of the Lottery class is generated by the constructor and can not be changed, accessor and mutator methods for lotteryNumbers are not defined.
4.The Lottery class should be documented using Javadocs. Javadocs are not needed for the client class, although your name should be included within comments at the top of the program.
5.Adhere to the Style Guide for both classes.
6.The grand prize exists in your imagination only (have fun!)
7.Use an initial range of 0 - 9 for the lottery numbers while testing. You'll feel better while debugging!
Evaluation:

Classes must compile without syntax errors or will not be evaluated. This lab is worth 25 points. Points will be distributed as follows:

•Lottery class (18 points)
◦Use of an array of integers
◦Use of the Random class
◦Definition of methods that support the objectives of the class, including a match and toString method
◦Methods produce correct results
◦Methods contain no end-user I/O
◦Code aheres to the style guide
•Client class (6 points)
◦Supports communication with the end-user
◦Main method utilizes the Lottery service class to meet the objectives of the application
◦Code aheres to the style guide

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

stu - An individual with utility function U(X) = X2 bought Lottery A and Lottery...
mathematics - the theoretical probability of winning the lottery is 1/1,000,000,...
maths - lisa won the lottery she used 1/2 of her lottery win to buy a house she ...
Computer Science - Write a Class to represent one of the following items. Note ...
Computer Sci Help pls - Write a Class to represent one of the following items. ...
Programming - Here is the question that I need help to write the code for the ...
programming - a) Define a Cat class. A Cat has name. Define two constructors, ...
Programming - I need your help to write a program using visual basic 2010 for ...
java programming - Create a program that will generate lottery numbers for the ...
java programming - I have to make two classes, one is to import a file and ...

Search
Members