Вы находитесь на странице: 1из 28

5

Assignment Front Sheet HND Division - IDM Computer Studies

Learner name Edexcel No. IDM Reg. No.

Date Issued Draft Submission date Completion date Submitted on


14th August 2015 30th November 2015

Qualification Unit number and title


HND in Computing and Systems Development 41 Programming in Java

Set by Ms.Ishani Jayasuriya


Assessor name

Branch

In this assignment you will have opportunities to provide evidence against the following criteria.

Indicate the page numbers where the evidence can be found

Learner declaration

I certify that the work submitted or this assignment is my own and research sources are fully acknowledged.

Learner signature: Date:

Outcomes/Grade Descriptors Achieved (Please Tick)

Outcomes/ Grade Descriptors P41.1 P41.2 P41.3 P41.4

1.1 1.2 2.1 2.2 3.1 3.2 3.3 3.4 3.5 4.1 4.2 4.3 4.4 4.5

Outcomes/ Grade Descriptors M1 M2 M3 D1 D2 D3 Grade Offered

Assessor comment:

Signature: Date:

Page 1 of 28
Evidence /
Page No. (to
To achieve the criteria the evidence be filled
Criteria reference Task no.
must show that the student is able by the
to: student)

P41.1.1 Discuss about programming Explain Machine language, T1.1


language. Assemble language and High
level language

P41.1.2 Critically evaluate the Procedural Explain Procedural programming and T1.2
programming and Object Oriented Object Oriented language
Programming.
P41.1.3 Define features of Object Oriented Discuss features of Object Oriented
Programing. Encapsulation, Inheritance, Programing T1.3
Polymorphism, Abstraction etc..

P41.1.4 Discuss fundamentals or Elements of fundamentals or Elements of java T1.4


java

Discuss about the statements and the


P41.2.1 Explain the types of Control flow two types of control flow statement. T2.1 , T2.2
statement in java. Selection If and switch,
Repetition While, Do while and For.

P41.3.1 Implement a Java Programming Provide the class and activity diagrams T3.1
solution based on a prepared design. for the given COLLECT FOUR java
Provide the required algorithms. Class game.
diagrams and activity diagrams.

P41.3.2 Make effective use of an Design necessary user interfaces


Integrated Development Using java programming language, T3.2
Environment (IDE) including code and implement the COLLECT FOUR java
screen templates game.

P41.4.1 critically review and Carry out complete system testing and
test a Java programming solution provide user guide. System testing and T4.1
user guide must include suitable screen
shots.

P41.4.2 analyse actual test Carry out complete system testing and
results against expected results to identify provide user guide. System testing and T4.2
discrepancies user guide must include suitable screen
shots

P41.5.1 create user Carry out complete system testing and T5.1
documentation for the provide ,
developed Java program solution user guide. System testing and user T5.2
guide must include suitable screen
shots. Test your complete project
with suitable data

Page 2 of 28
Evidence /
Page No.
To achieve the criteria the evidence must
Criteria reference Task no. (to be filled
show that the student is able to:
by the
student)
M1 Identify and apply Produce efficient requirement specification Task1,Task2,
strategies to find according to given criteria (M1.1) Task3
appropriate solutions
M2 Select / design Develop a solution which is performed basic
appropriate methods / function (M2.4). Task2,Task3,
techniques Task 4,Task5
M3 Present and communicate Establish database connection with JDBC or
Appropriate findings ODBC drivers (M3.5) Task 2, Task
4

D1 Use critical reflection to The Validity of results has been evaluated All Tasks
evaluate own work and justify using defined criteria(D1.2)
valid conclusions

D2 Take responsibility for Demonstrate it has own work and lessoned


managing and organizing activities learned using the Researching(D2.1) All Tasks

D3 Demonstrate convergent / Problems have been solved(D3.4) All tasks


lateral / creative thinking Representative of the new own ideas of
work(D3.6)
Effective way of thinking(D3.7)

Page 3 of 28
Page 4 of 28
Assignment brief
Qualification HND in Computing and Systems Development
Unit number and title 41 Programming in Java
Start date 14th August 2015
Deadline 30th November 2015
Ms.Ishani Jayasuriya
Assessor name

Assignment title CONNECT FOUR

Page 5 of 28
For this assignment, you must develop a Connect Four game. Connect Four is a two-
player game played on a vertical grid that is 7 squares wide by 6 squares high. Each cell
can store one disc. Each player is given 21 discs. One player uses red discs and the
other player uses yellow discs. The players can drop one disc into the grid per turn. The
discs will drop to the lowest empty space in the chosen column (due to gravity). The aim
of the game is for a player to get 4 in a row of their disc colour vertically, horizontally,
or diagonally. Once a player achieves this, they are declared the winner and the game
ends. A check must be performed each turn to see if 4-in-a-row has been achieved. If the
grid becomes full (no cells free) and neither player has achieved 4-in-a-row then the
game is declared a draw and ends.

Connect Four is a turn based game. At the start of the game, the grid is empty, and will
look like the diagram below. White circles indicate that the board is empty. This is for
demonstration
purposes only and it is acceptable for your own application to use squares:

The game proceeds in a series of turns. During each turn, the player whose turn it is
drops one of their discs into one of the columns. If this results in a win, or a full board
without a win, then the game ends. In all other situations, the turn switches to the other
player, who will drop one of their discs (of a different colour) into one of the columns.

The minimum number of turns in which four-in-a-row can be achieved is 7, so there is no


need to check for a win during the first 6 turns of the game.
Playing through an example game should help to demonstrate how the game should work.

Turn 1: Player One is using Yellow discs, and places their disc in column 4:

Page 6 of 28
As there were no other discs on the board, the yellow disc drops to the bottom of column
4. The
turn switches to Player Two who is using red discs.

Turn 2: Player Two is using Red discs, and places their disc in column 4:

As there was already a disc in column four, the red disc drops to the second bottom row of
the column, and sits on top of the yellow disc already in the column.

Page 7 of 28
The turn then switches back to Player One.

Turn 3: Player One places a disc in column 3:

As there were no other discs in column 3, the yellow disc drops to the bottom of column 3.
The turn switches to Player Two.

Turn 4: Player Two places a disc in column 4:

Page 8 of 28
As there were already two discs in column 4, the disc drops to the lowest empty row,
sitting on top of the previously placed discs. The turn then switches to Player One.

Turn 5: Player One places a disc in column 5:

As there were no other discs in column 5, the yellow disc drops to the bottom of column 5.
The turn switches to Player Two.

Turn 6: Player Two places a disc in column 2:

As there were no other discs in column 2, the red disc drops to the bottom of column 2.
The
turn switches to Player One.

Page 9 of 28
Turn 7: Player One places a disc in column 6:

As there were no other discs in column 6, the yellow disc drops to the bottom of column 6.
As there are now four yellow discs in a row, a message should be displayed to indicate that
the game is over and Player One/ Yellow has one:

As indicated, four-in-a-row can be achieved either horizontally (as in the above game),
vertically, or diagonally. Some screenshots of valid win conditions are shown below. The
winning line of discs is shown with a black line through them to make them easier to spot.
However, your program is not required to , show this screenshot. Your program only needs
to display a win message and end the game.

Examples :

Page 10 of 28
The Wikipedia page http://en.wikipedia.org/wiki/Connect_Four has more details on how
Connect Four works. You should note that the original game is a vertical board-based
game. You should also note that you are only required to implement the features discussed
in the assignment brief.

Your application should be presented as one window or form containing a 7 columns by 6


rows grid of buttons, each representing a square which may or may not contain a disc of
either colour. Underneath should be two labels. The first label should display whose turn it
is (Player One or Player Two). The second label should display important game updates
(e.g. if player one or player two achieves a wine, if a draw is reached, and if the game is a
draw).

At the start of the game, the player to go first should be chosen at random, and a
message displayed to indicate whether Player One is the yellow disc or the red disc player.
The method for selecting a column is at the discretion of the programmer. Suitable options
include providing buttons for Column 1 to Column 7 inclusive which may be pressed to
indicate column selection, or by asking the user to type in the column number they wish to
drop their disc into. Suitable validation checks should be carried out to ensure the column
number is valid, and that the column has space in it (i.e. it is not already full with 6 discs).

There is no limit on the number of turns, other than that there cannot be more than 42
turns as there are only 42 cells on the grid. The game continues until either one player
achieves four-in a-row horizontally, vertically or diagonally, or the board is full and four-in-
a-row has not been achieved by either player.

Page 11 of 28
Task 01

1. Briefly explain the differences between Machine language, Assemble language and High level language
This task provides evidence for P41.1.1
2. Give a brief definition about the differences between Procedural programming and Object Oriented
Programming.
This task provides evidence for P41.1.2
3. List down the features of Object Oriented Programing and explain them briefly
This task provides evidence for P41.1.3
4. Explain the fundamentals or Elements of java
This task provides evidence for P41.1.4

Task 02
1. In java Control flow statement used to change the sequence of execution within blocks. There are two
types in control flow statement. Explain them concisely.
This task provides evidence for P41.2.1

2. Display 30 to 80 by using Do while and For iteration statements. Provide the Source code and the screen
shot of the output.
This task provides evidence for P41.2.2

Page 12 of 28
Task 03

3.1 The designs of all the required algorithms are required as part of this task. You can use suitable design
techniques (Class diagrams, Activity diagrams)
This task provides evidence for P41.3.1

3.2 Design necessary user interfaces.


This task provides evidence for P41.3.2

Task 04

4.1 Using java programming language, implement the CONNECT FOUR java game.
Your program will need to perform the following operations
Represent discs as objects.
Represent the grid/ board as an object.
Provide a way to link disc images to suitable GUI components e.g. labels or buttons.
Allow the player to select a column.
Perform data validation to ensure the column number is valid and that the column
is not full.
Place the correct color of disc in the correct row of the chosen column.
Keep track of whose turn it is.
Display a Game Over message once four-in-a-row has been achieved horizontally,
vertically or diagonally, and display a message saying which player was the winner.
Display a Game Over message once the board is full, and display a message
saying
Draw if neither player has four-in-a-row when the board is full.

This task provides evidence for P41.4.1

4.2 Provide evidence and solutions for error handling during software implementation.
This task provides evidence for P41.4.2

Page 13 of 28
Task 05

5.1 Carry out complete system testing and provide user guide. System testing and user guide must include
suitable screen shots.
This task provides evidence for P41.5.1

5.2 Produce suitable screenshots and solutions for error handling during testing.
This task provides evidence for P41.5.1

All assignments should be submitted in the correct portfolio format by the required deadline and checked fully for
Spelling and grammar.
Your portfolio should have a title page and a contents page with suitable subsections and page number referencing.
Use appropriate search techniques to locate and select relevant information researching into security matters

Combine and present information in ways that are fit for purpose and audience explaining encryption techniques and
ethical decision making.

Sources of information
Books

Bloch J Effective Java, Second Edition (Prentice Hall, 2008) ISBN: 0321356683

Goetz B Java Concurrency in Practice (Addison Wesley, 2006) ISBN: 0321349601

Niemeyer P Learning Java, Third Edition (OReilly, 2005) ISBN: 0596008732

This brief has been verified as being fit for purpose

Assessor
Signature Date
Internal verifier
Signature Date

Page 14 of 28
Contents
Acknowledgement................................................................................................................................................................ 15
Y
Task 01................................................................................................................................................................................. 16
Task1.1 ...............16
Task1.2 .......................................................16
Task1.3............................17
Task1.4................................18
Task 02................................................................................................................................................................................. 20
Task2.1 .......................................................20
Task2.2........................................................................................22

Task 03................................................................................................................................................................................. 23
Task3.1 ..................................................................................................................................................................................23
Task3.2 ......24

Task 04................................................................................................................................................................................. 24
Task4.1 ...............24
Task4.2 .......24

Task 05................................................................................................................................................................................. 24
Task5.1 ...........................................24
Task5.2 ...................................................................................25

Reference............................................................................................................................................................................. 26

Page 15 of 28
Acknowledgement

The acknowledgement may go on like this........


I would like to express my special thanks of gratitude to my lecture Mr.Thanush Sakthithash &
IDM Staff who gave me the golden opportunity to do this wonderful project on the topic
__PROGRAMMING in Java________, which also helped me in doing a lot of Research and i
came to know about so many new things. I am really thankful to them.
Secondly i would also like to thank my parents and friends who helped me a lot in finishing this
project within the limited time.

I am making this project not only for marks but to also increase my knowledge.
Once again thank you to all for helping me.

Page 16 of 28
Task 1
1.1. Briefly explain the differences between Machine language, Assemble language and High level language
Answer)

Programming language are classified as

*Machine language
*Assembly language
* High level language

Machine language: Machine language or machine code is the native language directly understood by the computers central
processing unit or CPU. This type of computer language is not easy to understand, as it only uses a binary system, an element
of notations containing only a series of numbers consisting of one and zero, to produce commands.

Assembly language: Assembly Language is a set of codes that can run directly on the computers processor. This type of
language is most appropriate in writing operating systems and maintaining desktop applications. With the assembly level
language, it is easier for a programmer to define commands. It is easier to understand and use as compared to machine
language.

High level language: High Level Languages are user-friendly languages which are similar to English with vocabulary of
words and symbols. There are easier to learn and require less time to write.
They are problem oriented rather than machine based.
Program written in a high-level language can be translated into many machine language and therefore can run on any
computer for which there exists an appropriate translator.

1.2. Give a brief definition about the differences between Procedural programming and Object Oriented Programming.
Answer)
Object-oriented Programming Languages
Object-oriented Programming is a programming language that uses classes and objects to create models based on the real
world environment. An Object-oriented Programming application may use a collection of objects which will pass messages
when called upon to request a specific service or information. Objects are able to pass, receive messages or process
information in the form of data.

Procedural Programming Languages


Procedural Programming which at times has been referred to as inline programming takes a more top down approach to
programming. Object-oriented Programming uses classes and objects, Procedural Programming takes on applications by
solving problems from the top of the code down to the bottom.

Page 17 of 28
1.3. List down the features of Object Oriented Programing and explain them briefly
Answer)

These are the features of Object Oriented Programming

*Class
*Object
*Polymorphism
*Encapsulation
*Inheritance
*Abstraction

Page 18 of 28
Class
A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and
behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model
state and behavior.

Object
an object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects
that you find in everyday life.

Polymorphism
A Greek term means ability to take more than one form. An operation may exhibit different behaviors in different instances.
The behavior depends upon the types of data used in the operation.

Encapsulation
The technical term for combining data and functions together as a bundle is encapsulation.

Inheritance
this provides a powerful and natural mechanism for organizing and structuring your software. This section explains how
classes inherit state and behavior from their super classes, and explains how to derive one class from another using the
simple syntax provided by the Java programming

Abstraction
The process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other
words, it deals with the outside view of an object (interface).

1.4. Explain the fundamentals or Elements of java


Answer)

Java platform overview


Java technology is used to develop applications for a wide range of environments, from consumer devices to heterogeneous
enterprise systems. In this section, get a high-level view of the Java platform and its components.

The java language


Like any programming language, the Java language has its own structure, syntax rules, and programming paradigm. The Java
language's programming paradigm is based on the concept of OOP, which the language's features support. The Java language
is a C-language derivative, so its syntax rules look much like C's. For example, code blocks are modularized into methods
and delimited by braces ({ and }), and variables are declared before they are used. Structurally, the Java language starts with
packages. A package is the Java language's namespace mechanism. Within packages are classes, when considering a Java
program it can be defined as a collection of objects that communicate via invoking each other's methods. Now briefly look
into what do class, and within classes are methods, variables, constants, and more.

Object - software object with a real world object, they have very similar characteristics. Software objects also have a state
and behavior. A software object's state is stored in fields and behavior is shown via methods. So in software development,
methods operate on the internal state of an object and the object-to-object communication is done via methods.

Class - A class can be defined as a template/ blue print that describes the behaviors/states that object of its type support.

Methods - A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written,
data is manipulated and all the actions are executed.

Instance Variables - Each object has its unique set of instance variables. An object's state is created by the values assigned to
these instance variables.

The Java compiler

Page 19 of 28
When you program for the Java platform, you write source code in .java files and then compile them. The compiler checks
your code against the language's syntax rules, then writes out bytecode in .class files. Bytecode is a set of instructions targeted
to run on a Java virtual machine (JVM). In adding this level of abstraction, the Java compiler differs from other language
compilers, which write out instructions suitable for the CPU chipset the program will run on.

First java Program:

Lets look at a simple code that would print the words Hello World.

Let's look at how to save the file, compile and run the program. Please follow the steps given below:

* Open notepad and add the code as above.

* Save the file as: MyFirstJavaProgram.java.

* Open a command prompt window and go to the directory where you saved the class. Assume it's C:\.

* Type ' javac MyFirstJavaProgram.java' and press enter to compile your code. If there are no errors in your code, the
command prompt will take you to the next line (Assumption: The path variable is set).

* Now, type ' java MyFirstJavaProgram ' to run your program.

* You will be able to see ' Hello World ' printed on the window.

Basic syntax
about java programs, it is very important to keep in mind the following points.

Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.

Class Names - For all class names the first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.
Example class MyFirstJavaClass

Method Names - All method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.
Example public void myMethodName()

Program File Name - Name of the program file should exactly match the class name.

When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end
of the name (if the file name and the class name do not match your program will not compile).

Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'

public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part
of every Java program

Page 20 of 28
Task 2
2.1. In java Control flow statement used to change the sequence of execution within blocks. There are two types in control flow
statement. Explain them concisely.
Answer)
There are two categories of control flow statement

*Selection Statements : (if, if-else and switch)


*Loop Statements : (while, do-while and for)

Selection Statement

*if statement

The if statement executes a block of code only if the specified expression is true. If the value is false, then the If block is
skipped and execution continues with the rest of the program. You can either have a single statement or a block of code
within an If statement. Note that the conditional expression must be a Boolean expression.

Output
b>a

Page 21 of 28
*If-else statement

the if/else statement is an extension of the If statement. If the statements in the If statement fails, the statements in the else
block are executed. You can either have a single statement or a block of code within if-else blocks. Note that the conditional
expression must be a Boolean expression.

Output
b>a

*Switch case statement

the switch case statement, also called a case statement is a multi-way branch with several choices. A switch is easier to
implement than a series of if/else statements. The switch statement begins with a keyword, followed by an expression that
equates to a no long integral value. Following the controlling expression is a code block that contains zero or more labeled
cases. Each label must equate to an integer constant and each must be unique. When the switch statement executes, it
compares the value of the controlling expression to the values of each case label. The program will select the value of the
case label that equals the value of the controlling expression and branch down that path to the end of the code block. If none
of the case label values match, then none of the codes within the switch statement code block will be executed. Java includes
a default label to use in cases where there are no matches.

Page 22 of 28
Output
c is the greatest

Loop Statement

*While statement

the while statement is a looping construct control statement that executes a block of code while a condition is true. You can
either have a single statement or a block of code within the while loop. The loop will never be executed if the testing
expression evaluates to false. The loop condition must be a Boolean expression.

Output
number prints from 1 to 10

*Do-while Statement

The do-while loop is similar to the while loop, except that the test is performed at the end of the loop instead of at the
beginning. This ensures that the loop will be executed at least once. A do-while loop begins with the keyword do, followed by
the statements that make up the body of the loop. Finally, the keyword while and the test expression completes the do-while
loop. When the loop condition becomes false, the loop is terminated and execution continues with the statement immediately
following the loop. You can either have a single statement or a block of code within the do-while loop.

Output
number prints from 1 to 10

*For Loop Statement

the For Loop is a looping construct which can execute a set of instructions a specified number of times. Its a counter
controlled loop.

Output
number prints from 1 to 10

2.2. Display 30 to 80 by using Do While and FOR iteration statements. Provide the Source code and the screen shot of the output.
Answer)

Do While loop For loop

Page 23 of 28
For both loops shows the same output 30 to 80 in vertical position

Task 3
3.1. The designs of all the required algorithms are required as part of this task. You can use suitable design techniques
(Class diagrams, Activity diagrams)
Answer)
Activity Diagram

Page 24 of 28
Class Diagram

3.2. Design necessary user interfaces.


Answer)
4.

Task 4

4.1. Using java programming language, implement the CONNECT FOUR java game. Your program will need to perform the
following operations

Page 25 of 28
Answer) Connect4 java game is working perfectly

4.2. Provide evidence and solutions for error handling during software implementation.
Answer) for player1 (red) winner message for player2 (blue) winner message

Task 5

5.1. Carry out complete system testing and provide user guide. System testing and user guide must include suitable screen shots.
Answer)

* run (Connect4.java)

* only two players can play connect4, player-1 (Red) vs player-2 (Blue)

*Players take turn to drop coins. Click top arrows to drop.

*To win, you have to from a line of 4 coins. The line can be vertical, horizontal or diagonal.

*If the both players fill the board with full of coins then it will be tie and the coin will turn to yellow, then player must reset
the game.

5.2. Produce suitable screenshots and solutions for error handling during testing.
Answer)

for player1 (red) winner message for player2 (blue) winner message

Page 26 of 28
When both players are draw then press reset

Reference
Task1.1: http://oer.nios.ac.in/wiki/index.php/COMPUTER_LANGUAGE
Task1.2: https://neonbrand.com/website-design/procedural-programming-vs-object-oriented-programming-a-review/
Task1.3: http://studytipsandtricks.blogspot.com/2012/04/features-of-object-oriented-programming.html
Task1.4: http://www.ibm.com/developerworks/java/tutorials/j-introtojava1/
http://www.tutorialspoint.com/java/java_basic_syntax.htm

Task2.1: http://www.wideskills.com/java-tutorial/java-control-flow-statements
Task2.2: Done by Student

Task3.1: Done by Student


Task3.2: Done by Student

Task4.1: Done by Student


Task4.2: Done by Student

Task5.1: Done by Student


Task5.2: Done by Student

Page 27 of 28
Page 28 of 28