Professional Documents
Culture Documents
Assignment 3:
Initializing a battle
ship game board
(of sorts)
specific programing assignment. This is to tell the user that Termination screen:
is running the program what the program will do.
The last display of a program should be a message that indi-
2. Explains what the user is expected to do. If the user does
cates that the program in ending.
not need to enter anything, say this.
3. Explains what will happen after the user does as instructed. Examples:
S ECTION 2 JOptionPane.showOptionDialog
Review of OptionsDialog In lecture you were shown the following statics methods of the
class JOptionPane.
• showMessageDialog
• showInputDialog
1. showOptionsDialog which give buttons for your user to click on to make their se-
lection. When using this method you pass it an array of op-
2. Using Small images tions as strings and these show up as labeled buttons. The se-
lection the user clicks on is returned as an integer represent-
ing the index of the label in the array of options. The use of
buttons for selection eliminates the need for data validation as
would be needed is you asked them to enter their selection
into a text field.
The sample provided in the code above, creates the dialog box Notice that the buttons are all the same size and that size is
below. determined by the longest label. If shorter names are used,
say numbers instead of longer names, a much more narrow
dialog box is produced, as shown below.
that Daisy is on the rightt and Rose would be on the left. Also,
the control buttons for the window are on the opposite side of
the box title bar on a windows machine.
6
Problem Description Historically, battle ship was played on a game case that con-
sisted of a pegboard so that you could track where your ships
were and the shots you were making into your opponents
fleet.
You should be able to see that the board is displayed using a 7. You must have a method called displayBoard that takes
JOptionPane.show Options Dialog popup. The syntax for this a populated array as argument and creates a popup window
static method is given in Section 2 of this document. If you displaying the board. When a button on the popup is
don’t want to bother with a custom icon, simply enter null as clicked, the methods and returns the option selected by the
an argument where you would have passed the icon user determined by the button clicked.
So, the place to start is the pseudo code. And to do that you need
to do problem decomposition.
Start asking yourself questions and if you can’t answer them, ask
me or a class mate. I have seen some truly over complicated solu-
tions for this assignment.
Start early and work steadily. If you have any questions ASK!!!!!!
S ECTION 4 Remember , if your program does not compile, you will re-
ceive no credit for it. So, write your code in stages that you
Evaluation Criteria can alway return to if new code prevents you program from
compiling.
Extra credit:
E VALUATION C RITERIA I have suggested extra credit. If you think of something else
that will add value to the solution or give it an extra feature to
1. Submission requirements make it more versatile, you should discuss it with me to de-
termine if it will earn you any extra credit. You may earn as
2. Extra credit
much as 20/100 in extra credit per problem.
3. Source code Documentation
However, be aware, if your solution to the required problem
4. Programming style
is not correct, you will earn no extra credit points. This in-
cludes the alignment of the column characters and the ap-
pearance of being square. In other words, extra credit can
not be used to make up for not getting the required
assignment correct. If your characters are not lining up
Submission requirements:
correctly or your game board that has the same number of
Source code is expected to be submitted to the Moodle
rows and column does not appear square, any extra effort will
submission link for Assign 3, before the posted dead-
not count toward points. Extra credit is only for you to get
line. Assignments that are late will have a 20 point
credit for trying new ideas after you have correctly completed
penalty on the base problem.
the required problem.
10
• Any statements within a set of braces, must be indented one Here are a few exam-
tab to the right of the opening brace. ples of misalign-
• Variables should be given intuitive names indicating what is ment and mis-shape
stored in them. When helping you, I should not have to ask that will prevent you
you what is stored in a variable. from earning extra
• All variable names must start with a lowerCase letter. Suc- credit. In the image to
cessive words in a variable name, can either be separated the right and below, the
with an underscore, or start with an upper case. X’s do not align with
• Program name should start with an uppercase letter. the empty spot charac-
• Blank lines should be used to separate blocks of code. Do ters in either of these ex-
not put a blank line after each line of code! You will loose amples. Also, the one im-
points if you do this. age above is not square.
11