You are on page 1of 40

Programming Method

Great Event

Module Title

Assignment Title
June 2015
Examination Cycle
Name yay
Candidate Name
Roll no
Candidate No
KMD Computer Centre (Yangon)
Centre Name
Tin Tat Day
Submission Date:

Page | 1
Statement and Confirmation of Own Work

Programme/Qualification name: L4DC

All NCC Education assessed assignments submitted by students must have this statement as
the cover page or it will not be accepted for marking. Please ensure that this statement is either
firmly attached to the cover of the assignment or electronically inserted into the front of the
assignment.

Student declaration

I have read and understood NCC Education’s Policy on Academic Dishonesty and Plagiarism.

I can confirm the following details:

Student ID/Registration number : roll no yay

Name : Name Yay

Centre Name : KMD Computer Centre (Yangon)

Module Name : Designing and Developing Object Oriented Computer Programs

Module Leader : PHYO ZARCHI AUNG

Number of words : ( ) Words

I confirm that this is my own work and that I have not plagiarised any part of it. I have also noted
the assessment criteria and pass mark for assignments.

Due Date : 31ST October 2014

Student Signature :

Submitted Date : 31ST October 2014

Page | 2
Contents
TASK 1..........................................................................................................................................................3
Analysis........................................................................................................................................................4
Assumption..................................................................................................................................................5
Program.......................................................................................................................................................6
TASK 2........................................................................................................................................................20
Test Plan....................................................................................................................................................21
Test Case...................................................................................................................................................23
White Box Testing......................................................................................................................................34
TASK 3........................................................................................................................................................35
Class Diagram............................................................................................................................................36

Page | 3
TASK 1

Page | 4
Analysis
At first, to set up the GUI (Graphical User Interface) for the structural form of Connect

Four. The structure of the game is typically gird box. In the grid box, the objects are constructed

as discs and board. A process that links between discs images and GUI components is

provided. Labels, buttons and so on will include in this process. Then, players are needed to

choose a column. Data validation is also needed to perform valid number in their respective

column. The column does not have valid number when it is not full-filled. Only two players can

play the game. To start the game, players need to click start button. After clicking, it will show

random colour for player 1 and then random colour for player 2 synchronically. The colours are

available into red and yellow. Player 1 places the correct disc colour to its correct row. And then,

it reaches player two’s turn due to the alternate arrangement. The player 2 plays like the player

1. This arrangement will be used while playing game. The players can win the game with four

forms – horizontal, vertical, left diagonal and right diagonal. As an example, “Player 1 yellow is

winner” will be shown with message box when the player 1 won the game. “Player 2 red is

winner” will be shown with message box when the player 2 won. “A game is a draw”

message box will be shown if both players drew.

Page | 5
Assumption
In this game, there are two forms and four classes. To play the game in, start button can

be clicked by the player. It reaches the second form after have been clicked start button. It is

needed to test the condition for random colour. So, the random colour message box will be

shown for the players. The object is produced for game board and message boxes. For the

discs, the other objects are produced. The array list is also needed to construct objects. The

arrangement of the game is needed to test the condition for the players. After this step, the four

classes are produced for the winning positions. The four classes are horizontal, vertical, left

diagonal and right diagonal. It must need to test the condition. When the condition is draw, it

also must need to test draw condition. When this step is over, player needs to restart the game.

If the players do not want to play in unfinished game, it can start to new game when clicking

“start to restart game” button.

Page | 6
Program
Start Page
package conect4game;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class Startpage extends JFrame implements ActionListener{
public JButton button1;
public JButton button2;
public JLabel lblheader1;
public Startpage()
{
this.setTitle("Game Start");
this.setSize(500,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setLocation(100,100);
Color c=new Color(85,170,255);
this.getContentPane().setBackground(c);
lblheader1=new JLabel("Connect Four Game Start Page");
button1=new JButton("Start Game");
button2=new JButton("Exit");
lblheader1.setBounds(100, 10, 200, 20);
button1.setBounds(50,50,100 ,50);
button2.setBounds(200,50 ,100, 50);
button1.addActionListener(this);
button2.addActionListener(this);
this.add(lblheader1);
this.add(button1);

Page | 7
this.add(button2);
this.setVisible(true);
}
public static void main (String args[])
{
Startpage FP =new Startpage();
}

public void actionPerformed(ActionEvent e)


{
if (e.getSource()== button1)
{
PlayFrame objCon4=new PlayFrame();
if(CalculateRandom.CRandom().equals("YELLOW"))
{
ConnectFourGameBoard.p=false;
ConnectFourGameBoard.p1="Player One";
ConnectFourGameBoard.p2="Player Two";
JOptionPane.showMessageDialog(null, "Player One got YELLOW");
}
else
{
ConnectFourGameBoard.p=true;
ConnectFourGameBoard.p2="Player One";
ConnectFourGameBoard.p1="Player Two";
JOptionPane.showMessageDialog(null, "Player One got RED");
}
this.dispose();
}
if (e.getSource()== button2)

Page | 8
{
System.exit(0);
}
}
}

Play Frame
package conect4game;
import javax.swing.*;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.*;
public class PlayFrame extends JFrame implements ActionListener
{
public JButton btnReset;
public static JLabel lbl1;
public static JLabel lbl2;
public Container ctnGameB;
public JPanel pnlGameB;
public PlayFrame()
{
this.setSize(600,600);
this.setLocation(100,100);
this.setTitle("Connect Four Game");
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Color c=new Color(85,170,255);
this.getContentPane().setBackground(c);
btnReset=new JButton("Go To Start Game");

Page | 9
btnReset.addActionListener(this);
lbl1=new JLabel("Player1");
lbl2=new JLabel("Player2");
btnReset.setBounds(10, 10, 150, 20);
lbl1.setBounds(100, 500, 150, 20);
lbl2.setBounds(300, 500, 150, 20);
ctnGameB=new Container();
ctnGameB.setBounds(90, 100, 400, 350);
this.add(ctnGameB);
ConnectFourGameBoard objgb=new ConnectFourGameBoard();
pnlGameB=objgb.gameboard();
ctnGameB.add(pnlGameB);
this.add(btnReset);
this.add(lbl1);
this.add(lbl2);
this.setVisible(true);
}
public void actionPerformed(ActionEvent v)
{if(v.getSource()==btnReset)
{
ConnectFourGameBoard.Clear();
Startpage objst=new Startpage();
objst.show();
this.dispose();
}
}
public static void main (String args[])
{
PlayFrame PG =new PlayFrame();
}

Page | 10
}
ConnectFourGameBoard
package conect4game;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ConnectFourGameBoard extends JFrame implements ActionListener {
public JPanel pnlgameboard;
public static JButton btngame[][];

protected ConnectFourGameBoard()
{}

public static void main(String[] args)


{
ConnectFourGameBoard objGB=new ConnectFourGameBoard();
}

public JPanel gameboard()


{
pnlgameboard=new JPanel();
pnlgameboard.setBounds(0, 0, 400, 350);
btngame = new JButton[6][7];
pnlgameboard.setLayout(new GridLayout(6,7,1,1));
for(int row = 0; row < 6; row++)
{
for(int col = 0; col <7; col++)
{
btngame[row][col] = new JButton();
btngame[row][col].setSize(3,3);

Page | 11
btngame[row][col].setBackground(Color.white);
btngame[row][col].addActionListener(this);
pnlgameboard.add(btngame[row][col]);
}
}
pnlgameboard.setVisible(true);
return pnlgameboard;

public static void Clear()


{
for(int row = 0; row < 6; row++)
{
for(int col = 0; col <7; col++)
{
btngame[row][col].setBackground(null);
btngame[row][col].setBackground(Color.white);
btngame[row][col].setText("");
countNum=0;
}
}
}

static boolean p=false;


static int countNum=0;
int countDiagonal=0;
static String p1,p2;

Page | 12
public void actionPerformed(ActionEvent ae)
{
for(int i = 0;i <6;i++)
{
for(int j = 0; j<7;j++)
{
if(ae.getSource()==btngame[i][j])
{
int x;
countNum++;
for(x=5;x>=0;x--)
{
if(btngame[x][j].getText().equals("") && p==false)
{
if(btngame[x][j].getBackground().equals(Color.YELLOW) || btngame[x]
[j].getBackground().equals(Color.RED))
{
//System.out.println(btngame[x][j].getLocation());

else

{
PlayFrame.lbl1.setText(p2+"'s Turn");
btngame[x][j].setBackground(Color.YELLOW);
btngame[x][j].setForeground(Color.YELLOW);
btngame[x][j].setText("1");

Page | 13
p=true;

if(j>=3)

{
if(btngame[x][j].getText()=="1" && btngame[x][j-1].getText()=="1" &&
btngame[x][j-2].getText()=="1" && btngame[x][j-3].getText()=="1")
{
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}

}
if(j<=3)

{
if(btngame[x][j].getText()=="1" && btngame[x][j+1].getText()=="1" &&
btngame[x][j+2].getText()=="1" && btngame[x][j+3].getText()=="1")
{
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}
}
if(j>=1 && j<5)

Page | 14
if(btngame[x][j].getText()=="1" && btngame[x][j-1].getText()=="1" &&
btngame[x][j+1].getText()=="1" && btngame[x][j+2].getText()=="1")
{
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}
}

if(j<=5 && j>1)

{
if(btngame[x][j].getText()=="1" && btngame[x][j+1].getText()=="1" &&
btngame[x][j-1].getText()=="1" && btngame[x][j-2].getText()=="1")
{
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}

if(x<3)

{
if(btngame[x][j].getText()=="1" && btngame[x+1][j].getText()=="1" &&
btngame[x+2][j].getText()=="1" && btngame[x+3][j].getText()=="1")
{

Page | 15
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}

}
if(x>2 && j>2)
{
if(btngame[x][j].getText()=="1" && btngame[x-1][j-1].getText()=="1" &&
btngame[x-2][j-2].getText()=="1" && btngame[x-3][j-3].getText()=="1")
{
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}
}
if(x<3) //diagonal
{
if(j<=3)
{
if(btngame[x][j].getText()=="1" && btngame[x+1][j+1].getText()=="1" &&
btngame[x+2][j+2].getText()=="1" && btngame[x+3][j+3].getText()=="1")
{
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}
}
if(j>=3)
{

Page | 16
if((btngame[x][j].getText()=="1" && btngame[x+1][j-1].getText()=="1" &&
btngame[x+2][j-2].getText()=="1" && btngame[x+3][j-3].getText()=="1"))
{
JOptionPane.showMessageDialog(null, p1+" YELLOW Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the YELLOW color won");
}
}
}

break;
}
}
else
{
if(btngame[x][j].getBackground().equals(Color.YELLOW) || btngame[x]
[j].getBackground().equals(Color.RED))

{
//System.out.println(btngame[x][j].getLocation());

else

Page | 17
PlayFrame.lbl1.setText(p1+"'s Turn");
btngame[x][j].setBackground(Color.RED);
btngame[x][j].setForeground(Color.RED);
btngame[x][j].setText("2");
p=false;

if(j>=3)
{
if(btngame[x][j].getText()=="2" && btngame[x][j-1].getText()=="2" &&
btngame[x][j-2].getText()=="2" && btngame[x][j-3].getText()=="2")
{
JOptionPane.showMessageDialog(null, p2+" RED Win!");
Clear();
PlayFrame.lbl2.setText(p2+" with the RED color won");
}
}
if(j<=3)
{
if(btngame[x][j].getText()=="2" && btngame[x][j+1].getText()=="2" &&
btngame[x][j+2].getText()=="2" && btngame[x][j+3].getText()=="2")
{
JOptionPane.showMessageDialog(null, p2+" RED Win!");
Clear();
PlayFrame.lbl2.setText(p2+" with the RED color won");
}
}
if(j>=1 && j<5)
{
if(btngame[x][j].getText()=="2" && btngame[x][j-1].getText()=="2" &&
btngame[x][j+1].getText()=="2" && btngame[x][j+2].getText()=="2")

Page | 18
{
JOptionPane.showMessageDialog(null, p2+" RED Win!");
Clear();
PlayFrame.lbl2.setText(p2+" with the RED color won");
}
}
if(j<=5 && j>1)
{
if(btngame[x][j].getText()=="2" && btngame[x][j+1].getText()=="2" &&
btngame[x][j-1].getText()=="2" && btngame[x][j-2].getText()=="2")
{
JOptionPane.showMessageDialog(null, p2+" RED Win!");
Clear();
PlayFrame.lbl2.setText(p2+" with the RED color won");
}
}
if(x<3)
{
if(btngame[x][j].getText()=="2" && btngame[x+1][j].getText()=="2" &&
btngame[x+2][j].getText()=="2" && btngame[x+3][j].getText()=="2")
{
JOptionPane.showMessageDialog(null, p2+" RED Win!");
Clear();
PlayFrame.lbl2.setText(p2+" with the RED color won");
}
}
if(x<3)
{
if(j<=3)
{

Page | 19
if(btngame[x][j].getText()=="2" && btngame[x+1][j+1].getText()=="2" &&
btngame[x+2][j+2].getText()=="2" && btngame[x+3][j+3].getText()=="2")
{
JOptionPane.showMessageDialog(null, p1+" RED Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the RED color won");
}
}
if(j>=3)
{
if((btngame[x][j].getText()=="2" && btngame[x+1][j-1].getText()=="2" &&
btngame[x+2][j-2].getText()=="2" && btngame[x+3][j-3].getText()=="2"))
{
JOptionPane.showMessageDialog(null, p1+" RED Win!");
Clear();
PlayFrame.lbl2.setText(p1+" with the RED color won");
}
}
}
break;

}
}
if(countNum==42)
{
JOptionPane.showMessageDialog(null, "The Game is a draw");
Clear();
PlayFrame.lbl2.setText("Draw!!!!!!!!!!");
break;
}

Page | 20
}
}
}
}
}}

CalculateRandom
package conect4game;

public class CalculateRandom {


static int Norandom=0;
static String RColor="";
public static String CRandom()
{
Norandom=(int)(Math.random()*2+1);
if(Norandom==1)
{
RColor="RED";
}
if(Norandom==2)
{
RColor="YELLOW";
}

return RColor ;
}
public static void main(String[] args)
{
CalculateRandom random =new CalculateRandom();
System.out.println(random.CRandom());
}
}

Page | 21
TASK 2

Page | 22
Test Plan
Test Plan and Test Log for Unit Testing

Test Description of Input Values Date & Expected Type of


Case No Test Case Time Result Testing

1 The button will 26 March To show Black Box


placed on the 2015 button on Test
grid board. Click “Start” grid board
button 12:00 AM

2 The button First click at on a 26 March To change Black Box


color will seat button 2015 Button Color Test
change to means
yellow color 12:10 AM yellow
when click on
button at first
time

3 The button Second click at on 26 March To change Black Box


color will a seat button 2015 Button Color Test
change to red means red
color when click 12:20 AM
on button at first
time

4 The button Third click at on a 26 March To change Black Box


color will seat button 2015 Button Color Test
change to means
green color 12:30 AM Green
when click on
button at first
time

5 To save data Click save button 26 March To save data Black Box
values on grid board 2015 in text file Test
according to and show
each button on 12:40 AM successfully
seat grid board saved
message

6 To show button Click show ticket 26 March Display Black Box


color on grid status 2015 button color Test
board that read on button
from text file grid

Page | 23
12:50 AM

7 If user want to Click Reset button 26 March Show all seat Black Box
clear all record 2015 button will Test
color on each change to
seat button 1:10 AM green color

8 User want to Click auto allocate 26 March Display the Black Box
auto allocate button 2015 auto allocate Test
seat on grid message box
board 1:20 AM will show

9 Request Enter allocation 26 March Show input Black Box


number of seat number of seat at 2015 message box Test
that user want input box
to booking 1:30 AM
number

10 Request seat Enter seat 26 March Show Input Black Box


number that number that user 2015 message box Test
user want to require
choice 1:40 AM

11 To allocate seat Enter number of 26 March Automatically Black Box


number seat and seat 2015 seat placed Test
automatically number of button
1:50 AM

Page | 24
Test Case
Test Case No 1

Test Data Click “show ticket status” button

Type of Data Normal

Expected Result To show button on grid board.

Actual Result See Figure 1

Figure 1

Page | 25
Test Case

Test Case No 2

Test Data First click at on a seat button

Type of Data Normal

Expected Result To change Button Color means yellow

Actual Result See Figure 2

Figure 2

Page | 26
Test Case

Test Case No 3

Test Data Second click at on a seat button

Type of Data Normal

Expected Result To change Button Color means red

Actual Result See Figure 3

Figure 3

Page | 27
Test Case

Test Case No 4

Test Data Third click at on a seat button

Type of Data Normal

Expected Result To change Button Color means Green

Actual Result See Figure 4

Figure 4

Page | 28
Test Case

Test Case No 5

Test Data Click save button on grid board

Type of Data Normal

Expected Result To save data in text file and show successfully saved
message

Actual Result See Figure 5

Figure 5

Page | 29
Test Case

Test Case No 6

Test Data Click show ticket status

Type of Data Normal

Expected Result Display button color on button grid

Actual Result See Figure 6

Figure 6

Page | 30
Test Case

Test Case No 7

Test Data If user want to clear all record color on each seat button

Type of Data Normal

Expected Result Show all seat button will change to green color

Actual Result See Figure 7

Figure 7

Page | 31
Test Case

Test Case No 8

Test Data User want to auto allocate seat on grid board

Type of Data Normal

Expected Result Display the auto allocate message box will show

Actual Result See Figure 8

Figure 8

Page | 32
Test Case

Test Case No 9

Test Data Request number of seat that user want to booking number

Type of Data Normal

Expected Result Show input message box

Actual Result See Figure 9

Figure 9

Page | 33
Test Case

Test Case No 10

Test Data Request seat number that user want to choice

Type of Data Normal

Expected Result Show Input message box

Actual Result See Figure 10

Figure 10

Page | 34
Test Case

Test Case No 11

Test Data To allocate seat number automatically

Type of Data Normal

Expected Result Automatically seat placed

Actual Result See Figure 11

Figure 11

Page | 35
White Box Testing for CRandom (Desk Checking)
1.for (int i = 0; i < row; i++)
{
2.for (int j = 0; j < col; j++)
{
3.if(e.getSource()==btns[i][j])
{
4.Color colors[] = new Color[3];
5.colors[0] = Color.green;
6.colors[1] = Color.yellow;
7.colors[2] = Color.red;
8.if(btns[i][j].getBackground()==(colors[0]))
{
9.btns[i][j].setBackground(colors[1]);
}
10.else if(btns[i][j].getBackground()==(colors[1]))
{
11.btns[i][j].setBackground(colors[2]);
}
12.else if(btns[i][j].getBackground()==(colors[2]))
{
13.btns[i][j].setBackground(colors[0]);
}
}
}
}

Line I J btns[i][j] Click Condition Condition Condition3 Actual


No 1 2 Result
1

public void actionPerformed(ActionEvent e)


{
1. int row = Character.getNumericValue(button_label.charAt(0));
2. int column = Character.getNumericValue(button_label.charAt(1));
3. clicks++;

4. if (clicks % 3 == 1) ------- condition 1


{
5. btns[row][column].setBackground(Color.yellow);}

Page | 36
6. else if (clicks % 3 == 2) ---------- condition 2
{
7. btns[row][column].setBackground(Color.red);
}
8. else if (clicks % 3 == 0) ---------------- condition 3
{
9. btns[row][column].setBackground(Color.green);

Line row column clicks condition 1 btns[row] condition 2 Conditi Final


No. [column] on 3 Result

1 3

2 2

3 1

4 true

5 btns[3] To
[2].setbac show
kground=y yellow
ellow color at
row 3
column
2

6 false

8 false

Page | 37
TASK 3

Page | 38
Class Diagram

Page | 39
EventOne
EventTwo
+button: JButton
+contentPane: Container +button: JButton
+btns: JButton +contentPane: Container
+clicks: int +btns: JButton
+btnSave: JButton +btnSave: JButton
+btnreset: JButton +btnreset: JButton
+btnNew: JButton +btnNew: JButton
+btnallocate: JButton +btnallocate: JButton
+pnlGameBoard: JPanel +pnlGameBoard: JPanel

+init() +init()
+actionPerformed(Action Event) +actionPerformed(Action Event)

MainGreateEvent
+btnevent1: JButton
+btnevent2: JButton
+btnevent3: JButton

+MainGreateEvent()
+actionPerformed(Action Event)
+main(String)

EventThree
+button: JButton
+contentPane: Container
+btns: JButton
+btnSave: JButton
+btnreset: JButton
+btnNew: JButton
+btnallocate: JButton
+pnlGameBoard: JPanel
+init()
+actionPerformed(Action Event)

Page | 40

You might also like