67
Designing and Developing Object-Oriented Computer Programs BATTLESLUGS Presented by AUNG PYAE (MCC Training Institute, Mandalay Campus) March 2016

Designing and Developing Object Oriented Computer Programs (DDOOCP)

Embed Size (px)

Citation preview

Page 1: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Designing and Developing Object-Oriented Computer Programs

BATTLESLUGS

Presented by AUNG PYAE

(MCC Training Institute, Mandalay Campus) March 2016

Page 2: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 1

NCC Education

Level (4) Diploma in Computing

Module title Designing and Developing Object-Oriented

Computer Programs

Assignment title Battleslugs

Candidate name AUNG PYAE

Candidate no 00148187

Exam cycle March 2016

Word count

Marker’s comments:

Moderator’s comments:

Marks:

Moderated marks:

Final marks:

Page 3: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 2

STATEMENT AND CONFIRMATION OF OWN WORK

Programmed qualification name: Level (4) Diploma in Computing

Name: Designing and Developing Object-Oriented Computer Programs

Each NCC Education assessed assignment submitted by you must have this statement

attached to the assignment as the cover page or it will not be accepted for making. Please

ensure that this statement is either firmly attached to the cover of the assignment or

electronically inserted NUMBER the front of the assignment.

All submitted work must have this form as the cover / first page. Please include this form as

part of a standard format when submitting an assignment.

STUDENT DECALARATION

I have read and understood NCC Education’s policy and Academic Dishonesty and

Plagiarism. I can confirm the following details;

Student ID 00148187

Name AUNG PYAE

Centre name MCC Training Institute, Mandalay Campus,

Myanmar

Module name Designing and Developing Object-Oriented

Computer Programs

Title of work Battleslugs

Module leader DAW SOEPYAE KHAING

Number of words

I can confirm that is my own work that I have not plagiarized any part of it. I have also noted

the grading criteria and pass mark for assignment.

Due date 2016

Student signature aungpyae

Submitted date 2016

Page 4: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 3

TABLE OF CONTENTS

TABLE OF CONTENTS ...................................................................................................................... 3

Introduction ........................................................................................................................................... 4

Acknowledgement ................................................................................................................................. 5

TASK 1: The Application ..................................................................................................................... 6

The program codes .................................................................................................................... 12

TASK 2: Testing Data ......................................................................................................................... 34

2.1: Discussion about how the data was selected and executed ........................................... 34

2.2: White box testing .................................................................................................................... 35

Test plan: generate cell around ................................................................................................ 35

Program code for generate cell around .................................................................................. 35

Test No. 1 .................................................................................................................................... 37

Test No. 2 .................................................................................................................................... 38

Test No. 3 .................................................................................................................................... 39

Test No. 4 .................................................................................................................................... 40

Test No. 5 .................................................................................................................................... 42

Test plan: generate slug ............................................................................................................ 44

Program code for generateSlug method ................................................................................ 44

Test No. 1 .................................................................................................................................... 45

Test No. 2 .................................................................................................................................... 47

Test No. 3 .................................................................................................................................... 49

Test No. 4 .................................................................................................................................... 50

Test No. 5 .................................................................................................................................... 52

2.3: Black box testing ..................................................................................................................... 54

TASK 3: UML Class Diagram ........................................................................................................... 64

Conclusion ........................................................................................................................................... 65

References ............................................................................................................................................ 66

Page 5: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 4

Introduction

Hello!

My name is Aung Pyae and I study business information technology from NCC Education

Level 4 Diploma in computing course at MCC Training Institute, Mandalay Campus in

Myanmar. I am attending this computer course because information technology (IT) is

essential important today and most of business process use computerized systems. As I am

interest in IT and I want to improve my knowledge and creation skills, I attended to MCC

Training Institute (Mandalay Campus) since 2013. MCC Training Institute (Myanmar) is

recognized by NCC Education and University of Greenwich in UK. So I am attending this

course which is offered by NCC Education Center.

There are four main subjects in our Level 4 first semester course:

Computer Networks

Designing and Developing Object-Oriented Computer Programs

Designing and developing a website

Office Solutions Development

This assignment is aimed for the global assignment subject, designing and developing

object-oriented computer programs (DDOOCP). This subject provides a through introduction

to computer programming using Java language. DDOOCP subject use Java language with

overview of GUI and IDE, and certain concepts part of a program such as class, object,

method, the components of swing, and attributes of component.

In this assignment, we have to develop a small java game. This game is very similar to the

popular game Battleships, but there is differences between two games. In this game, there

are no fixed shapes for each of the two players. Each player gets five slugs to place on 12 –

12 board, and throw slugs with their turn.

This introduction is aimed for this DDOOCP assignment and this subject was taught by our

teacher, Daw Soepyae Khaing. I had done this assignment with my teacher.

AUNG PYAE

MCC Training Institute, Mandalay Campus

March 2016

Page 6: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 5

Acknowledgement

Knowledge is most valuable prize of the world and the teacher who gives this knowledge are

also valuable and grand persons. When I arrived in MCC (Myanmar Computer Company

Limited) Training Institute, everything was difficult for me and I learned many subjects about

computer and information technology. Some are easy but some are difficult. There are many

teachers and officers in our school. The teacher who teaches our subjects teaches me kindly.

I thank to my teachers with best wishes.

This global subject is important for me because we cannot achieve the Level 4 honor degree

without passing this subjects. So I need to study hard and make practice for my tasks and

topics. This assignment is completely done under the guidance of my DDOOCP teacher,

Daw Soepyae Khaing. I great thank to my teacher and all other teachers in our Level 4

subjects and they give me some great advices and logical thinking. I also thank to our class

tutor, Daw Zin Thandar as she gives me strength for my mind and teach us to become well

professional technicians.

Next, I thank to my friends who help me in solving the difficulties of this assignment and help

to become a complete assignment. They also help to complete and add some knowledge for

this assignment and give more useful advices. I also thank my MCC Training Institute, NCC

Education and University of Greenwich. I can study Business IT course because of them. I

also thank all my teachers and friends who help me to finish and to become a complete

assignment.

And finally, I great thank to MCC and NCC since it services me to get more ways for my

living and guide me to become a professional IT technician.

AUNG PYAE

MCC Training Institute, Mandalay Campus

March 2016

Page 7: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 6

TASK 1: The Application

Open the program to play the game. The player input form will be appear and enter the

player one’s name. After entering the player one’s name, click “OK”.

NOTE: The game cannot be close without entering the player name.

Reference figure: Figure 1.1.1

Figure: 1.1.1

Place the segments on playing board. First click the generate button to product the slug.

Random generation is used and place segment on the board by clicking move slug button

and place on the playing board. The player need to place five segments on the board and

cancel the selected segment if not required.

Reference figure: Figure 1.1.2

Page 8: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 7

Figure: 1.1.2

Next step is to enter the player two’s name. As in the flow of player one, the player two also

need to enter name, and place the five segments on playing board.

Reference figure: Figure 1.1.3, Figure: 1.1.2

Figure: 1.1.3

After placing five segments for player two, the game playing board will automatically start

with soft background music and the start turn is player one.

Reference figure: Figure 1.1.4

Page 9: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 8

Figure: 1.1.4

Select target and throw the salt. Each player can throw one time at their turn. Select the

target slug and click throw. If the target is hit, the color of slug will changed to red and the

target is missed, the slug color will be gray. The color of selected slug before throwing is

purple. The turn is cycling each two player and the playing board is automatically update the

bard stages of two players.

Reference figure: Figure: 1.1.5, Figure: 1.1.6

Page 10: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 9

Figure: 1.1.5

Figure: 1.1.6

While playing the game, the player can view the board stage of his/her to know what part of

slugs are hit. To view this result, click show my board button. The color of hit slugs are show

with red color on playing board stage.

Reference figure: 1.1.7

Page 11: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 10

Figure: 1.1.7

When all the slug of one player is killed or hits, the game is over and the result form will be

appear. The two players can know their results with their shot times, hit times, and skill

percentage. Close to exit the game.

Reference figure: 1.1.8

Figure: 1.1.8

Page 12: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 11

Page 13: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 12

The program codes

PlayerPlacing.java

package ddoocp_march_2016; import java.awt.Color; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.WindowConstants; public class PlayerPlacing extends javax.swing.JFrame { private PlacingPlayerOnBoard clabel; protected static int slug[]; protected static boolean isMoving = false; protected static boolean player1 = true; static String player1name=null,player2name=null; private JButton jbtncancel; private JButton jbtngenerate; private JButton jbtnmove; private JPanel jpboard; private JPanel jpplayer; public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(PlayerPlacing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PlayerPlacing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) {

Page 14: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 13

java.util.logging.Logger.getLogger(PlayerPlacing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PlayerPlacing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new PlayerPlacing(); } }); } public PlayerPlacing() { setSize(780, 550); setLocationRelativeTo(null); setVisible(true); jpboard = new JPanel(); jpplayer = new JPanel(); jbtngenerate = new JButton(); jbtnmove = new JButton(); jbtncancel = new JButton(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); getContentPane().setLayout(null); setContentPane(new JLabel(new ImageIcon("img.jpg"))); jpboard.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0))); jpboard.setLayout(new GridLayout(12, 12, 1, 1)); getContentPane().add(jpboard); jpboard.setBounds(10, 10, 500, 500); jpplayer.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0))); jpplayer.setLayout(new GridLayout(5, 5, 1, 1)); getContentPane().add(jpplayer); jpplayer.setBounds(550, 10, 200, 200); jbtngenerate.setFont(new Font("Tahoma", 0, 12)); // NOI18N jbtngenerate.setText("Generate your slugs"); jbtngenerate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jbtngenerateActionPerformed(evt); } }); getContentPane().add(jbtngenerate); jbtngenerate.setBounds(550, 380, 200, 30); JLabel mylabel =new JLabel("<html><div align='justify'>Guide: Click generate button to produce your slugs. Click move to set your selected slugs on playing board. You need to place five slugs on your board.</div></html>"); mylabel.setForeground(Color.white); mylabel.setBounds(550,250,200,80);

Page 15: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 14

getContentPane().add(mylabel); jbtnmove.setFont(new Font("Tahoma", 0, 12)); // NOI18N jbtnmove.setText("Move slugs"); jbtnmove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jbtnmoveActionPerformed(evt); } }); getContentPane().add(jbtnmove); jbtnmove.setBounds(550, 430, 200, 30); jbtncancel.setFont(new Font("Tahoma", 0, 12)); // NOI18N jbtncancel.setText("Cancel move slugs"); jbtncancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jbtncancelActionPerformed(evt); } }); getContentPane().add(jbtncancel); jbtncancel.setBounds(550, 480, 200, 30); clabel = new PlacingPlayerOnBoard(jpboard, jpplayer, this); while (player1name==null || player1name.length()<=0) { player1name= JOptionPane.showInputDialog(this, "Enter first player name","Player Form Input",JOptionPane.INFORMATION_MESSAGE); } setTitle("Place slug for "+player1name); } private void jbtngenerateActionPerformed(ActionEvent evt) { int indexes[] = clabel.calculateSlug(); slug = clabel.convertToDirection(indexes); } private void jbtncancelActionPerformed(ActionEvent evt) { isMoving = false; } private void jbtnmoveActionPerformed(ActionEvent evt) { if(slug != null) { isMoving = true; } } }

PlacingPlayerOnBoard.java

package ddoocp_march_2016; import java.awt.Color; import java.awt.event.MouseAdapter;

Page 16: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 15

import java.awt.event.MouseEvent; import java.util.Random; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; public class PlacingPlayerOnBoard { private JLabel jlblboard[], jlblgenerate[]; private int newslugindex[]; private PlayerPlacing pp; public PlacingPlayerOnBoard(JPanel jpboard, JPanel jpgenerate, PlayerPlacing pp) { this.pp = pp; jlblboard = new JLabel[144]; for(int i = 0; i < jlblboard.length; i++) { JLabel lbl = new JLabel(); lbl.setOpaque(true); lbl.setBackground(Color.white); lbl.setBorder(new LineBorder(Color.decode("#708090"))); //placing board color lbl.setName(String.valueOf(i)); lbl.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { lblMouseClicked(evt); } public void mouseEntered(MouseEvent evt) { lblMouseEntered(evt); } public void mouseExited(MouseEvent evt) { lblMouseExited(evt); } }); jlblboard[i] = lbl; jpboard.add(lbl); } jlblgenerate = new JLabel[25]; for(int i = 0; i < jlblgenerate.length; i++) { JLabel lbl = new JLabel(); lbl.setOpaque(true); lbl.setBackground(Color.white); lbl.setBorder(new LineBorder(Color.decode("#708090"))); //sample placing board color lbl.setHorizontalAlignment(SwingConstants.CENTER); lbl.setForeground(Color.white); jlblgenerate[i] = lbl; jpgenerate.add(lbl); } }

Page 17: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 16

private int[] generateCellAround(int genCellIndex) { int i[] = new int[8]; for (int k=0;k<8;k++) { i[k]=-1; } if(genCellIndex == 0) { i[0] = 1; i[1] = 6; i[2] = 5; } else if(genCellIndex == 4) { i[2] = 9; i[3] = 8; i[4] = 3; } else if(genCellIndex == 20) { i[0] = 21; i[6] = 15; i[7] = 16; } else if(genCellIndex == 24) { i[4] = 23; i[5] = 18; i[6] = 19; } else if(genCellIndex > 0 && genCellIndex < 4) { i[0] = genCellIndex + 1; i[1] = genCellIndex + 6; i[2] = genCellIndex + 5; i[3] = genCellIndex + 4; i[4] = genCellIndex - 1; } else if(genCellIndex > 20 && genCellIndex < 24) { i[0] = genCellIndex + 1; i[4] = genCellIndex - 1; i[5] = genCellIndex - 6; i[6] = genCellIndex - 5; i[7] = genCellIndex - 4; } else if(genCellIndex == 9) { i[2] = 14; i[3] = 13; i[4] = 8; i[5] = 3; i[6] = 4; } else if(genCellIndex == 14) { i[2] = 19; i[3] = 18; i[4] = 13; i[5] = 8; i[6] = 9; } else if(genCellIndex == 19) { i[2] = 24; i[3] = 23; i[4] = 18; i[5] = 13; i[6] = 14; } else if(genCellIndex == 5) { i[0] = 6; i[1] = 11; i[2] = 10; i[6] = 0; i[7] = 1; } else if(genCellIndex == 10) { i[0] = 11; i[1] = 16; i[2] = 15; i[6] = 5; i[7] = 6; } else if(genCellIndex == 15) { i[0] = 16; i[1] = 21; i[2] = 20; i[6] = 10; i[7] = 11; } else { i[0] = genCellIndex + 1; i[1] = genCellIndex + 6; i[2] = genCellIndex + 5; i[3] = genCellIndex + 4; i[4] = genCellIndex - 1; i[5] = genCellIndex - 6; i[6] = genCellIndex - 5; i[7] = genCellIndex - 4; } return i; } protected int[] calculateSlug() { int index[] = new int[5];

Page 18: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 17

Random r = new Random(); int cellindex = r.nextInt(25); index[0] = cellindex; for(int i = 1; i < 5; i++) { int num[] = generateCellAround(cellindex); int ran = -1; int tempran = 0; while(ran == -1) { tempran = r.nextInt(8); int tmp = num[tempran]; boolean found = false; for(int j = 0; j < index.length; j++) { if(tmp == index[j]) { found = true; break; } } if(!found) ran = num[tempran]; } index[i] = ran; cellindex = ran; } for(int i = 0; i < jlblgenerate.length; i++) { jlblgenerate[i].setBackground(Color.white); } for(int i = 0; i < index.length; i++) { jlblgenerate[index[i]].setBackground(Color.decode("#708090")); // label box color jlblgenerate[index[i]].setText(String.valueOf(i + 1)); } return index; } protected int[] convertToDirection(int index[]) { int d[] = new int[4]; int cellindex = index[0]; for(int i = 1; i < index.length; i++) { int dir = 0; if(index[i] == cellindex + 1) dir = 0; else if(index[i] == cellindex + 6) dir = 1; else if(index[i] == cellindex + 5) dir = 2; else if(index[i] == cellindex + 4) dir = 3; else if(index[i] == cellindex - 1) dir = 4; else if(index[i] == cellindex - 6) dir = 5; else if(index[i] == cellindex - 5) dir = 6; else dir = 7; d[i - 1] = dir; cellindex = index[i]; } return d; } private boolean validCellindex(int oldindex, int newindex) { boolean b = false; if(jlblboard[oldindex].getBackground().equals(Color.white)) { if(oldindex == 0) {

Page 19: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 18

if((newindex == 1 || newindex == 13 || newindex == 12) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else if(oldindex == 11) { if((newindex == 23 || newindex == 22 || newindex == 10) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else if(oldindex == 143) { if((newindex == 142 || newindex == 130 || newindex == 131) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else if(oldindex == 132) { if((newindex == 133 || newindex == 120 || newindex == 121) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else if(oldindex > 0 && oldindex < 11) { if((newindex == oldindex + 1 || newindex == oldindex + 13 || newindex == oldindex + 12 || newindex == oldindex + 11 || newindex == oldindex - 1) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else if(oldindex > 132 && oldindex < 143) { if((newindex == oldindex + 1 || newindex == oldindex - 1 || newindex == oldindex - 13 || newindex == oldindex - 12 || newindex == oldindex - 11) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else if(oldindex % 12 == 0) { if((newindex == oldindex + 1 || newindex == oldindex + 13 || newindex == oldindex + 12 || newindex == oldindex - 12 || newindex == oldindex - 11) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else if(oldindex % 12 == 11) { if((newindex == oldindex + 12 || newindex == oldindex + 11 || newindex == oldindex - 1 || newindex == oldindex - 13 || newindex == oldindex - 12) && jlblboard[newindex].getBackground().equals(Color.white)) b = true; } else { b = true; } } if(b == true && jlblboard[newindex].getBackground().equals(Color.white)) { b = true; } else { b = false; } return b; } private void lblMouseEntered(MouseEvent evt) { if(PlayerPlacing.isMoving) { boolean validplacing = true; newslugindex = new int[5]; int index = Integer.parseInt(((JLabel)evt.getSource()).getName()); newslugindex[0] = index; for(int i = 0; i < PlayerPlacing.slug.length; i++) {

Page 20: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 19

if(PlayerPlacing.slug[i] == 0) { if(validCellindex(index, index + 1)) { index = index + 1; newslugindex[i + 1] = index; } else { validplacing = false; } } else if(PlayerPlacing.slug[i] == 1) { if(validCellindex(index, index + 13)) { index = index + 13; newslugindex[i + 1] = index; } else { validplacing = false; } } else if(PlayerPlacing.slug[i] == 2) { if(validCellindex(index, index + 12)) { index = index + 12; newslugindex[i + 1] = index; } else { validplacing = false; } } else if(PlayerPlacing.slug[i] == 3) { if(validCellindex(index, index + 11)) { index = index + 11; newslugindex[i + 1] = index; } else { validplacing = false; } } else if(PlayerPlacing.slug[i] == 4) { if(validCellindex(index, index - 1)) { index = index - 1; newslugindex[i + 1] = index; } else { validplacing = false; } } else if(PlayerPlacing.slug[i] == 5) { if(validCellindex(index, index - 13)) { index = index - 13; newslugindex[i + 1] = index; } else { validplacing = false; } } else if(PlayerPlacing.slug[i] == 6) {

Page 21: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 20

if(validCellindex(index, index - 12)) { index = index - 12; newslugindex[i + 1] = index; } else { validplacing = false; } } else { if(validCellindex(index, index - 11)) { index = index - 11; newslugindex[i + 1] = index; } else { validplacing = false; } } } if(validplacing) { for(int i = 0; i < newslugindex.length; i++) { jlblboard[newslugindex[i]].setBackground(Color.gray); } } else { lblMouseExited(evt); } } } private void lblMouseExited(MouseEvent evt) { for(int i = 0; i < jlblboard.length; i++) { if(jlblboard[i].getBackground() == Color.gray) { jlblboard[i].setBackground(Color.white); } } } private void lblMouseClicked(MouseEvent evt) { int index = Integer.parseInt(((JLabel)evt.getSource()).getName()); if(jlblboard[index].getBackground() == Color.gray) { if(PlayerPlacing.player1) { for(int i = 0; i < newslugindex.length; i++) { jlblboard[newslugindex[i]].setBackground(Color.decode("#708090")); // placed color PlayingBoard.player1slug.add(newslugindex[i]); } PlayerPlacing.slug = null; PlayerPlacing.isMoving = false; for(int i = 0; i < jlblgenerate.length; i++) { jlblgenerate[i].setBackground(Color.white); } if(PlayingBoard.player1slug.size() == 25) { PlayerPlacing.player1 = false;

Page 22: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 21

for(int i = 0; i < jlblboard.length; i++) { jlblboard[i].setBackground(Color.white); } while (PlayerPlacing.player2name==null || PlayerPlacing.player2name.length()<=0) { PlayerPlacing.player2name= JOptionPane.showInputDialog(pp, "Enter second player name","Player Form Input",JOptionPane.INFORMATION_MESSAGE); } pp.setTitle("Place slug for "+PlayerPlacing.player2name); } } else { for(int i = 0; i < newslugindex.length; i++) { jlblboard[newslugindex[i]].setBackground(Color.decode("#708090")); PlayingBoard.player2slug.add(newslugindex[i]); } PlayerPlacing.slug = null; PlayerPlacing.isMoving = false; for(int i = 0; i < jlblgenerate.length; i++) { jlblgenerate[i].setBackground(Color.white); } if(PlayingBoard.player2slug.size() == 25) { PlayingBoard pb = new PlayingBoard(); pb.setVisible(true); JOptionPane.showMessageDialog(pb, "Start turn : " +PlayerPlacing.player1name); pp.dispose(); } } } } }

PlayingBoard.java

package ddoocp_march_2016; import java.awt.Color; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileInputStream; import java.util.ArrayList; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel;

Page 23: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 22

import javazoom.jlme.util.Player; public class PlayingBoard extends JFrame { private JLabel jLabel1; private JLabel jLabel2; private JLabel jLabel3; private JLabel jLabel4; private JButton jbtnshow; private JButton jbtnthrow; private JPanel jpboard; protected static ArrayList player1slug = new ArrayList(); protected static ArrayList player2slug = new ArrayList(); protected static ArrayList player1shoot = new ArrayList(); protected static ArrayList player2shoot = new ArrayList(); protected static int selectedtarget = -1; protected static boolean player1turn = true; public static boolean run=true; private PlayerPlayingOnBoard ppob; JLabel lblplayer; Thread songthread; public PlayingBoard() { initComponents(); setSize(860, 700); setLocationRelativeTo(null); ppob = new PlayerPlayingOnBoard(jpboard, this); songthread=new Thread(){ @Override public void run() { super.run(); while(run==true) { try { FileInputStream fis=new FileInputStream("music_popper.mp3"); Player playMP3=new Player(fis); playMP3.play(); } catch(Exception e) { e.printStackTrace(); } } } }; songthread.start(); } private void initComponents() { jpboard = new JPanel();

Page 24: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 23

jbtnthrow = new JButton(); jbtnshow = new JButton(); jLabel1 = new JLabel(); jLabel2 = new JLabel(); jLabel3 = new JLabel(); jLabel4 = new JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Battleslugs Board: OPPONENT "+PlayerPlacing.player2name+"; TURN - "+PlayerPlacing.player1name+" "); setResizable(false); getContentPane().setLayout(null); getContentPane().setBackground(Color.decode("#A9A9A9")); jpboard.setBorder(BorderFactory.createLineBorder(Color.decode("#708090"))); jpboard.setLayout(new GridLayout(12, 12, 1, 1)); getContentPane().add(jpboard); jpboard.setBounds(20, 10, 650, 650); jbtnthrow.setFont(new Font("Tahoma", 0, 12)); jbtnthrow.setText("THROW"); jbtnthrow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jbtnthrowActionPerformed(evt); } }); getContentPane().add(jbtnthrow); jbtnthrow.setBounds(710, 330, 100, 60); jbtnshow.setFont(new java.awt.Font("Tahoma", 0, 12)); jbtnshow.setText("Show my board"); jbtnshow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jbtnshowActionPerformed(evt); } }); getContentPane().add(jbtnshow); jbtnshow.setBounds(710, 630, 120, 30); jLabel3.setBackground(new Color(255, 0, 0)); //miss targets jLabel3.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jLabel3.setOpaque(true); getContentPane().add(jLabel3); jLabel3.setBounds(710, 70, 20, 20); jLabel2.setFont(new Font("Tahoma", 0, 12)); jLabel2.setText("Missed targets"); getContentPane().add(jLabel2); jLabel2.setBounds(740, 0, 90, 40); jLabel1.setBackground(Color.decode("#708090")); //hit targets jLabel1.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jLabel1.setOpaque(true); getContentPane().add(jLabel1); jLabel1.setBounds(710, 10, 20, 20);

Page 25: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 24

jLabel4.setFont(new Font("Tahoma", 0, 12)); jLabel4.setText("Hit targets"); getContentPane().add(jLabel4); jLabel4.setBounds(740, 60, 90, 40); JLabel lblguide =new JLabel("<html><div align='justify'>Select your target segment and click THROW.</div></html>"); lblguide.setBounds(710,100,130,60); getContentPane().add(lblguide); lblplayer =new JLabel(""); lblplayer.setBounds(710,200,130,100); getContentPane().add(lblplayer); if(player1turn){ lblplayer .setText("<html><b>OPPONENT</b>:<br/>"+PlayerPlacing.player2name+"<br/><br/><b>TURN</b>:<br/>"+PlayerPlacing.player1name+"</html>"); } else{ lblplayer.setText("<html><b>OPPONENT</b>:<br/>"+PlayerPlacing.player1name+"<br/><br/><b>TURN</b>:<br/>"+PlayerPlacing.player2name+"</html>"); } pack(); } private void jbtnshowActionPerformed(ActionEvent evt) { new MyPlayingBoard(this, true); } private void jbtnthrowActionPerformed(ActionEvent evt) { if(selectedtarget == -1) { JOptionPane.showMessageDialog(this, "Sorry! select your target slug and throw."); } else { ppob.throwSalt(); } } }

PlayerPlacingOnBoard.java

package ddoocp_march_2016; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane;

Page 26: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 25

import javax.swing.JPanel; public class PlayerPlayingOnBoard { private JPanel jp; private JButton jbtn[]; private PlayingBoard pb; //private JLabel lblplayer; public PlayerPlayingOnBoard(JPanel jp, PlayingBoard pb) { this.jp = jp; this.pb = pb; jbtn = new JButton[144]; for(int i = 0; i < jbtn.length; i++) { JButton btn = new JButton(); btn.setFocusable(false); btn.setName(String.valueOf(i)); btn.setBackground(Color.white); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnActionPerformed(evt); } }); jbtn[i] = btn; jp.add(btn); } } private void placingByPlayer() { for(int i = 0; i < jbtn.length; i++) { jbtn[i].setBackground(Color.white); if(PlayingBoard.player1turn) { if(PlayingBoard.player1shoot.contains(i)) { jbtn[i].setBackground(Color.decode("#708090")); if(PlayingBoard.player2slug.contains(i)) { jbtn[i].setBackground(Color.red); } } else { jbtn[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnActionPerformed(evt); } }); } } else { if(PlayingBoard.player2shoot.contains(i)) { jbtn[i].setBackground(Color.decode("#708090")); if(PlayingBoard.player1slug.contains(i)) { jbtn[i].setBackground(Color.red); }

Page 27: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 26

} else { jbtn[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnActionPerformed(evt); } }); } } } } private void btnActionPerformed(ActionEvent evt) { int index = Integer.parseInt(((JButton)evt.getSource()).getName()); if(PlayingBoard.selectedtarget != -1 && jbtn[PlayingBoard.selectedtarget].getBackground().equals(Color.decode("#8A2BE2"))) { //select jbtn[PlayingBoard.selectedtarget].setBackground(Color.white); } PlayingBoard.selectedtarget = index; jbtn[index].setBackground(Color.decode("#8A2BE2")); //select } protected void throwSalt() { Thread t = new Thread(new Runnable() { public void run() { int targetindex = PlayingBoard.selectedtarget; for(ActionListener al : jbtn[targetindex].getActionListeners()) { jbtn[targetindex].removeActionListener(al); } if(PlayingBoard.player1turn) { PlayingBoard.player1shoot.add(targetindex); if(PlayingBoard.player2slug.contains(targetindex)) { jbtn[targetindex].setBackground(Color.red); } else { jbtn[targetindex].setBackground(Color.decode("#708090")); } } else { PlayingBoard.player2shoot.add(targetindex); if(PlayingBoard.player1slug.contains(targetindex)) { jbtn[targetindex].setBackground(Color.red); } else { jbtn[targetindex].setBackground(Color.decode("#708090")); } }

Page 28: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 27

try { Thread.sleep(1000); } catch (Exception e) {} if(checkWinning()) { if(PlayingBoard.player1turn){ pb.songthread.stop(); pb.setVisible(false); winner w = new winner(PlayerPlacing.player1name); } else{ pb.songthread.stop(); pb.setVisible(false); winner w = new winner(PlayerPlacing.player2name); } } else { PlayingBoard.selectedtarget = -1; PlayingBoard.player1turn = PlayingBoard.player1turn != true; for(JButton btn : jbtn) { for(ActionListener al : btn.getActionListeners()) { btn.removeActionListener(al); } } placingByPlayer(); if(PlayingBoard.player1turn) { pb.setTitle("Battleslugs Board: OPPONENT - "+PlayerPlacing.player2name+"; TURN - "+PlayerPlacing.player1name+" "); } else { pb.setTitle("Battleslugs Board: OPPONENT - "+PlayerPlacing.player1name+"; TURN - "+PlayerPlacing.player2name+" "); } if(PlayingBoard.player1turn){ pb. lblplayer.setText("<html><b>OPPONENT</b>:<br/>"+PlayerPlacing.player2name+"<br/><b>TURN</b>:<br/>"+PlayerPlacing.player1name+"</html>"); } else{ pb.lblplayer.setText("<html><b>OPPONENT</b>:<br/>"+PlayerPlacing.player1name+"<br/><b>TURN</b>:<br/>"+PlayerPlacing.player2name+"</html>"); } } } });

Page 29: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 28

t.start(); } private boolean checkWinning() { boolean b = true; if(PlayingBoard.player1turn) { for(int i = 0; i < PlayingBoard.player2slug.size(); i++) { if(!PlayingBoard.player1shoot.contains(PlayingBoard.player2slug.get(i))) { b = false; break; } } } else { for(int i = 0; i < PlayingBoard.player1slug.size(); i++) { if(!PlayingBoard.player2shoot.contains(PlayingBoard.player1slug.get(i))) { b = false; break; } } } return b; } }

MyPlayingBoard.java

package ddoocp_march_2016;

import java.awt.Color;

import java.awt.Font;

import java.awt.Frame;

import java.util.ArrayList;

import javax.swing.BorderFactory;

import javax.swing.JDialog;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.WindowConstants;

import javax.swing.border.LineBorder;

public class MyPlayingBoard extends JDialog {

private JPanel jpboard;

Page 30: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 29

public MyPlayingBoard(Frame parent, boolean modal) {

super(parent, modal);

jpboard = new JPanel();

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

setTitle("My board stage");

setResizable(false);

getContentPane().setLayout(null);

jpboard.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));

jpboard.setLayout(new java.awt.GridLayout(12, 12, 1, 1));

getContentPane().add(jpboard);

jpboard.setBounds(0, 0, 500, 500);

setSize(507, 530);

generateSlugs();

setLocationRelativeTo(parent);

parent.setBackground(Color.green);

setVisible(true);

}

private void generateSlugs() {

ArrayList alslug = new ArrayList();

ArrayList alshoot = new ArrayList();

//check for player one or player two

if(PlayingBoard.player1turn) {

alslug = PlayingBoard.player1slug;

alshoot = PlayingBoard.player2shoot;

}

else {

alslug = PlayingBoard.player2slug;

Page 31: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 30

alshoot = PlayingBoard.player1shoot;

}

//show slugs by labels on panel

for(int i = 0; i < 144; i++) {

JLabel lbl = new JLabel();

lbl.setOpaque(true);

lbl.setBackground(Color.white);

if(alslug.contains(i)) {

lbl.setBackground(Color.decode("#708090"));

if(alshoot.contains(i)) {

lbl.setBackground(Color.red);

}

}

lbl.setBorder(new LineBorder(Color.decode("#708090"))); //board border color

jpboard.add(lbl);

}

}

}

winner.java

package ddoocp_march_2016; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; public class winner extends JFrame { Font f=new Font("Tahoma",Font.PLAIN,14); JLabel lbltext=new JLabel("BATTLESLUGS : GAME RESULT REPORT"); JLabel lblwinner=new JLabel("WINNER :"); JLabel lblwinnerplayer=new JLabel(); JLabel lblplayershots = new JLabel("SHOT");

Page 32: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 31

JLabel lblplayerhits = new JLabel("HIT"); JLabel lblplayerpercentage = new JLabel("PERCENTAGE"); JLabel lblshow = new JLabel("GAME RESULT"); JLabel lblp1 = new JLabel(PlayerPlacing.player1name); JLabel lblp2 = new JLabel(PlayerPlacing.player2name); JLabel lblp1shot = new JLabel(); JLabel lblp1hit = new JLabel(); JLabel lblp1per = new JLabel(); JLabel lblp2shot = new JLabel(); JLabel lblp2hit = new JLabel(); JLabel lblp2per = new JLabel(); JButton btnok = new JButton("CLOSE"); public winner(String s) { setTitle("RESULT"); //setResizable(false); setVisible(true); setLocationRelativeTo(null); setSize(630,330); setLayout(null); lbltext.setBounds(10,10,350,30); lbltext.setFont(f); add(lbltext); lblwinner.setBounds(10,50,100,30); lblwinner.setFont(f); add(lblwinner); lblwinnerplayer.setBounds(110,50,350,30); lblwinnerplayer.setFont(f); add(lblwinnerplayer); lblshow.setBounds(10,100,200,30); lblshow.setFont(f); lblshow.setBorder(BorderFactory.createLineBorder(Color.black)); add(lblshow); lblp1.setBounds(210,100,200,30); lblp1.setFont(f); lblp1.setBorder(BorderFactory.createLineBorder(Color.black)); add(lblp1); lblp2.setBounds(410,100,200,30); lblp2.setFont(f); lblp2.setBorder(BorderFactory.createLineBorder(Color.black)); add(lblp2); // END PLAYER LABEL

Page 33: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 32

lblplayershots.setBounds(10,130,200,30); lblplayershots.setFont(f); lblplayershots.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblplayershots); lblplayerhits.setBounds(10,160,200,30); lblplayerhits.setFont(f); lblplayerhits.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblplayerhits); lblplayerpercentage.setBounds(10,190,200,30); lblplayerpercentage.setFont(f); lblplayerpercentage.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblplayerpercentage); //END TABLE SPECIFICATION lblp1shot.setBounds(210,130,200,30); lblp1shot.setFont(f); lblp1shot.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblp1shot); lblp1hit.setBounds(210,160,200,30); lblp1hit.setFont(f); lblp1hit.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblp1hit); lblp1per.setBounds(210,190,200,30); lblp1per.setFont(f); lblp1per.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblp1per); //END PLAYER ONE SCORE lblp2shot.setBounds(410,130,200,30); lblp2shot.setFont(f); lblp2shot.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblp2shot); lblp2hit.setBounds(410,160,200,30); lblp2hit.setFont(f); lblp2hit.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblp2hit); lblp2per.setBounds(410,190,200,30); lblp2per.setFont(f); lblp2per.setBorder(BorderFactory.createLineBorder(Color.white)); add(lblp2per); //END PLAYER ONE SCORE btnok.setBounds(210, 250, 200, 30); btnok.setFont(f); btnok.addActionListener(new ActionListener() {

Page 34: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 33

@Override public void actionPerformed(ActionEvent arg0) { // p.songthread.stop(); System.exit(0); } }); add(btnok); lblwinnerplayer.setText(s); //player one total shots int p1shot = PlayingBoard.player1shoot.size(); //player two total shots int p2shot = PlayingBoard.player2shoot.size(); //calculate player one hits int p1hit = 0; for(int i = 0; i < PlayingBoard.player2slug.size(); i++) { if(PlayingBoard.player1shoot.contains(PlayingBoard.player2slug.get(i))) { p1hit++; } } //calculate player two hits int p2hit = 0; for(int i = 0; i < PlayingBoard.player1slug.size(); i++) { if(PlayingBoard.player2shoot.contains(PlayingBoard.player1slug.get(i))) { p2hit++; } } lblp1shot.setText(String.valueOf(p1shot)); lblp2shot.setText(String.valueOf(p2shot)); lblp1hit.setText(String.valueOf(p1hit)); lblp2hit.setText(String.valueOf(p2hit)); //player one hit percent lblp1per.setText(String.valueOf(100*p1hit/p1shot) + " %"); //player two hit percent lblp2per.setText(String.valueOf(100*p2hit/p2shot) + " %"); } }

Page 35: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 34

TASK 2: Testing Data

2.1: Discussion about how the data was selected and executed

The game is developed with two players and system record the name of two players to show

on the board and output result. For each player, the system will generate the five slugs with

random sequence and other place for five times (five segments) on playing board for each

player. Selected segments cannot be overlap each other.

The system is tested with Black box testing and White Box testing to explore each function.

White Box testing is tested with two stages: generate cell around on playing board and

generate slug for producing the slugs for player. Black box testing check the input form

validation, layer turn, generate slugs and throwing slugs.

Types of data types used in White Box testing:

Normal valid (can upgrade)

Boundary (can upgrade)

Invalid (error)

Page 36: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 35

2.2: White box testing

Test plan: generate cell around

Test no. Test date Test data Type of data Excepted result

1 23-1-2016 4 Normal

/

Valid

[-1,-1,9,8,3,-1,-

1,-1,-1]

2 23-1-2016 0 Boundary

/

Exception

[1,6,5,-1,-1,-1,-

1,-1]

3 23-1-2016 6 Normal

/

Valid

[0,5,4,3,-2,-7,-

6,-5]

4 24-1-2016 1 Boundary

/

Exception

[0,5,4,-2,-1,-1,-

1,-1]

5 25-1-2016 ten Invalid

/

Exception

Error

Program code for generate cell around

1. private int[] generateCellAround(int genCellIndex) {

2. int i[] = new int[8];

3. for (int k=0;k<8;k++)

4. {

5. i[k]=-1;

6. }

7. if(genCellIndex == 0)

8. { i[0] = 1; i[1] = 6; i[2] = 5; }

9. else if(genCellIndex == 4)

10. { i[2] = 9; i[3] = 8; i[4] = 3; }

11. else if(genCellIndex == 20)

12. { i[0] = 21; i[6] = 15; i[7] = 16; }

Page 37: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 36

13. else if(genCellIndex == 24)

14. { i[4] = 23; i[5] = 18; i[6] = 19; }

15. else if(genCellIndex > 0 && genCellIndex < 4) {

16. i[0] = genCellIndex + 1;

17. i[1] = genCellIndex + 6;

18. i[2] = genCellIndex + 5;

19. i[3] = genCellIndex + 4;

20. i[4] = genCellIndex - 1;

21. }

22. else if(genCellIndex > 20 && genCellIndex < 24) {

23. i[0] = genCellIndex + 1;

24. i[4] = genCellIndex - 1;

25. i[5] = genCellIndex - 6;

26. i[6] = genCellIndex - 5;

27. i[7] = genCellIndex - 4;

28. }

29. else if(genCellIndex == 9)

30. { i[2] = 14; i[3] = 13; i[4] = 8; i[5] = 3; i[6] = 4; }

31. else if(genCellIndex == 14)

32. { i[2] = 19; i[3] = 18; i[4] = 13; i[5] = 8; i[6] = 9; }

33. else if(genCellIndex == 19)

34. { i[2] = 24; i[3] = 23; i[4] = 18; i[5] = 13; i[6] = 14; }

35. else if(genCellIndex == 5)

36. { i[0] = 6; i[1] = 11; i[2] = 10; i[6] = 0; i[7] = 1; }

37. else if(genCellIndex == 10)

38. { i[0] = 11; i[1] = 16; i[2] = 15; i[6] = 5; i[7] = 6; }

39. else if(genCellIndex == 15)

40. { i[0] = 16; i[1] = 21; i[2] = 20; i[6] = 10; i[7] = 11; }

41. else {

42. i[0] = genCellIndex + 1;

43. i[1] = genCellIndex + 6;

44. i[2] = genCellIndex + 5;

45. i[3] = genCellIndex + 4;

46. i[4] = genCellIndex - 1;

47. i[5] = genCellIndex - 6;

48. i[6] = genCellIndex - 5;

Page 38: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 37

49. i[7] = genCellIndex - 4;

50. }

51. return i;

52. }

Test No. 1 Test data: genCellIndex=4

Ste

p

No.

Lin

e

No.

Variables Condition Retur

n k gen

Cell

Inde

x

I 1 2 3 4 5 6 7 8 9 1

0

1

1

1

2

K<

8

1 1 4

2 3 0 T

3 5 I[0]=-1

4 3 1 T

5 5 I[1]=-1

6 3 2 T

7 5 I[2]=-1

8 3 3 T

9 5 I[3]=-1

10 3 4 T

11 5 I[4]=-1

12 3 5 T

13 5 I[5]=-1

14 3 6 T

15 5 I[6]=-1

16 3 7 T

17 5 I[7]=-1

18 3 8 F

19 7 F

20 9 T

21 10 [-1,-

1,9,8,3,-

1,-1,-1,-

Page 39: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 38

1]

22 51 [-1,-

1,9,8,

3,-1,-

1,-1,-

1]

References:

T = True

F = False

i = int genCellIndex

genCellIndex = generate cell index

Test No. 2 Test data: genCellIndex=0

Ste

p

No.

Lin

e

No.

Variables Condition Retur

n k gen

Cell

Inde

x

I 1 2 3 4 5 6 7 8 9 1

0

1

1

1

2

K<

8

1 1 0

2 3 0 T

3 5 I[0]=-1

4 3 1 T

5 5 I[1]=-1

6 3 2 T

7 5 I[2]=-1

8 3 3 T

9 5 I[3]=-1

10 3 4 T

11 5 I[4]=-1

12 3 5 T

13 5 I[5]=-1

14 3 6 T

Page 40: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 39

15 5 I[6]=-1

16 3 7 T

17 5 I[7]=-1

18 3 8 F

19 7 T

20 8 [1,6,5,-

1,-1,-1,-

1,-1]

21 52 [1,6,5,

-1,-1,-

1,-1,-

1]

References:

T = True

F = False

i = int genCellIndex

genCellIndex = generate cell index

Test No. 3 Test data: genCellIndex=6

Ste

p

No.

Lin

e

No.

Variables Condition Retur

n k gen

Cell

Inde

x

I 1 2 3 4 5 6 7 8 9 1

0

1

1

1

2

K<

8

1 1 6

2 3 0 T

3 5 I[0]=-1

4 3 1 T

5 5 I[1]=-1

6 3 2 T

7 5 I[2]=-1

8 3 3 T

Page 41: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 40

9 5 I[3]=-1

10 3 4 T

11 5 I[4]=-1

12 3 5 T

13 5 I[5]=-1

14 3 6 T

15 5 I[6]=-1

16 3 7 T

17 5 I[7]=-1

18 3 8 F

19 7 F

20 9 F

21 11 F

22 13 F

23 15 F

24 22 F

25 29 F

26 41 [0,5,4,3,-

2,-7,-6,-

5]

27 51 [0,5,4,

3,-2,-

7,-6,-

5]

References:

T = True

F = False

i = int genCellIndex

genCellIndex = generate cell index

Test No. 4 Test data: genCellIndex=1

Ste Lin Variables Condition Retur

Page 42: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 41

p

No.

e

No.

k gen

Cell

Inde

x

I 1 2 3 4 5 6 7 8 9 1

0

1

1

1

2

K<

8

n

1 1 1

2 3 0 T

3 5 I[0]=-1

4 3 1 T

5 5 I[1]=-1

6 3 2 T

7 5 I[2]=-1

8 3 3 T

9 5 I[3]=-1

10 3 4 T

11 5 I[4]=-1

12 3 5 T

13 5 I[5]=-1

14 3 6 T

15 5 I[6]=-1

16 3 7 T

17 5 I[7]=-1

18 3 8 F

19 7 F

20 9 F

21 11 F

22 13 F

23 15 T

24 16 [0,5,4,-

2,-1,-1,-

1,-1]

25 51 [0,5,4,

-2,-1,-

1,-1,-

1]

Page 43: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 42

References:

T = True

F = False

i = int genCellIndex

genCellIndex = generate cell index

Test No. 5 Test data: genCellIndex= ten

Ste

p

No.

Lin

e

No.

Variables Condition Retur

n k gen

Cell

Inde

x

I 1 2 3 4 5 6 7 8 9 1

0

1

1

1

2

K<

8

1 1 ten

2 3 0 T

3 5 I[0]=-1

4 3 1 T

5 5 I[1]=-1

6 3 2 T

7 5 I[2]=-1

8 3 3 T

9 5 I[3]=-1

10 3 4 T

11 5 I[4]=-1

12 3 5 T

13 5 I[5]=-1

14 3 6 T

15 5 I[6]=-1

16 3 7 T

17 5 I[7]=-1

18 3 8 F

19 7 F

20 9 F

Page 44: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 43

21 11 F

22 13 F

23 15 F

24 22 F

25 29 F

26 31 F

27 33 F

28 35 F

29 37 F

30 39 F

31 41 error

References:

Please user inserts only the number.

T = True

F = False

i = int genCellIndex

genCellIndex = generate cell index

Page 45: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 44

Test plan: generate slug

Test no. Test date Test data Type of data Excepted result

1 25-1-2016 cellindex=4 Normal

/

Valid

generateSlug

2 25-1-2016 cellindex=3 Normal

/

Valid

generateSlug

3 25-1-2016 cellindex=5 Boundary

/

Exception

generateSlug

4 26-1-2016 cellindex=25 Boundary

/

Exception

String.valueOf(i

+ 1)

5 26-1-2016 cellindex=one Invalid

/

Exception

Error

Program code for generateSlug method

1. protected int[] calculateSlug() {

2. int index[] = new int[5];

3. Random r = new Random();

4. int cellindex = r.nextInt(25);

5. index[0] = cellindex;

6. for(int i = 1; i < 5; i++) {

7. int num[] = generateCellAround(cellindex);

8. int ran = -1;

9. int tempran = 0;

10. while(ran == -1) {

11. tempran = r.nextInt(8);

12. int tmp = num[tempran];

13. boolean found = false;

14. for(int j = 0; j < index.length; j++) {

15. if(tmp == index[j]) {

Page 46: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 45

16. found = true;

17. break;

18. }

19. }

20. if(!found) ran = num[tempran];

21. }

22. index[i] = ran;

23. cellindex = ran;

24. }

25. for(int i = 0; i < jlblgenerate.length; i++) {

26. jlblgenerate[i].setBackground(Color.white);

27. }

28. for(int i = 0; i < index.length; i++) {

29. jlblgenerate[index[i]].setBackground(Color.decode("#708090"));

30. jlblgenerate[index[i]].setText(String.valueOf(i + 1));

31. }

32. return index;

33. }

Figure: Generate slugs

Test No. 1 Test data: generate slug = 4

Assume:

index[0] = cellIndex

Page 47: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 46

int ran = -1

S

t

e

p

N

o

.

L

i

n

e

N

o

.

Variables Condition Method

calling

Out

put

Slu

g

r

1

Cel

lind

ex

i t

m

p

t

m

p

te

mp

ran

te

mp

ran

fo

u

n

d

j If(i

<5

>

While(temp1==-1)

J<index.length

generateCellAround(cellindex);

1 6 [0,6

,7,1

0]

1

2 1

0

[-

1,5,

6,0,

-1]

-

1

3 1

4

0 true

4 1

5

1 true

5 2

0

1 false

6 2

5

0 The

bac

kgro

und

colo

r of

labe

lgrid

will

be

slat

Page 48: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 47

e

gray

7 2

8

0 The background color of labelgrid will be gray.

References:

T = True

F = False

Test No. 2 Test data: generate slug = 3

Assume:

index[0] = cellIndex

int ran = -1

S

t

e

p

N

o

.

L

i

n

e

N

o

.

Variables Condition Method

calling

Out

put

Slu

g

r

1

Cel

lind

ex

i t

m

p

t

m

p

te

mp

ran

te

mp

ran

fo

u

n

d

j If(i

<5

>

While(temp1==-1)

J<index.length

generateCellAround(cellindex);

1 6 [0,6

,7,1

1

Page 49: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 48

0]

1

0

[-

1,5,

6,0,

-1]

-

1

2 1

4

0 true

3 1

5

1 true

4 2

0

1 false

5 2

5

0 The

bac

kgro

und

colo

r of

labe

lgrid

will

be

slat

e

gray

6 2

8

0 The background color of labelgrid will be gray.

References:

T = True

Page 50: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 49

F = False

Test No. 3 Test data: generate slug = 5

Assume:

index[0] = cellIndex

int ran = -1

S

t

e

p

N

o

.

L

i

n

e

N

o

.

Variables Condition Method

calling

Out

put

Slu

g

r

1

Cel

lind

ex

i t

m

p

t

m

p

te

mp

ran

te

mp

ran

fo

u

n

d

j If(i

<5

>

While(temp1==-1)

J<index.length

generateCellAround(cellindex);

1 6 [0,6

,7,1

0]

1

2 1

0

[-

1,5,

6,0,

-1]

-

1

3 1

4

0 true

4 1

5

1 true

5 2

0

1 false

6 2

5

0 The

bac

kgro

Page 51: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 50

und

colo

r of

labe

lgrid

will

be

slat

e

gray

7 2

8

0 The background color of labelgrid will be gray.

References:

T = True

F = False

Test No. 4 Test data: generate slug = 25

Assume:

index[0] = cellIndex

int ran = -1

S

t

e

p

N

L

i

n

e

N

Variables Condition Method

calling

Out

put

Page 52: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 51

o

.

o

.

Slu

g

r

1

Cel

lind

ex

i t

m

p

t

m

p

te

mp

ran

te

mp

ran

fo

u

n

d

j If(i

<5

>

While(temp1==-1)

J<index.length

generateCellAround(cellindex);

1 6 [0,6

,7,1

0]

1

2 1

0

[-

1,5,

6,0,

-1]

-

1

3 1

4

0 true

4 1

5

1 true

5 2

0

1 false

6 2

5

0 The

bac

kgro

und

colo

r of

labe

lgrid

will

be

slat

e

gray

7 2

8

0 The background color of

Page 53: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 52

labelgrid will be gray.

References:

T = True

F = False

Test No. 5 Test data: generate slug = one

Assume:

index[0] = cellIndex

int ran = -1

S

te

p

N

o.

Li

n

e

N

o

.

Variables Condition Method

calling

Out

put

2 S

lu

g

r

1

Cel

lind

ex

i t

m

p

t

m

p

te

mp

ran

te

mp

ran

fo

u

n

d

j If(i

<5

>

While(temp1==-1)

J<index.length

generateCellAround(cellindex);

1 2 o

n

e

Erro

r

gen

ersti

ng

the

slug

References:

Page 54: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 53

T = True

F = False

Page 55: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 54

2.3: Black box testing

Test No. Test date Test objectives Tester name Expected result

1 26-1-2016 To enter player

name

Aung Pyae Enter player

name in player

form

2 26-1-2016 To generate

segments

Aung Pyae Generate slugs

3 26-1-2016 To place

segment five

times

Aung Pyae Generate

segment for five

times

4 26-1-2016 To move

segment

Aung Pyae Move segments

on playing board

5 26-1-2016 To cancel

segment

Aung Pyae Cancel the

selected

segment

6 26-1-2016 To place slug Aung Pyae Place generated

slugs on board

7 26-1-2016 To turn player Aung Pyae Turn the player

8 26-1-2016 To select target Aung Pyae Select the target

to throw

9 26-1-2016 To throw Aung Pyae Throw to the

selected slug

10 26-1-2016 To check throw Aung Pyae Target cannot

be throw without

selecting

11 26-1-2016 To view player

board stage

Aung Pyae View the

player’s board

stage

12 26-1-2016 To view the

winning result

Aung Pyae View the

winning result of

game

13 26-1-2016 To exit the

game

Aung Pyae Exit the program

Page 56: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 55

Case of test no: 1 (Black box testing)

Test objective: To enter player name

Test procedure: Set player name

Expected result: Enter player name in player form

Actual result: Figure 2.3.1

Figure: 2.3.1

Case of test no: 2 (Black box testing)

Test objective: To generate segments

Test procedure: Generate the segments

Expected result: Generate five slugs

Actual result: Figure 2.3.2

Figure: 2.3.2

Page 57: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 56

Case of test no: 3 (Black box testing)

Test objective: To place segments five times

Test procedure: Select segments for five times

Expected result: Generate segment for five times

Actual result: Figure 2.3.3

Figure: 2.3.3

Case of test no: 4 (Black box testing)

Test objective: To move segment

Test procedure: Move the segment on board

Expected result: Move segments on playing board

Actual result: Figure 2.3.4

Page 58: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 57

Figure: 2.3.4

Case of test no: 5 (Black box testing)

Test objective: To cancel segment

Test procedure: Cancel the slug

Expected result: Cancel the selected segment

Actual result: Figure 2.3.5

Figure: 2.3.5

Page 59: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 58

Case of test no: 6 (Black box testing)

Test objective: To place slug

Test procedure: Place the slug on board

Expected result: Place generated slugs on board

Actual result: Figure 2.3.6

Figure: 2.3.5

Case of test no: 7 (Black box testing)

Test objective: To turn player

Test procedure: Turning between two players

Expected result: Turn the player

Actual result: Figure 2.3.7, Figure: 2.3.8

Figure: 2.3.7

Page 60: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 59

Figure: 2.3.8

Case of test no: 8 (Black box testing)

Test objective: To select target

Test procedure: Select the target slug

Expected result: Select the target to throw

Actual result: Figure 2.3.9

Page 61: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 60

Figure: 2.3.9

Case of test no: 9 (Black box testing)

Test objective: To throw

Test procedure: Throw the slug

Expected result: Throw to the selected slug

Actual result: Figure 2.3.10

Figure: 2.3.10

Page 62: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 61

Case of test no: 10 (Black box testing)

Test objective: To check throw

Test procedure: Check the target is selected or not

Expected result: Target cannot be throw without selecting

Actual result: Figure 2.3.11

Figure: 2.3.11

Case of test no: 11 (Black box testing)

Test objective: To view player board stage

Test procedure: Show the hit slugs and segments

Expected result: View the player’s board stage

Actual result: Figure 2.3.12

Page 63: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 62

Figure: 2.3.12

Case of test no: 12 (Black box testing)

Test objective: To view the winning result

Test procedure: Show the game result table

Expected result: View the winning result of the game

Actual result: Figure 2.3.13

Page 64: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 63

Figure: 2.3.13

Case of test no: 13 (Black box testing)

Test objective: To exit the game

Test procedure: Exit the program

Expected result: Exit the program

Actual result: Figure 2.3.14

Figure: 2.3.14

Page 65: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 64

TASK 3: UML Class Diagram

Figure: UML class diagram of the game

Page 66: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 65

Conclusion

The DDOOCP module includes 10 main topics and consists of basic knowledge of object

oriented programming. With the understanding of the class, method, object, actions and

naming the variables.

From this subject, I understand about beware of the origins of Java, understand the reasons

for its wide use, understand and use block structure, understand the distinction between a

class and an object, understand the process of instancing, understand and use data types,

understand and use variables, have a basic understanding and experience of programming

an event, program arithmetic/algebraic expressions, use the methods of string class.

I have learned practical and knowledge from this DDOOCP module in the NCC Education’s

Diploma in Computing. When I do the assignment of this module, I have done all tasks well

my assignment by applying these practical and knowledge.

From this assignment, I understand about the object oriented programming. With practical

skill and knowledge, I test the whole program and test the codes. Draw the fully detailed

UML diagram. Testing the data with black and white box testing techniques. And commonly

use of the basic concepts of java programming.

Page 67: Designing and Developing Object Oriented Computer Programs (DDOOCP)

Presented by AUNG PYAE Designing and Developing Object-Oriented Computer Programs

March 2016 Page - 66

References

DDOOCP Student Workbook (V1.2 - November 2015 Edition)

www.developer.java.com

www.stackoverflow.com

END OF ASSIGNMENT