Professional Documents
Culture Documents
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
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 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.
Student Signature :
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”
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
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();
}
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()
{}
Page | 11
btngame[row][col].setBackground(Color.white);
btngame[row][col].addActionListener(this);
pnlgameboard.add(btngame[row][col]);
}
}
pnlgameboard.setVisible(true);
return pnlgameboard;
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(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;
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
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
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
Page | 24
Test Case
Test Case No 1
Figure 1
Page | 25
Test Case
Test Case No 2
Figure 2
Page | 26
Test Case
Test Case No 3
Figure 3
Page | 27
Test Case
Test Case No 4
Figure 4
Page | 28
Test Case
Test Case No 5
Expected Result To save data in text file and show successfully saved
message
Figure 5
Page | 29
Test Case
Test Case No 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
Expected Result Show all seat button will change to green color
Figure 7
Page | 31
Test Case
Test Case No 8
Expected Result Display the auto allocate message box will show
Figure 8
Page | 32
Test Case
Test Case No 9
Test Data Request number of seat that user want to booking number
Figure 9
Page | 33
Test Case
Test Case No 10
Figure 10
Page | 34
Test Case
Test Case No 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]);
}
}
}
}
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);
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