Kolej Matrikulasi Kedah
Kolej Matrikulasi Kedah
TITLE : ARRAY
MATRIC NO : MS2018175630
PRACTICUM : DFT34
TABLE OF CONTENT
INTRODUCTION………………………..……………………………………………3
PROBLEM STATEMENT……………………………………………………………4
PROBLEM ANALYSIS……………………………………………………………….5
DESIGN A SOLUTION……………………………………………………………..6-7
Pseudocode……………………………………………………………………………6
Flowchart………………………………………………………………………………7
IMPLEMENTATION………………………………………………………………8-9
TESTING………………………………………………………………………….10-12
DOCUMENTATION…………………………………………………………………13
REFERENCES………………………………………………………………………..14
3|Page
1.0 Introduction
An Array is an ordered indexed collection of data values of the same type. An array consists
of five (5) components which is data type, name, size, index and element. Additionally, the
elements of an array are stored in a contiguous memory location. It is a data structure where
we store similar elements. We can store only a fixed set of elements in a Java array. Array in
Java is index-based, the first element of the array is stored at the 0th index, 2nd element is
stored on 1st index and so on. To use an array, it must first be declared and created. Then
operations on an array can access elements in the array to do some operations on the array
such as entering data into array, displaying elements in array, find the sum of all elements,
find the average of elements, find the largest or smallest element, find the frequency of
elements in an array and searching for specific value in an array.
4|Page
A program will receive inputs from the user and save them in a double type array name
price[]. The minimum data to be saved is ten (10).
This program also allows user to retrieve the saved data. User will enter the keyword (price)
to be searched in the array.
Process Declaring and create array price to enter the 10 prices entered by
the user . Repeating read the prices for 10 prices and stored the
prices at the index. The user will enter the search price that he/she
want to find at the index and the message will display if the search
price was found at the index and calculate the total of search price
was found at the index. If the search was not found at the index the
message will display .
Output The message “ The price is found at the index” + i and The Total of
the price found at the index or the message “ The price is not
found”.
6|Page
4.1 Pseudocode
Start
Declare and create array price
i=0
for ( i < 10 )
Read price[i]
i=i+1
endfor
for ( i < 10 )
if ( searchprice == price [i])
user = true
print message “ Price is found at index” ,i
Foundprice = Foundprice + 1
endif
i=i+1
endfor
if ( user == false )
print message “Price is not found”
else
print Foundprice
Stop
7|Page
4.2 Flowchart
Start
i =0
False
Initialize user = false
i < 10
Foundprice=0
True
i=i+1
User ==
i < 10
false
True False
True
True
Searchprice=
= price [i]
True
Print message “ The
price is not found” False
user = true
Foundprice = Foundprice + 1
Stop
i=i+1
8|Page
5.0 Implementation
//declaring variables
//size of array is 10
double[]price=new double[10];
//Input statements
System.out.print ("Please enter the price : RM ");
price[i] = sc.nextDouble();
}
if ( searchprice == price[i]){
user = true;
//processing statement that will calculate the
total of search price
Foundprice = Foundprice + 1;
}
}
if (user == false )
//display the message that the price was not find the
index
System.out.println ( " \nThe price is not found at
the index");
else
//display message for total of price found
System.out.print ( " \nTotal of the price found is "
+ Foundprice);
}
}
10 | P a g e
6.0 Testing
A program will receive 10 input from the user and the user will enter the search price that to
be searched at the index. It will display message "The price is found at the index" or the
message "The Price is not found ". The program also display the frequency of the price found
based on the search price. The class name is ArrayPrice. The method main in a Java Program
marks entry point of the program. The program execution begins with the first statement in
the method main, and ends with the last statement in it. Creating objects for user entered the
input (sc as object). Declaring variables because it can be used to store the prices that entered
by the user. The size of array is 10 because to allocate 10 consecutive memory location to
store 10 prices that entered by the user. Input statements price[i] used to accept the 10 prices.
The input statement which will display the message to read the search price the user want to
search at the index. The program will display the message the price was found and index
price if the price was found at the index. Processing statement that will calculate the total of
search price in the index number of prices. It will display message for total of price found
from the loop. If the search prices was not found in the index prices it will display the
message that the price was not find the index.
14 | P a g e
8.0 References