0% found this document useful (0 votes)
2 views48 pages

Individual Assignment

This document outlines an individual assignment for a course on Advanced Programming Language Concepts at Technology Park Malaysia, focusing on developing a computer application to visualize vaccination data in Malaysia. The assignment includes tasks such as creating data parser packages, displaying vaccination records, and computing statistics related to vaccination data using various programming paradigms, particularly functional and declarative programming. The document details the implementation of these tasks, including code snippets and functional programming concepts used throughout the development process.

Uploaded by

TEE HUI CHIEN
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)
2 views48 pages

Individual Assignment

This document outlines an individual assignment for a course on Advanced Programming Language Concepts at Technology Park Malaysia, focusing on developing a computer application to visualize vaccination data in Malaysia. The assignment includes tasks such as creating data parser packages, displaying vaccination records, and computing statistics related to vaccination data using various programming paradigms, particularly functional and declarative programming. The document details the implementation of these tasks, including code snippets and functional programming concepts used throughout the development process.

Uploaded by

TEE HUI CHIEN
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

Individual Assignment

TECHNOLOGY PARK MALAYSIA

CT006-3-3-APLC

ADVANCED PROGRAMMING LANGUAGE CONCEPTS

HAND OUT DATE: 19th January 2022

HAND IN DATE: 28th March 2022

WEIGHTAGE: 50%

NAME: TEE HUI CHIEN

TP NUMBER: TP051538

INTAKE: UC3F2111SE

NAME OF LECTURER: MR. Lee Kim Keong


Table of Contents
Introduction......................................................................................................................................3

Solution Code..................................................................................................................................5

Task 1...............................................................................................................................................5

1.0 Appropriate Data Parser Package..........................................................................................5

2.0 Display all vaccination and registration records in Malaysia..............................................14

2.1 Vaccination Records.........................................................................................................14

2.2 Registration Records........................................................................................................15

3.0 Compute the Sum of Fully Vaccinated People By state and/or by Month..........................16

3.1 Compute the Sum of Fully Vaccinated People by State......................................................16

3.2 Compute the Sum of Fully Vaccinated People by State and Month................................18

4.0 Find the highest/lowest the vaccination taken weekly for adult and child..........................21

4.1 Find the highest and lowest the vaccination taken weekly for adult and child from whole
list...........................................................................................................................................21

4.2 Find the highest and lowest the vaccination taken weekly for adult and child By Year..24

5.0 Display the weekly total number of vaccinations by vaccine type......................................28

Task 2.............................................................................................................................................31

2.1 Create Prolog Knowledgebase File......................................................................................31

2.2 Appropriateness of data structure used................................................................................35

2.3 Appropriateness of Prolog programming for the requirement.............................................35

Conclusion.....................................................................................................................................44

References......................................................................................................................................45

Page | 2
Introduction

There is always a lot of simple or complexity programming problems require to be solved by


programmers during developing their application. The programming paradigms is a method
available for programmers to use to solve their programming problems (Thanoshan, 2019). Since
the term of paradigms in programming paradigm refer to the approaches that can use to solve
some problems or complete some tasks (Bhumika, 2022). The programming paradigms also can
be defined as the tools or techniques able to be implemented by programmer using any
programming languages through following the methodology of that techniques (Bhumika, 2022).

There are mainly two type of programming paradigms which are imperative programming
paradigm and declarative programming paradigm (Thanoshan, 2019). The imperative
programming paradigm which based on Von Neumann architecture is considered as one of the
oldest programming paradigms (Bhumika, 2022). It is easier to implement compared to
declarative programming paradigm, because it works step by step by following the instructions
statements assigned (Bhumika, 2022). It concentrates on how to solve the problem instead of the
efficiency and productivity (Bhumika, 2022). Hence, there is always several programming
statements and result stored at the end when developing solution using imperative programming
paradigm. Besides that, it is difficult to use to solve complex programming problems. The
example of imperative programming paradigm are procedural programming, object-oriented
programming, and parallel processing approach (Thanoshan, 2019).

In contrast, declarative programming paradigm considered as more modern programming


languages (Bhumika, 2022). It emphasizes on what to do for solving the problem with the
simplest actions rather than how to solve (Thanoshan, 2019). It helps programmers to express
computation logic that require to solve the problem without talking about the solution’s step by
step (Bhumika, 2022). As a result, programmers can develop their applications more efficiency
and productivity since the parallel programming are allowed. Logic programing, functional
programming, and database processing approach are categorized under the declarative
programming paradigm (Thanoshan, 2019).

This assignment aims to develop a computer application that can used to visualize statistic data
related to daily vaccination records and vaccine program registration records in Malaysia by

Page | 3
using the MYCovid datasets API provided by Danial Sim in GitHub. Multi-programming
paradigms will be applied when developing this computer application, however the declarative
programming paradigms such as functional programming and logic programming will be
primarily implemented to solve specific problems in task 1 and task 2 respectively. Some of the
necessary imperative programming languages such as object-oriented programming and
procedural programming are used.

Page | 4
Solution Code

Task 1

There are lot of functional programming concepts have been implemented in developing the
functions of task 1. For example, purity, high order function, lambda expression, functional
interface, currying, partial application, recursion, recursive lambda, function composition,
parametric polymorphism, and generic (Inouye, 2022). The purpose of using functional
programing is because it can avoid the system from side effect, provide code reusability,
comprehensibility, testability, and parallel programming (concurrency), as well as make system
development process become more efficiency and productivity (Inouye, 2022).

1.0 Appropriate Data Parser Package

First and foremost, appropriate data parser package chosen for computer application reading the
MYCovid datasets provided by Danial Sim in csv documents will be discussed. It is in the
criteria 5 from task 1. Two approaches provided by programmer to read the csv MYCovid
datasets which one is from csv files downloaded from APIs URL given and stored in program
folder, thus another one is from directly retrieved from datasets APIs URL given.

1. Read datasets from Downloaded Local CSV file in program folder.

Figure 1: Path for downloaded csv file in program folder

Page | 5
Figure 2: Open CSV and other necessary jar file

OpenCSV is data parser package chosen for computer application reading the MYCovid datasets
through the csv file downloaded in program folder. This is because OpenCSV is a CSV parser
library for Java (Singh, 2021). Those highlighted jar files are required to be downloaded and
added into the program libraries before running the project.

Figure 3: Dependencies need to import to read the csv file

The OpenCSV related dependencies needs to be imported at the class that responsible to read file
first, in this case is LocalCSVFileReader class.

Page | 6
Figure 4: LoadCsvFileReader class

Then the path of csv files in program folder be defined as public static final variables as it should
not be able to modify and require to be called by GUI class. Besides that, the readCSVFile()
public static method define to read the csv file and convert it into the string array by line through

Page | 7
the passed in arguments which is file path (fileName) by using CSVFileReader() and
FileReader() functions provided by OpenCSV library. The withSkipLines(1) function used to
skip the first line of CSV because it is the title but not data. The getVaxRecordList() method is
used to convert the line data returned from readCSVFile into the appropriate object List with
appropriate constructor. Inside the getVaxRecordList() the method use for creating the certain
type of objects using different constructors will be invoked. For example, there are
createVaxRecord (), createVaxStateRecord (), createVaxAdultChildRecord (),
createVaxTypeRecord (), and createVaxRegMYRecord () methods used to create object when
iterate every line of csv line data obtained using map () higher order function.

Functional Concepts:

The first functional concept used in this method is generic as known as parametric
polymorphism. In this case, the generics with upper bounded wildcard used in the return type
of getVaxRecordList(). For example, List<? extends Record>. The meaning of “?” represent as
unknown, while the meaning of “extends” represent as the unknown type must be sub-class of
Record class (baeldung, 2021; Oracle, 2022).

Figure 5: Record Interface

Figure 6: RegistrationRecord class

Figure 7: VaccinationRecord Class

Page | 8
RegistrationRecord class and VaccinationRecord class are the sub-class of Record class since
they are implements from the Record interface. Therefore, only the object list in List<
RegistrationRecord> and List<VaccinationRecord> can be return in the return type of
getVaxRecordList(). The use of generic upper bounded wildcard ensures the type safety and
avoids redundant of similar methods due to provide relax restriction on the method return types
(Oracle, 2022).

Besides that, side effect and purity also applied in this method. This is because the
getVaxRecordList() method is not affected by any state variables values outside its local
environment, but always return the same output with the same input (YLD, 2021).

Moreover, high order function such as stream (), map (), and collect () are used (KnoldusInc,
2019). The high order functions allow return function as a result or take the function as an
argument (KnoldusInc, 2019). The used of those high order functions together also make the
pipelining functional concept indirectly be implemented. In this case stream pipelining with the
concept of chaining operations together used, which the stream () and map () act as intermediate
operation while the collect () act as terminal operation (Gootooru, 2022).

Furthermore, the lambda expression used by assigned it as variable in this case. This is because
the variable’s type is the Function<T,R> functional interface which has only one method that
provided by [Link] in Java 8. The lambda expression declared have the same number
of parameters and same return type as the variable type of that variable. Those lambda
expressions declared in variables used for creating VaccinationRecord or RegistrationRecord
objects with different classes constructors (w3schools, 2022). For example, there are
createVaxRecord, createVaxStateRecord, createVaxAdultChildRecord, createVaxTypeRecord,
and createVaxRegMYRecord variables. To involve the function of lambda expression .apply()
must use. The lambda expression returns a value through execute a short block of code which
takes in parameters (w3schools, 2022).

Page | 9
Figure 8: Dashboard GUI Class

Figure 9: Method inside Dashboard GUI class

The code snippet above shown how the vaccination record lists or vaccine program registration
record list required to be further used later be created and obtained through read from local
downloaded csv file at the first when project start running.

Page | 10
2. Read datasets from APIs URL csv file.

Figure 10: OnlienCSVFileReader class

There is not any outsource data parser package needed to be downloaded and added into the
project libraries when read online csv file from APIs URL. The read file functions through URL
needed are all available in java program such as BufferedReader(), InputStreamReader(), and,
URL(). The URL path of csv files will be defined as public static final variables as it should not
be able to modify (avoid side effect) and require to be called by GUI class later. Besides that, the
readCSV() public static method define to read the csv file through the passed in file ULR (url).
Then it combines with the readOnlineCSVFile() function in order to collect all lines in csv
dataset into string array except the first which is the title but not data. The
getOnlineVaxRecordList() method is used to convert the line data returned from
readOnlineCSVFile() function into the appropriate object list with appropriate constructor. Inside
the getOnlineVaxRecordList(), the methods used for creating the certain type of objects using
different constructors will be invoked when iterating every line of csv data obtained using map ()
higher order function.

Page | 11
Functional Concept

Similar with the read datasets from downloaded local CSV file in program folder. It used of
generic with upper bounded wildcard, side effect, purity, higher order function (map,
stream, and collect), pipelining, lambda expression in Function<T,R> functional type
functional concepts.

Figure 11: Method in Dashboard GUI class

Not only that, but the functional composition functional concept can be observed. For example,
the readOnlineCSVFile() function operate as the parameter of getOnlineVaxRecordList()
function, then the readCSV() function operate inside the readOnlineCSVFile() function. The
create object function such as [Link](), [Link](),
[Link](), [Link] (), or
[Link] () functions are also operate inside the
getOnlineVaxRecordList() function. As a result, there are combination of at least four functions
into a new complicated function in order to get the necessary lists. The functional composition is
a technique that use to combine two or more functions into a single function (Java Functional
Composition, 2018). The combination of functions usually happens in a new single function.

Page | 12
3. Output

The dataset sources can be changed at the welcome page. The user needs to click to load data
button after choosing the drop-down list. The line below the click to load data button can help
users to identify which sources their dataset used to view data.

Figure 12: Welcome Page (Load from local csv file)

Figure 13Welcome Page (Load from online csv file)

Page | 13
2.0 Display all vaccination and registration records in Malaysia

The first criteria of Task 1 are to display all vaccination and vaccine program registration records
in Malaysia.

2.1 Vaccination Records

Figure 14: Button Event in Dashboard GUI class to show Vaccination Record

Since all the necessary vaccination lists and vaccine program registration records have been
created and inserted data when read the csv file even from local downloaded csv file or online
APIs URL csv file. So, the obtained and assigned vaccination record list called
VaxMYRecordList variable can be directly used to display all record. The VaxMYRecordList
variable will be iterated in order to add the attributes’ values of all VaccinationRecord Object
into the row of the of JTable.

Figure 15: Vaccination Record Page

Page | 14
2.2 Registration Records

Figure 16: Button Event in Dashboard GUI class to show Registration Record

The obtained and assigned vaccination record list called VaxRegMYRecordList variable can be
directly used as the requirement is to display all record. The VaxRegMYRecordList variable will
be iterated in order to add the attributes’ values of all RegistrationRecord Object into the row of
the of JTable.

Figure 17: Registration Record Page

Page | 15
3.0 Compute the Sum of Fully Vaccinated People By state and/or by
Month

3.1 Compute the Sum of Fully Vaccinated People by State

Figure 18: getVaxStateRecordByStateTotal() Method in [Link]

The code snippet above shown how the getVaxStateRecordByStateTotal variable with
Function<T,R> type can compute the obtained all vaccination record in list<VaccinationRecord>
into Map collection that store the state with its sum of fully vaccinated people in lambda
expression.

Functional Concepts:

In this function, the purity, high order function, lambda expression, functional interface,
and method references used. The purity concept applied when there is not side effect, and the
return output is based on the input only. The higher order function like stream() and collect()
used in this function. The lambda expression used is Function<T,R> functional interface. Two
reference methods use when collection groupingBy() and summingInt() for returning Map data
structures such as VaccinationRecord::getState and VaccinationRecord::getDailyFull.

Figure 19: Button Event in Dashboard GUI class to show Total Fully Vaccinated People by State

The code snippet above shown how the [Link]() function be


invoked in GUI class in order to compute the obtained dataset list into sum of fully vaccinated
people by state in map data structure. Then the map sets in computed map will be iterated and
added into specific JTabel.

Page | 16
Figure 20: Fully Vaccinated People by State Page

Page | 17
3.2 Compute the Sum of Fully Vaccinated People by State and Month

Figure 21: getVaxStateRecordByStateYearMonthTotal() Method in Controller Class

Figure 22: getStateYearMonth() method in VaccinationRecord Class

The code snippet above shown how the function in getVaxStateRecordByStateYearMonthTotal


functional interface compute the obtained all vaccination record in list<VaccinationRecord> into
Map collection that store the state:year-month with its sum of fully vaccinated people by
grouping the collections using the getStateYearMonth() method in VaccinationRecord class then
summarizing by dailyFull attribute value of object using lambda expression (short block of
code).

Figure 23: Methods in Controller Class

Besides that, getVaxStateRecordByState, getVaxStateRecordByMonth, and


getVaxStateRecordByYear lambda expressions in Function<T,R> functional interface type used
to get the combo box items needed for searching the total fully vaccinated by state, year, and
month.

Page | 18
Figure 24: Method in Controller Class

The getVaxStateRecordByStateNMonthTotal () currying lambda expression used for searching


the total fully vaccinated by state, year, and month.

Functional Concepts

The currying lambda expression concept applied in the


getVaxStateRecordByStateNMonthTotal (). This is because total 4 arguments accepted in that
function will be turned into 4 functions that each accepts a single argument. The currying
techniques applied when n arguments accepted by the function can be break into n functions
which each receive one argument only (psil123, 2018).

Figure 25: Button Event in Dashboard GUI class to show Total Fully Vaccinated People by State and Year and Month

There is total 4 apply functions will called when invoked


getVaxStateRecordByStateNMonthTotal () and each of the function will accepts only one single
argument.

Not only that, the purity, high order function, pipelining, and functional interface used. The
purity concept applied when there is not side effect, and the return output is based on the input
only. The higher order function like map(), distinct(), filter(), mapToint(), collect (), and sum()
used in the above functions. The pipelining indirectly implemented when those high order
functions combine to use. In pipelining, the map(), filter() and mapToInt() are stateless
intermediate operation, while distinct() is stateful intermediate operation. The collect() and sum()
are terminal operation. The functional interface used is Function<T,R>.

Page | 19
Output:

Figure 26: Total Fully Vaccinated People by State Year Month Page

Page | 20
4.0 Find the highest/lowest the vaccination taken weekly for adult and
child

4.1 Find the highest and lowest the vaccination taken weekly for adult and
child from whole list

Figure 27: Methods in Controller Class

The [Link]() and


[Link] () functions respectively used to compute the
obtained all vaccination record in list<VaccinationRecord> into Map collection that store the
year-week with its total vaccination of Children or Adult by grouping the collections using the
getYearWeek() function in VaccinationRecord class then summarizing by the total of
getChildFull/getAdultFull and getChildPartial/getAdultPartial attribute value of object.

Figure 28: Methods in Controller Class

The [Link] () function is used to find out and return the set that have the highest value
number from the obtained map collection. While the
[Link]() and
[Link] () respectively used to find out and return
the maximum year-week set that have the highest total vaccination from the obtained map
collection that store the year-week with its total vaccination of Children or Adult.

Page | 21
Figure 29: Methods in Controller Class

The [Link]() function is used to find out and return the set that have the lowest value
number from the obtained map collection. While the
[Link]() and
[Link]() respectively used to find out and return
the minimum year-week set that have the lowest total vaccination from the obtained map
collection that store the year-week with its total vaccination of Children or Adult.

Functional Concept:

The Functional composition that is kind of the functional composition concept used in
[Link]() and
[Link]()
[Link]() and
[Link](). This is because the [Link](),
[Link](), [Link]() and
[Link]() functions are all applied using lambda
expression in Function <T,R> functional type. So, they can be compose into new function by
using the compose() and andThen(). The compose() methods first call the function inside
parameter then only call the function outside. While andThen() opposite with compose() because
it first call the outside function then only call the function inside parameter. Not only that, the
purity, high order function, pipelining, and lambda expression functional used.

Page | 22
Output:

Figure 30: Adult & Child Weekly Vaccination Taken Page

Page | 23
4.2 Find the highest and lowest the vaccination taken weekly for adult and
child By Year

Since the functions in 3.1 used to find the highest and lowest from whole list by mixing the year,
so the functions in 3.2 provided users opportunity to view the highest and lowest by specific year
only.

Figure 31: Methods in Controller Class

The [Link]() function used to filter obtained vaccination record list into
specific year only. The [Link]() function used to compute the
obtained all vaccination record in list<VaccinationRecord> into Map collection that store the
week number with new VaccinationRecord record list.

Functional Concepts:

The partial application functional concepts used in [Link]() by


passed in filterVaxRecordLstYear function as variable in arguments. Two of them should
combine together to work well (Paul, 2015). Moreover, Functional Interface called
TriFunction<A,B,C,R> is declared and used for declaring lambda expression. Functional
Interface is as a single method interface which allow only one method to exhibit
(GeeksforGeeks, 2022).

Figure 32: TriFunction Functional Interface in Computation Class

Page | 24
Not only that, the purity, high order function, pipelining, and lambda expression functional
used.

Figure 33: Methods in Controller Class

The getMaxFromArr and getMinFromArr lambda expressions used for getting the maximum or
minimum integer number from the integer array.

Functional Concepts:

The head recursion concepts with recursive lambda using BiFunction functional interface used
in these two functions. This is because there is recursive call in each function which function
called itself by deducting the counter by 1 in every iteration until it become 0 (stop condition)
(Simic, 2021). It is head recursion because the recursive call is not the last thing that function
executes but the array[0] (Simic, 2021). Not only that, the purity and lambda expression,
functional interface also used.

Figure 34: Methods in Controller Class

Page | 25
Figure 35: Methods in Controller Class

The getMaxTotalWeeklyAdultVaxByYear() function is used to find out the sets which have the
highest total weekly adult vaccination in specific list from the obtained vaccination record
dataset that is by date. The getMinTotalWeeklyAdultVaxByYear() function is used to find out
the sets which have the lowest total weekly adult vaccination in specific list from the obtained
vaccination record dataset that is by date. The getMaxTotalWeeklyChildVaxByYear() function
is used to find out the sets which have the highest total weekly child vaccination in specific list
from the obtained vaccination record dataset that is by date. The
getMinTotalWeeklyChildVaxByYear() function is used to find out the sets which have the
lowest total weekly child vaccination in specific list from the obtained vaccination record dataset
that is by date.

Functional Concepts:

The partial application functional concepts used in the above four functions as they allow
method in BiFunction lambda expression be passed in as arguments. Two of them should
combine to achieve the goal of find lowest and highest total vaccination of adult or child by
week in specific year. Not only that, the high order function, pipelining, and lambda
functional used.

Page | 26
Output:

Figure 36: Search Highest and Lowest Adult and Child Weekly Vaccination Taken by Year 2021

Figure 37: Search Highest and Lowest Adult and Child Weekly Vaccination Taken by Year 2022

Page | 27
5.0 Display the weekly total number of vaccinations by vaccine type

Figure 38: getVaxWeeklyTotalByType Method in Controller class

The getVaxWeeklyTotalByType is lambda expression defined using BiFunction functional


interface type that used for returning the map collection that consist of vaccine type as key and
total as value in set. This function accepts the obtained vaccination record list from dataset and
vaccine type as arguments. Then each vaccination record object in list used will be iterated to
group by year-week and sum the total of vaccine used for phase 1, phase 2 and phase 3. Finally,
there map into the map collection.

Functional Concepts:

Firstly, lambda expression and functional interface (BiFunction) used in this lambda
expression. When [Link]() function call, the lambda expression

Page | 28
allow block of code can be passed in as an argument. So, it as known as anonymous class or
blocks. Besides that, the partial function application concept and currying concept also used
in partial() function from Computation class. This is because that partial () function accepts the
passed in function (TriFunction<A, B, C, R> f or BiFunction<A, B, R> f) as an argument. In this
case, the function passed in is add() function or add3() function from Computation class. The
partial function application only workable when two partial applications combine and used
together.

The partial function application functional concepts used in the above four functions as they
allow method in BiFunction argument types and return type be passed in as arguments. Two of
them should combine to achieve the goal of find lowest and highest total vaccination of adult or
child by week in specific year. Not only that, the high order function, pipelining, and lambda
functional used.

Figure 39: Functional Interface and computation methods in Computation class

Page | 29
Figure 40: partial() methods in Computation class

Output:

Figure 41: Weekly Total Vaccination By Vaccine Type Page

Page | 30
Task 2

Task 2 aimed to list the total vaccination registration of all the states in Malaysia by using the
logic programming language called Prolog. It is also as one of the declarative programming
paradigms. The prolog expresses the logic for solving problem as relations (virtusa, 2022). For
example, that is the sentences for programmer to express the facts and also the rules based on
logic inferences on all available data (Kshirsagar, 2019). There are few steps for completing task
2 which are create the prolog knowledgebase file consists of required facts and rules, then
connected to the prolog knowledgebase file to use the rules and facts in file to query and
compute the required data from dataset.

2.1 Create Prolog Knowledgebase File

Figure 42: printRegistrtaionRecord() Method in PrologKnowledgeBaseFile class

The printRegistrtaionRecord() method used to print line on the prolog file by recursive the
obtained registration record list and insert each registration record object as facts in prolog log by
line. All the data attributes’ values in registration record will be printed as registration () fact in
new prolog file. The format is registration (State, Date, Total, Phase2, Mysj, Call, Web,
Children, ChildrenSolo, Adolescents, Elderly, Comorb, Oku).

Page | 31
Figure 43: printLastestRegistrtaionRecord() Method in PrologKnowledgeBaseFile class

The printLastestRegistrtaionRecord() method used to print line on the prolog file by recursive
the obtained registration record list and insert each registration record object as facts in prolog by
line. Only last 16 registration records that consist of latest total vaccination registration record
will be looped and used to create the facts. Two attributes’ values in registration record will be
included in latest_registration () fact which are state and total. Hence, the format is
latest_registration(State, Total).

Functional Concept

The recursion concept used in these two methods as there is recursive call when function called
itself by adding the counter by 1 in every iteration until it become same size with the array length
(stop condition). It is head recursion because the recursive call is not the last thing that function
executes but return count.

Page | 32
Figure 44: createKnowledgebaseFile() Method in PrologKnowledgeBaseFile class

The createKnowledgebaseFile() method used to create a file with the “.pl” extension called
“APLC_KnowledgebaseFile” in project folder. Not only that, but the method also writes the
necessary facts and rules to the file by line. In this method, the printRegistrtaionRecord() and
printLastestRegistrtaionRecord() methods are used to print two different kind of facts. There are
also some necessary rules require to compute the facts have been inserted together into the
prolog log knowledgebase file at last few lines.

Output:

The below are the content of the prolog file created.

Page | 33
Figure 45: Content inside APLC_KnowledgebaseFile.pl (registration() facts)

Figure 46: Content inside APLC_KnowledgebaseFile.pl (latest_registration() facts)

Page | 34
Figure 47: Content inside APLC_KnowledgebaseFile.pl (Rules)

2.2 Appropriateness of data structure used

From the above facts and rules printed out in created prolog knowledgebase file, the appropriate
data structure has been used. This is because every argument of every predicate are a term or a
list is followed. For registration (State, Date, Total, Phase2, Mysj, Call, Web, Children,
ChildrenSolo, Adolescents, Elderly, Comorb, Oku) predicate, the arguments inside it are all atom
constants and integer constants. The predicate of latest_registration(State, Total) itself is the
structure and the arguments inside it are all atom constants and integer constants.

Not that all the defined rule predicate are also obey the rule of every argument of a predicate
must be a term or a list. For example, state_list(SortList):- findall(State,
registration(State,_,_,_,_,_,_,_,_,_,_,_,_), List),sort(List, SortList). This rule used to find all the

Page | 35
distinct state list from all the facts of registration(). The findall() is a built-in predicate. Inside the
argument of findall(), there is State which is variable, registration(State,_,_,_,_,_,_,_,_,_,_,_,_)
which is structure, and List also the variable. sort() is a structure while there are two variable
inside its arguments.

2.3 Appropriateness of Prolog programming for the requirement

Other than state_list(SortList) :- rule, there are still few rules have been defined in prolog file.

1. filter_registration_by_state_list(List, State) :- used to filter out the registration fact by using


specific state.
2. filter_registration_by_date_list(List, Date) :- used to filter out the registration fact by using
specific date.
3. filter_registration_by_state_date_list(List, State, Date) :- used to filter out the registration
fact by using specific state and date.
4. all_registration_list(List) :- used to get all the registration fact.
5. date_list(SortList):- used to find all the distinct date list from all the facts of registration()
6. sortByState(SortedList) :- used to sort all the lastest_registration() facts by state.
7. sortByTotal(SortedList) :- used to sort all the lastest_registration() facts by total registration
number.

The built-in predicate of prolog programming language such as findall(+Template, :Goal, -Bag),
sort(+List, -Sorted), and keysort(+List, -Sorted) have been used.

Figure 48: connectPLFile() Method in PrologController class

The jpl jar file need to be downloaded and added into the libraries of project in order to allow
programmer to query the prolog file created inside the project system folder. The programmer
needs to establish the connection to the create prolog file through the function called

Page | 36
connectPlFile shown at above before creating the query and get the computed data using rules
and facts inside the prolog file.

Figure 49: Method in PrologController class

Page | 37
Figure 50: Methods in PrologController class

Page | 38
Figure 51: Methods in PrologController class

Page | 39
Figure 52: Methods in PrologController class

For example, registrationRecordFilteredByState(), registrationRecordFilteredByDate(),


registrationRecordFilteredByStateAndDate(), allRegistrationRecordList(),
getRegistrationRecordState(), getRegistrationRecordDate(),
latestRegistrationTotalSortedByState(), and latestRegistrationTotalSortedByTotal() methods

Page | 40
connect to the prolog file through consult query first before that query to the corresponsing rules
in the prolog file respectively. The obtained result will be handled, processed, splited, and
assigned into the object list, string list or string and integer linked HashMap respectively.

Output:

Figure 53: Filter Total Vaccination Registration by State and/or Date (Filter All)

Page | 41
Figure 54: Filter Total Vaccination Registration by State and/or Date (Filter State only)

Figure 55: Filter Total Vaccination Registration by State and/or Date (Filter Date Only)

Page | 42
Figure 56: Filter Total Vaccination Registration by State and/or Date (Filter State and Date)

Figure 57: Sort Total Vaccination Registration by Total Vaccination Registration or State (Sorted by Total)

Page | 43
Figure 58: Sort Total Vaccination Registration by Total Vaccination Registration or State (Sorted by State)

Page | 44
Conclusion

In the conclusion, this computer program successfully developed by mainly using the concept
related to functional programming and logic programming which be categorized under the
declarative programming paradigm. For example, the functional concepts such as purity, high
order function, pipelining, functional composition, currying, partial application, recursion,
lambda expression, lambda currying, lambda recursive, method references, and generic in
wildcard and functional interfaces have been applied during task 1 project development process.
Besides that, the knowledge regarding logic programming approach have been applied in task 2
of the project such as when creating the prolog knowledgebase file, use appropriate data
structure and prolog programming language to design rule and fact, connect prolog file, and
create method based on the prolog rules. All the features developed in this computer program by
strict programming languages because Java and Prolog are both strict programming languages.
This is because the strict programming languages will access all the arguments to the functions
before call or invoke, while the non-strict programming language will only access to the
arguments required by the function after called that function (Moody, 2016). Strict
programming languages call-by-value, whereas non -strict call-by-need (Moody, 2016).

Page | 45
References
baeldung. (2021, December 23). The Basics of Java Generics. Retrieved from Baeldung:
[Link]

Bhumika, R. (2022, March 24). Introduction of Programming Paradigms. Retrieved from


GeeksforGeeks: [Link]
paradigms/

GeeksforGeeks. (2022, January 16). Functional Interfaces in Java. Retrieved from


GeeksforGeeks: [Link]
%20functional%20interface%20is%20an,any%20number%20of%20default%20methods.

Gootooru, N. (2022). hat is stream pipelining in Java 8? Retrieved from java2novice:


[Link]
#:~:text=Answer%3A,%22%20and%20%22terminal%20operations%22.

Inouye, J. (2022, March 15). Functional Programming Languages: Concepts & Advantages.
Retrieved from [Link]: [Link]

Java Functional Composition. (2018, December 10). Retrieved from jenkov:


[Link]

KnoldusInc. (2019, December 20). Functional Java: Let’s understand the higher-order function.
Retrieved from medium: [Link]
the-higher-order-function-1a4d4e4f02af

Kshirsagar, P. (2019, October 15). Prolog | An Introduction. Retrieved from GeeksforGeeks:


[Link]
%20logic%20programming,called%20as%20Facts%20and%20Rules).

Moody, D. (2016). CS5205: Foundation in Programming Languages Lecture 1 : Overview.


Retrieved from Slide Player: [Link]

Oracle. (2022). Upper Bounded Wildcards. Retrieved from Oracle:


[Link]

Page | 46
Paul. (2015, April 23). Partial Function Application in Java 8. Retrieved from Paul Gross's
Blog: [Link]

psil123. (2018, September 18). Currying Functions in Java with Examples. Retrieved from
GeeksforGeeks: [Link]
examples/#:~:text=Function%20Currying%20is%20a%20concept,%2Dvalued
%20argument%20multi%2Dfunctions.

Simic, M. (2021, December 8). Tail vs. Non-Tail Recursion. Retrieved from Baeldung:
[Link]
%20tail%2Drecursive,can%20reuse%20the%20existing%20one.

Singh, A. (2021, July 29). Reading a CSV file in Java using OpenCSV. Retrieved from
GeeksforGeeks: [Link]

Thanoshan, M. (2019, November 12). What exactly is a programming paradigm? Retrieved from
freeCodeCamp: [Link]
paradigm/

virtusa. (2022). DIGITAL THEMES Logic Programming. Retrieved from virtusa:


[Link]
%20programming%20is%20a%20programming,based%20on%20all%20available
%20data.

w3schools. (2022). Java Lambda Expressions. Retrieved from w3schools:


[Link]
%20were%20added%20in,the%20body%20of%20a%20method.

YLD. (2021, February 4). The Not-So-Scary Guide to Functional Programming. Retrieved from
yldBlog: [Link]
#:~:text=A%20side%20effect%20is%20when,described%20as%20having%20side
%20effects.

Page | 47
Page | 48

You might also like