الأسايمنت جافا الأولي

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 33

Pearson BTEC Level 5 HND Diploma in Computing and Systems Development

Unit No and Title


Unit 23 - Mathematics for software Development

Learner Full Name:


(MAZEN OBAIDEEN)

Registration Number:
(JG97374)

Assignment No. 1 of 1

Assignment Title: Electricity invoice calculation - Part 1 (1 of 1)

ABC HORIZON Pearson BTEC Approved Centre


Centre Number: 91667

MAZEN OBAIDEEN Unit 17 Page 1 of 33


LEARNER ASSIGNMENT SUBMISSION AND DECLARATION

When submitting evidence for assignment, each learner must sign a


declaration confirming that the work is their own.

Learner Full Name MAZEN OBAIDEEN


Registration No: JG97374

Program Title Pearson BTEC Level 5 HND Diploma in Computing and Systems Developme

Unit No and Title Unit 41 - Programming in Java


Assignment No. 1 of 1
Assignment Title Electricity invoice calculation
Assessor Name Mohamad Obaid
Lecturer’s Name Mohamad Obaid
Issue Date 5/26/2018
Deadline 6/12/2018
Date Submitted 6/12/2018
Learner Declaration
I certify that the work submitted for this assignment is my own and any
similarity is within the range of plagiarism 20%. I have clearly referenced
and acknowledged any sources or research as per Harvard Referencing
System. I understand that false declaration is a form of malpractice and
subject to penalty. In case the plagiarism is detected in my work, the
management has all the right to cancel my assignment and take action
against me.

Learner Signature: Mazen Obaideen


Date: 06-Jun-18
Note: Attach this form with the assignment

MAZEN OBAIDEEN Unit 17 Page 2 of 33


Guidelines for the Assignment:

1. Use office 2016


2. Page Size is A4.
3. Use standard Arial font size 12.
4. Use 1.5 line spacing.
5. Have a 1.27 centimeters’ margin on all the sides. Use the Narrow Setting.
6. Include page numbers.
7. Headings: use 16-point Arial Bold for first level headings, and 14 point Arial Bold for second
level headings. If a third level heading is required, use 12 point Arial Bold.
8. Attach a completed Statement and Confirmation of Own Work to the front of the paper copy
of your assignment.
9. The first page of your assignment should be a title page, which should also state your
name, BTEC ID number and the name of the Center where you are studying.
10. Include a table of contents, you must use "Automatic table of content" by go to references >
Table of content > automatic table 2
11. Start each task on a new page and include the question at the top of the page.
12. Ensure any diagrams, screen shots, PowerPoint slides, etc. fit correctly on the page and a
referenced, for example, Fig. 1, Fig. 2, etc.
13. Check spelling, grammar and punctuation.
14. You should also ensure that you proof read your assignments, before submitting, because
the MS Word auto checking software doesn't always highlight every mistake.
15. Use accurate Harvard referencing and include a bibliography. (Citation and Referencing), ,
you must use " references " by go to references > Bibliography > references. Add
references at the end of report
16. Write your name, unit name and page number in the footer of your assignment document.
17. Upload your assignment and all the related files into ABC HORIZON LMS.

MAZEN OBAIDEEN Unit 17 Page 3 of 33


‫المحتويات‬
TASK 1........................................................................................................................................................................... 5

1.1................................................................................................................................................................................... 5

1.2................................................................................................................................................................................. 15

TASK 2.........................................................................................................................................................................17

2.1................................................................................................................................................................................. 17

2.2................................................................................................................................................................................. 21

Task 3.......................................................................................................................................................................... 23

3.1................................................................................................................................................................................. 23

3.2................................................................................................................................................................................. 24

3.5................................................................................................................................................................................. 25

3.6................................................................................................................................................................................. 25

Task 4.......................................................................................................................................................................... 27

4.1................................................................................................................................................................................. 27

4.2................................................................................................................................................................................. 28

4.3................................................................................................................................................................................. 28

4.4................................................................................................................................................................................. 29

Gantt chart

MAZEN OBAIDEEN Unit 17 Page 4 of 33


MAZEN OBAIDEEN Unit 17 Page 5 of 33
TASK 1

1.1
Characteristics:

Java is a global language that is widely distributed and also known as object oriented

Powerful, safe, dynamic, high-resiliency is supportive and oriented to entities

Also help in designing games and creating programs with graphical user interface

You can achieve the required benefit from all Internet features

It is characterized by a library containing instructions and ready-made taps to design software of a


sophisticated technical nature

Java provides an interactive environment over the Web

It also enables us to create programs for personal and professional use. These programs are
performed through a variety of editors or environments that facilitate the writing of commands such
as : NetBeans IDE , Eclipse

It is known that the Java language contains the so-called "class"

It is a statment used frequently to execute commands , they contain templates for creating objects
and for determining the methods and types of object data all class objects must contain the
properties of the base class , Because classes are categories , and entities are elements within
each category

To declare a class , consist of the following sections

Then the name of the class (class name), the keywords and finally the text of the printed code
within the brackets { }

Software systems developed using operational programming languages are based on


implementation , OOP offers real models in terms of everything that can be modeled as something

On the example, the table is an object, the object book, The person is an object

Java is inherently a vector-oriented program, because programming in Java is centered around


object creation, processing, and merging together to function as a single block

MAZEN OBAIDEEN Unit 17 Page 6 of 33


One of the best features provided by Java is to build programs running on the web under the
name JavaAplet , they are programs written in Java that work in web browsers and are usually
part of a website , it contains internal instructions that allow you to run a variety of software

- Of course, Applet programs are executed when a user opens a Web site in any browser that is
supported by Java and is done within the browser window , The Applet can also play multimedia in
formats not supported by the browser

An example of a web is applet :

Windows Media Player uses the Applet to display video files embedded in browsers

-3D modeling display Applet

reasons for choice :

A great reason to choose Java is the ecosystem, because Java provides a very rich API that is
characterized by the presence of layers

Because there is a Java VM for each Operating System

Also the most prominent reasons for choosing Java

The presence of support tools (IDE, CI)

A huge collection of third party libraries

There is a good number of Mutawites working to improve them, making them excel in a number of
languages

Works on multiple platforms everywhere

Easy to detect and correct errors

 Inheritance

Is the process by which one acquires characteristics (Methods& fiels) of another party through
inheritance, the information is made controllable in hierarchical order

The class that acquired the attributes is called a Sub class(Child class)

The class that inherits its properties is called a Super class (Parent class)

MAZEN OBAIDEEN Unit 17 Page 7 of 33


extends is the keyword used to inherit the properties of a class. Following is the syntax of extends
keyword.

According to the following syntax:

class Super {

.....

.....

class Sub extends Super {

.....

.....

The following example illustrates the Java inheritance process

you can observe two classes namely Calculation and My_Calculation.

Using extends keyword, the My_Calculation inherits the methods addition() and Subtraction() of
Calculation class.

Copy and paste the following program in a file with name My_Calculation.java

class Calculation {

int z;

public void addition(int x, int y) {

z = x + y;

System.out.println("The sum of the given numbers:"+z);

public void Subtraction(int x, int y) {

z = x - y;

System.out.println("The difference between the given numbers:"+z);

MAZEN OBAIDEEN Unit 17 Page 8 of 33


}

public class My_Calculation extends Calculation {

public void multiplication(int x, int y) {

z = x * y;

System.out.println("The product of the given numbers:"+z);

public static void main(String args[]) {

int a = 20, b = 10;

My_Calculation demo = new My_Calculation();

demo.addition(a, b);

demo.Subtraction(a, b);

demo.multiplication(a, b);

After executing the program, it will produce the following result

Output

The sum of the given numbers:30

The difference between the given numbers:10

The product of the given numbers:200

MAZEN OBAIDEEN Unit 17 Page 9 of 33


In the previous program

In the given program, when an object to My_Calculation class is created, a copy of the contents
of the superclass is made within it. That is why, using the object of the subclass you can access
the members of a superclass.

Encapsulation

is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism,
and abstraction.

Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the
data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden
from other classes, and can be accessed only through the methods of their current class.
Therefore, it is also known as data hiding.

To achieve encapsulation in Java :

Declare the variables of a class as private.

Provide public methods (set and get) to modify and display variable values

We have example :

/* File name : EncapTest.java */

public class EncapTest {

private String name;

private String idNum;

private int age;

public int getAge() {

return age;

public String getName() {

return name;

MAZEN OBAIDEEN Unit 17 Page 10 of 33


public String getIdNum() {

return idNum;

public void setAge( int newAge) {

age = newAge;

public void setName(String newName) {

name = newName;

public void setIdNum( String newId) {

idNum = newId;

public set () and get () methods are the access points of the instance variables of the EncapTest
class. Normally, these methods are referred as getters and setters. Therefore, any class that
wants to access the variables should access them through these getters and setters.

The variables of the EncapTest class can be accessed using the following program –

MAZEN OBAIDEEN Unit 17 Page 11 of 33


/* File name : RunEncap.java */

public class RunEncap {

public static void main(String args[]) {

EncapTest encap = new EncapTest();

encap.setName("James");

encap.setAge(20);

encap.setIdNum("12343ms");

System.out.print("Name : " + encap.getName() + " Age : " + encap.getAge());

Output

Name : James Age : 20

Benefits of Encapsulation

classes attributes can be made for read-only or write

The class can control what is stored in its attributes

data structure:

Data types: Specifies the values that the variable takes if the variable contains data of type int

This means that it can only take data from a valid type

Data types have two categories:

1. Types of primitive data: such as double, string, integer, bolean, float

2 - Types of non - primitive data: such as strings and matrices are all types of non - primitive data

First, we will talk about primitive data types: the data of the variable must be specified before it is
called (declarate the variables)

MAZEN OBAIDEEN Unit 17 Page 12 of 33


To use a num variable in our program, you must declare it first, as shown

Int num ;

It is the approach followed with all variables at the beginning of each program

- Knowing that the size of primitive data types does not change from one operating system to
another

One of the most important data types used in Java

Integer:

Used to store positive and negative integers without commas

We use int when the data type is "short" is insufficient to accommodate the number

And thus his domain is wider.

Defaul size : 4 byte

Default value : 0

Double: Contains negative and positive numbers in addition to decimal numbers

It is the default option for decimal values in general , size : 8 byte

For example :

Example:

class JavaExample {

public static void main (String [] args) {

double num = -42937737.9d;

System.out.println (num);

Output:

-4.29377379E7
MAZEN OBAIDEEN Unit 17 Page 13 of 33
Boolean

It expresses the logical amount with two values, either true or false

Boolean values are used in branch statements to verify the validity of the contained logical
expression .

Characters: It is used to store characters (letters) , such as A,B,C

Size: 16 bit

Represents an unicode value , each printable and nonprintable character has a Unicode value

because Java language works on storing characters as unicode, can be used with any language
written in the world

One dimensional array is a list of same typed variables. To create an array, first you must declare
an array variable of required type

Declaring an matrix is the same way of declaring a variable but with an extra square brackets. To
inform the compiler, that the variable represents an array, suffix or prefix (Java allows) the variable
name with a pair of square brackets. Array size should be given at the time of creation itself.
Depending upon the size, continuous memory locations are allocated to the elements. Array
identifier follows the same rules of Java identifiers.

Instantiation of an Array in java

arrayRefVar=new datatype[size];

Example of single dimensional java array

class Testarray{

public static void main(String args[]){

int a[]=new int[5];//declaration and instantiation

a[0]=10;//initialization

a[1]=20;

a[2]=70;

a[3]=40;

a[4]=50;

MAZEN OBAIDEEN Unit 17 Page 14 of 33


//printing array

for(int i=0;i<a.length;i++)//length is the property of array

System.out.println(a[i]);

Output:

10

20

70

40

50

Two-dimensional arrays are defined as "an array of arrays". Since an array type is a first-class
Java type, we can have an array of ints, an array of Strings, or an array of Objects , we can index
Two-dimensional (2D) arrays by two subscripts, one for the row and one for the column.

class MultidimensionalArray {

public static void main(String[] args) {

int[][] a = {

{1, 2, 3},

{4, 5, 6, 9},

{7},

};

System.out.println("Length of row 1: " + a[0].length);

System.out.println("Length of row 2: " + a[1].length);

System.out.println("Length of row 3: " + a[2].length);

MAZEN OBAIDEEN Unit 17 Page 15 of 33


}

When you run the program, the output will be:

Length of row 1: 3

Length of row 2: 4

Length of row 3: 1

1.2
Java is a flexible language for several reasons

Portable: You can transfer the code written in Java from one computer to another without fear of
system configuration details

Security: When compiled, the source language written in Java is compiled into (bytecode)

Which is later interpreted by the Java virtual machine , in addition Java security technology
includes a large set of APIs, tools, and implementations of commonly used security algorithms,
mechanisms, and protocols.The Java security APIs span a wide range of areas, including
cryptography, public key infrastructure, secure communication, authentication, and access control.
Safety technology for the developer provides a comprehensive security framework for writing
applications.

Multiple Platforms: The most flexible stuff in Java is (cross platform)

It works on all common systems where JVM is present , this applies to Mac OS, Linux, Windows

Self-Memory Managed:In terms of memory, customization and de-allocation of objects

Do not worry because JVM takes care of them

High performance: Java has proven to be powerful in terms of efficiency and memory

MAZEN OBAIDEEN Unit 17 Page 16 of 33


Network support: with each version, a community of developers who

Contribute to the development of Java with advanced and advanced APIs and libraries, available
as ready-to-use packages for the creation of reliable and robust network systems

JVM

Java Virtual Machine: the default Java language,feature built in Java language

Function: Enable various computers to run programs written in Java and can be said that JVM is a
default processor

JVM is divided into 3 sections:

1. Class Loader Subsystem

2. Runtime Data Area

3. Execution Engine

Byte code

Is an intermediate language that interprets source codes from a high-level language into a low-
level language (machine language)

But if we move this code to another operating system, the machine language will be different

Instead of editing the machine code directly

We convert the code to the bytecode and then from the bytecode to the machine we will work on

MAZEN OBAIDEEN Unit 17 Page 17 of 33


TASK 2

2.1
A.

Inputs (commercial) Inputs (residential)


C= consumption CP1= consumption Period 1
Outputs CP2= consumption Period 2
M=money CP3= consumption Period 3
Outputs
M=money

B.

There are different class names

First :

Customer class:it's Superclass(main) contains customer specific features

Second

Commercial Customer:

A subclass is called , it has own attributes and such as the consumption the parent class can not
access , The same thing for methods

Residential Customer:

Also called subclass and have their own attributes

Such as consumption according to the time period and Superclass (client) can not access to it

The idea is that the features of the customer are automatically generated at (commercial and
domestic) any subscriber

Hence any method found at the Superclass can subclass , To reach her but the reverse is
incorrect

C.

Class name Attribute with data type Class name


MAZEN OBAIDEEN Unit 17 Page 18 of 33
Int no , String name
Void display ( ) Int counter_id Customer
Int year , int month
Double view ( ) Double consumption Commercial
Double consumption 10→6
Double view ( ) Double consumption 6→5 Residential
Double consumption 6→10

D.

Flow chart :

MAZEN OBAIDEEN Unit 17 Page 19 of 33


MAZEN OBAIDEEN Unit 17 Page 20 of 33
Class diagram :

Δ : Is an command mean extends(Express the inheritance)

 I have two types of commercial invoice and home so I resorted to inheritance and designed
Superclass and subclass

MAZEN OBAIDEEN Unit 17 Page 21 of 33


2.2
File strcture

We have 4 Classes:

They :

1-main class

2- commercial class

3- residential class

4- client class

All of which have a (.java) extension

It will be in a main package and each class will have components

1-class client

-Attribute:

Int no : It means that I have declared a variable of type (integer) for one of the customer
registration information , which is (customer number)

String name :

String name :It means defining or declaring a string variable for a registration information

It is a (name)

Int counter id :The declaration of an int variable for one of the customer registration data (counter
number)

Int year : The declaration means a variable of type (int), which expresses the year of issuing the
invoice (year number id)

Int month : The declaration of a variable of type (int), which expresses the number of the month in
which the invoice (month number)

MAZEN OBAIDEEN Unit 17 Page 22 of 33


-Methods :

Void view ( )

It prints the customer registration information in the company according to Inputs

2-Class commercial client

Attributes :

Int consumption: declare a variable of type (Double) for the amount of consumption according to
the commercial invoice

Methods:

Double solve () : Is a method that calculates the cost or value of the exchange of electricity based

on the monthly consumption ratios (Sliding system)

3-Class residential client

Attributes :

Consumption 10 → 6 : We declare an variable of type (Double) under the name of consumption,


which defines the first consumption period from 10 am to 6 pm

Consumption 6 → 5: It is a variable of type (Double) that defines the second consumption period
from 6 pm to 5 am

Consumption 5 → 10: It is a variable of type (Double) to define the period of the third consumption

she is from 5 am to 10 pm

Methods:

Double solve ( ) : It is a double type that calculates the value or cost of the exchange of electricity
based on the specific consumption periods.

MAZEN OBAIDEEN Unit 17 Page 23 of 33


Task 3

3.1
Main Class :

MAZEN OBAIDEEN Unit 17 Page 24 of 33


Client class:

MAZEN OBAIDEEN Unit 17 Page 25 of 33


MAZEN OBAIDEEN Unit 17 Page 26 of 33
Commercial class

MAZEN OBAIDEEN Unit 17 Page 27 of 33


class Residential

MAZEN OBAIDEEN Unit 17 Page 28 of 33


3.2
Symbol (Δ) which refers to inheritance by the class Diagram

We have interpreted this symbol programmatically with the following statement:

Public : Indicates the type of the variable, private or public


Residential : Class name
Extends : The word that expresses Δ in inheritance (ie, a commercial class is an extension of a
customer main class)
Client : It is the class of the father who inherited the attributes to the residential class , Thus the
residential class takes the attributes of the father with its own attributes.

Classlibraries: I called a library called: [ import javax.swing.JOptionPane; ]


Used to show the Options window (OptionPane) in front of the user for:
1- Warn him or inform him of anything
2 - Ask him if he agrees to something or not
3 - Request the introduction of a value

- And with this beautiful library it offers many functions that can be used to get
Confirm dialogs – input dialogs– message dialogs

3.4

MAZEN OBAIDEEN Unit 17 Page 29 of 33


3.5
Netbeans: Is one of the most famous programs used to print a statement and a Java expression

The general concept is Java-oriented IDE , It needs to work as a Java virtual machine

Netbeans is an open source program that is used by a large number of programmers and
developers and I am also used to it as the main editor of Java code

Netbeans IDE : Also known as the software developer with a graphical interface and is an
integrated software environment that supports a variety of programming languages, including
PHP, java

Developed in Java and provides great features such as: Monitoring of grammatical errors - alerting
the programmer in case of writing a wrong expression or forgetting an arc or semicolon, for
example in one of the lines of code

restructuring the code in an organized and consistent manner

It is worth mentioning that the program is completely free and without any restrictions on its use
and works on all known systems without problems

3.6
General framework of the program is design and development of Java application for Electra

Includes specific inputs and outputs (results)

It works at the expense of the bill of electricity for customers, and are two types according to the
following scenario:

First: Customer information and data must be recorded in the company as:

Customer serial number, name, counter number

The invoice must contain the number of the month in which the invoice was issued and the year

First type of customers:

MAZEN OBAIDEEN Unit 17 Page 30 of 33


Commercial: The invoice is calculated with the commercial customer based on monthly
consumption

According to a schedule that determines the amount of consumption in kilowatts (from ... to) in
exchange for an amount imposed for each kilowatt estimated in (TL)

This pattern is known as the slide system

The other type of customer is residential

Depending on the consumption period 3 periods (morning - afternoon - evening) are arranged
according to the schedule in consecutive hours

Each period of electricity use is from 10 am to 6 pm for example

It has a specific cost per kilowatt-consumer estimated in (TL)

An ordinary user can work on the program using the graphical user interface (GUI), making the
application more user friendly and flexible

Or you can add a simple control module in the form of a dialog box containing all entries
necessary for all functions (console)

When a simple user interface works by JoptionPane , 3 options show to customer

1- Entering a commercial invoice

2- Insert a home tab

3- Help

4- Exit

MAZEN OBAIDEEN Unit 17 Page 31 of 33


Task 4

4.1
After checking and testing the code, you have corrected some simple spelling mistakes

but I did not notice any errors in the code in the code call to reduce or disrupt the work of the
program

The definition of variables (declaration) and their attribution of values is true so that I did not begin
to declare the variables using numbers

also, make sure not to leave blank spaces in the name of the variable (if it is more than one word).
to avoid this error, add an underscore (_)symbol or the words can be connected immediately

because of the conditions of the variables start with a letter or underscore or $ and do not initiate a
number

commands and statement are all correct

Include a document or text file to help the user learn and understand the program easily

In reviewing the program, it was confirmed that the variable names were identical in the different
classes

Also, methods and classes were arranged and organized and therefore subject to the correct rules
and conditions

Append annotations Adding a task at the programmer level and arranging the lines under each
one increases the visibility and aesthetics of the code

I've included a text document or report to help the user use the program easily and understand
how it works

4.2

MAZEN OBAIDEEN Unit 17 Page 32 of 33


4.3
After reviewing, checking and looking from a software developer's perspective, there are
suggestions for developing or improving the work

I can add other classes to the program to calculate the value or amount of customer consumption
per month and another class calculated the total annual consumption plus the value of the invoice
by 12 months for the residential customer

- The last date for the payment of the invoice may be placed with the client's notice of the
existence of fines in the event of a delay of one week from the payment

As well as the attributes of the client can add a phone number + place of residence

4.4

MAZEN OBAIDEEN Unit 17 Page 33 of 33

You might also like