CT006 3 3 APLC IndAssignmt Question
CT006 3 3 APLC IndAssignmt Question
CT006 3 3 APLC IndAssignmt Question
Learning Outcomes:
ASSIGNMENT DESCRIPTION:
Students are required to answer all the following questions. For each question, students are
mandatorily to explain the given problem or code snippets using their own words and
possible solution code provided using either functional or logic programming
paradigms. It is importantly to note that, the imperative programming paradigms adopted
will be awarded zero marks.
Question 1: (5 marks)
Question 2: (5 marks)
Analyse the code given in Figure 1 and construct the getTotal(filename) method
using method reference mechanism in Java 8 for parsing the given data type.
12
23
34
45
56
56
//put this value into a file, write a functional program to get the value from the file (txt)
n calculate the total exercise in lecture slide
Question 3: (5 marks)
Consider the code in Listing 1. The writeEvenNumTo() method that writes even number
from 0 to 100 to the specified file. Rewrite the method using higher-order function for the
file.
Consider the code in Listing 2. Identify and discuss the possible side-effect and you are
required to adapt it to functional code in Java.
public class Q3 {
Double d1 = 200.0;
Double d2 = 20.0;
d1 = null;
result = demo.mul(d1, d2);
System.out.println( result );
}
public Double mul(Double x, Double y) {
return x * y;
}
}
Listing 2: Code sample for multiplication function
Consider the following requirements. Using a functional language like Java 8, construct a
computer program to calculate the total payment of the order. In an order, compute the 6% of
each item and add 10% of service tax for the shopping order. Calculate the total payment of
the order. Note: rounding up all the computed result.
The program should consider functional concepts like purity, higher-order function, lambda
expression and etc. Note that: Imperative programming style is NOT allowed.
Examine the following code sample and point out the problems of the perform(T) method
in which the type tends to be generic but a type-casting is demanded. Based on the problems,
rewrite the program code in object-oriented programming paradigm (OOP) that satisfies the
generic type for the perform(T) method.
Trace the following program. Compare and contrast between the checker1 and
checker2 for evaluating the expressions. Explain the evaluation strategy used by the
checker1 and checker2.
Appraise the programming concepts that are implemented above. Breakdown the
computational functions for computing sale tax, goods tax, service charge and finally a total
of payment. After defining the functions, compose a new function to compute a price with
goods and sale tax.
Question 9: (5 marks)
Consider the following functional code below. Adapt the given program code using Logic
programming paradigm, Prolog. Your solution code should include recursion concept and
demonstrate the query sample.
Consider the following functional code in Java 8 and answer the question.
Adapt the given program code using Logic programming paradigm, Prolog. Your solution
code should include recursion concept.
Consider the Java code as follows. Adapt the given program code in Listing 1 using Logic
programming paradigm, Prolog. Your solution code should include facts and rules and
demonstrate the query sample.
import java.util.*;
public class Property {
private TreeMap<String, Double> assets = new TreeMap();
public Property collect() {
assets.put("Condominium", new Double(589000.00));
assets.put("Apartment", new Double(430000.00));
assets.put("Semi-D", new Double(860000.00));
assets.put("Factory", new Double(9500000.00));
assets.put("Agricultural Land", new Double(280000.0));
return this;
}
public List<String> find(double price) {
List<String> propLst = new ArrayList();
String name = null;
propLst = assets.entrySet().stream()
.filter( p -> p.getValue() > price )
.map( p -> p.getKey() )
.collect(Collectors.toCollection(
ArrayList::new ));
return propLst;
}
public static void main(String[] args) {
System.out.println( new Property()
.collect()
.find( 500000.00 ) );
}
}
import java.util.*;
public ProductController() {
productLst.put("Pen", 9.9);
productLst.put("ruler", 3.9);
productLst.put("bag", 58.9);
productLst.put("testpad", 11.2);
}
return pName;
}
Knowledge/Presentation
Able to analyse the given problem or code snippets and revise solution code
declaratively or functionally as well as logically.
Able to explain the developed solution with code snippets in a good report
presentation manner.
Software Required
ASSIGNMENT TYPE:
Individual Assignment
HAND-IN DATE:
GRADING CRITERIA
A+ = Distinction A+ = 80-100
Superior achievement in assignment,
outstanding quality; complete in every way.
A = Distinction A = 75-79
Very high achievement in all objectives,
excellent quality assignment.
B+ = Credit B+ = 70-74
Very good/High achievement in most objectives,
high quality assignment.
B = Credit B = 65-69
Good/High achievement in most objectives,
shows some of the qualities but lacks
comprehensiveness nevertheless quality assignment.