Programming Problem 1

searchcoilΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 1 μέρα)

280 εμφανίσεις

NAME:

STUDENT ID:

EXAM
USER
NO:


COMP241,
Fall
2003, Midterm 1

Programming Part

Two

q
uestions.

Total: 60 pts.

Duration: 90 minutes

When finished with your work, close the NetBeans IDE and log out. Hand in this sheet, otherwise
your exam will not be gr
aded.

I
nstructions
:

Your working folder
for this exam will be
F:
\
USR
\
EXAM
\
EXAM#
, where # is your exam user
number. Save all your programs into your exam# folder.

We will refer to this folder as your
“home directory”.

From the
F:
\
USR
\
SHARE

folder
, c
opy the
file
s

listNumbers.java
,

Tombala.java
and .nbattrs into
your home directory.

The programming problems below will ask you to
fill in these files
.

Because of the difficulty of coordinating four classrooms, NO REQUESTS TO CLARIFY
EXAM PROBLEMS are allowed duri
ng the exam. If you are unclear about the statement of a
problem, make a reasonable guess and write down your interpretation. If your interpretation and
your answer are consistent, you will receive full credit.

Programming Problem
1

[40 points]

Write a Ja
va applet that simulates a variant of a Tombala game between two players.

The rules of this game are as follows:


i.

Each player has a card containing ten (10)
distinct

integers between 1 and 99. The
contents of each player’s card are filled in randomly in t
he beginning of the game.

ii.

At

the beginning of the game, there is a bag containing chips with integers 1 through
99 on them. At each step of the game, one chip is randomly drawn from the bag and
is not put back in
.

iii.

Players’ scores start at 0. Each time a ch
ip is drawn, if the number drawn appears on
a player’s card, his score increases by one. This is called a “hit”.

iv.

A player wins the game when his score reaches 10.

v.

If both players reach a score of 10 at the same time, they
both win
.


Implement an applet wit
h a graphical user interface for simulating a Tombala game. Your GUI
should


-

d
isplay the integers on each player’s card during the entire game
,

-

use a
JButton
that, when clicked, simulates

the next number
being

drawn from the
bag
,

-

d
isplay the correct scores

of both players at each step of the game
, and,

-

d
isplay a message whenever one or both players win, and disallow the drawing of
new numbers from the bag after that point
.


(continued on the next page)




(Programming Problem 1 continued)


You
do not

have t
o display which particular integers on each card have already been drawn.

The
GUI components have already been defined and attached to an applet for you. You are asked to
fill in the rest of the program.
Only override the
init()

method of
JApplet
. Do not
o
verride

the
start()

and
paint()

methods for this application.


Several
suggestions
have been provided for you in Tombala.java. These suggestions are there to
guide your thinking only. You are
not required

to follow them. We strongly recommend that you
read

all of the suggestions and have a concrete design in your mind before you start writing code.


Compile your program and generate an HTML file that refers to your applet.


Files to be submitted
for this problem
: Tombala.java, Tombala.class, Tombala.html


Programming Problem 2

[
20 points]


Write a Java application by filling in the file listNumbers.java. Your application should ask the
user for two numbers

b


and

n


using an input dialog. It should then print all base b numbers
with n digits in increasing

order.
(
Assume that b ≤

10
)
.

For instance, if b
is

3 and n
is

2, the
output of your program should be


00

01

02

10

11

12

20

21

22


Use a recursive method to implement this applicatio
n.

The Java class implementing this
application

should have two static methods:


-

a

“main” method

-

a

method that does the recursive comp
utation and printing of numbers

as described in listNumbers.java
. Make sure that your program compiles with no errors.


Files to be submitted
for this problem
:

listNumbers.java, listNumbers.class