0% found this document useful (0 votes)
23 views

ARRAY ASSIGNMENT

array
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

ARRAY ASSIGNMENT

array
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

KOLEJ MATRIKULASI KEDAH

SC025 COMPUTER SCIENCE 2

TITLE : ARRAY

NAME : ALHANI MAWADDAH BALQIS BINTI MAJDI

MATRIC NO : MS2118122500

PRACTICUM : DFT39

LECTURER : MADAM NORLISAH BINTI SAMSURI

SUBMITTED ON : 10th APRIL 2022

1
Table of Content

2
s
1.0 Problem Statement........................................................................................................................3
2.0 Problem Analysis (IPO)...................................................................................................................4
3.0 Design A Solution............................................................................................................................5
3.1 Pseudocode.................................................................................................................................5
3.2 Flowchart.....................................................................................................................................6
4.0 Implementation & Documentation................................................................................................7
5.0 Testing............................................................................................................................................8
REFERENCES........................................................................................................................................12

3
1.0 Problem Statement
A program will receive inputs from the user and save them in a String type array;
bookID[]. The minimum data to be saved is ten (10).
This program also allows user to retrieve the saved data. User will enter the keyword
(bookID) to be searched in the array.
The program then will display the following information:
- an appropriate message if the element is found
- the index of found element
- an appropriate message if the element is not found.

4
2.0 Problem Analysis (IPO)

Input : bookID,keyword
Process : -Create and declare an array for bookID.
-Repeat input bookID into the array for 10 times.
-Input keyword and repeat compare element 10 times.
-Display message ”The book is FOUND!”and ” is present at index ”
or “The book is NOT FOUND!” based on keyword.

Output : bookID,index,message”The book is FOUND!” and ” is present at


index ” or “The book is NOT FOUND!”.

5
3.0 Design A Solution
3.1 Pseudocode
Start

Create array bookID[10]

int i=0

for each bookID in the array

read bookID[]

i++

endfor

Read keyword

initialize found=false

int i=0

for each bookID in the array

if(keyword.equals(bookID[]))

found=true

Print message “The book is FOUND!”,”is present at index”

Print bookID[],index

endif

i++

endfor

if(found==false)

Print message “The book is NOT FOUND! “

endif

End

6
3.2 Flowchart

Start

Create array bookID[10]

int i=0

False

i<bookID.length Read keyword initialize found=false

int i=0
True

i<bookID.length

Read bookID[] False

True

i++ i++

False
found==false search.equals(bookID[i])

False
True True

Print message “The book is NOT FOUND! “ found=true

Print message”The book is


FOUND!”,”is present at index”

End Print bookID,index

7
4.0 Implementation & Documentation

8
5.0 Testing
First Output
 ----jGRASP exec: java ArrayBookID
Enter the BookID 1:A1
Enter the BookID 2:A2
Enter the BookID 3:A3
Enter the BookID 4:A4
Enter the BookID 5:A5
Enter the BookID 6:A6
Enter the BookID 7:A7
Enter the BookID 8:A8
Enter the BookID 9:A9 Enter
the BookID 10:A10
Enter BookID to search :
A5
The book is FOUND!
A5 is present at index 4
 ----jGRASP: operation complete.

Figure 1.Output1

 ----jGRASP exec: java ArrayBookID


Enter the BookID 1:A1
Enter the BookID 2:A2
Enter the BookID 3:A3
Enter the BookID 4:A4
Enter the BookID 5:A5
Enter the BookID 6:A6
Enter the BookID 7:A7
Enter the BookID 8:A8
Enter the BookID 9:A9 Enter
the BookID 10:A10
Enter BookID to search :
A10
The book is FOUND!
A10 is present at index 9

9
 ----jGRASP: operation complete.
Second Output

Figure 2.Output2

10
Third Output
 ----jGRASP exec: java ArrayBookID
Enter the BookID 1:A1
Enter the BookID 2:A2
Enter the BookID 3:A3
Enter the BookID 4:A4
Enter the BookID 5:A5
Enter the BookID 6:A6
Enter the BookID 7:A7
Enter the BookID 8:A8
Enter the BookID 9:A9 Enter
the BookID 10:A10
Enter BookID to search :
A15
The book is NOT FOUND!
 ----jGRASP: operation complete.

Figure 3.Output3

11
Fourth Output
 ----jGRASP exec: java ArrayBookID
Enter the BookID 1:A1
Enter the BookID 2:A2
Enter the BookID 3:A3
Enter the BookID 4:A4
Enter the BookID 5:A5
Enter the BookID 6:A6
Enter the BookID 7:A7
Enter the BookID 8:A8
Enter the BookID 9:A9 Enter
the BookID 10:A10
Enter BookID to search :
A20
The book is NOT FOUND!
 ----jGRASP: operation complete.

Figure 4.Output4

12
REFERENCES
Hermansen , C. (2019, October 22). Initializing arrays in Java. Opensource.com. Retrieved
April 6, 2022, from https://opensource.com/article/19/10/initializing-arrays-java

Iyer, A. (2019, May 22). Java array tutorial: Single & Multi Dimensional Arrays in Java.
Edureka. Retrieved April 6, 2022, from https://www.edureka.co/blog/java-array/

Md Ali, M. A., & Mohd Zain, M. (2022). Problem Solving Using Java. Fourth published.

Nam, H. M. (2019, August 21). Array Java Programming. Notes about arrays in Java.
Retrieved April 6, 2022, from https://www.codejava.net/java-core/the-java-++++

Vincent Abba, I. (2022, February 4). Java array – how to declare and initialize an array in
Java example. freeCodeCamp.org. Retrieved April 6, 2022, from
https://www.freecodecamp.org/news/java-array-how-to-declare-and-initialize-an-
arrayin-java-example/

13

You might also like