Advance Programming Language Assignment | College Homework Help

This Assignment is coding based, which based on 11 Programming Question which needed to be solved in Any Java IDE with JDK 8 onwards and SWI-Prolog. For more information please find the attachment.

Learning Outcomes:

Don't use plagiarized sources. Get Your Custom Essay on
Advance Programming Language Assignment | College Homework Help
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

 

On conclusion students should be able to:

CLO1:   Compare various programming language paradigms such as object oriented and functional paradigms by analysing the structure and behaviour of code. (C4, PLO2)

CLO2:  Adapt functional programs to solve computing problems using functional and logic programming language concepts. (P6, PLO3)

 

 

No. Learning Outcome Assessment
1 Compare various programming language paradigms such as object oriented and functional paradigms by analysing the structure and behaviour of code. (C4, PLO2) Individual Assignment
2 Adapt functional programs to solve computing problems using functional and logic programming language concepts. (P6, PLO3) Individual Assignment
3 Explain the features of modern non-strict functional languages by comparing their behaviour against the standard of the paradigms. (C2, PLO1) Quiz

 

 

 

 

 

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)

 

Analyse the following MathUtility class. Explain it in detail in the context of functional programming concepts.  Your explanation should include a comparison between imperative and declarative/functional programming concepts according to the given code example.

 

public class MathUtility {

private static int count = 1;

public static int sum(int num1, int num2) {

count++;

multiply(num1,num2);

return num1 + bnum2;

}

}

 

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

 

Figure 1: List of numbers

 

 

 

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.

 

static void writeEvenNumTo( String fn ) {

for (int i = 0; i <= 100; i+=2) {

String line = Integer.toString(i) +
System.lineSeparator();

try {

Files.write(

Paths.get(fn),

line.getBytes(),

StandardOpenOption.CREATE,

StandardOpenOption.APPEND);

} catch (IOException e) {

e.printStackTrace();

}

}

}

Listing 1: Code sample for writing even number (0-100) to file

Question 4: (10 marks)

 

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 {

 

public static void main(String[] args) {

Q3 demo = new Q3();

 

Double d1 = 200.0;

Double d2 = 20.0;

 

double result = demo.mul(d1, d2);

System.out.println( result );

 

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

 

 

 

 

Question 5: (10 marks)

 

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.

 

ITEM NAME PRICE TAX (6%) SUB-TOTAL
Milk 3.9 0.234 4.134
 Cookies 15.5 0.93 16.43
Peanut butter 15.9 0.945 16.854
    GRAND TOTAL: 37.418
    SERVICE TAX (10%): 3.7418
    TOTAL PAYMENT: 41.1598

Table 1: Order list for payment calculation including tax involved

 

 

 

Question 6: (10 marks)

 

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.

 

public class Demo {

private static class Researcher{

public void doArticle() { System.out.println(

“Researcher is writing a full-text article.”);

}

}

private static class Lecturer{

public void doArticle() { System.out.println(

“Lecturer is writing a full-text article.”);

}

}

private static <T> void perform(T type){

type.doArticle();

}

public static void main(String args[]){

Researcher resrcher = new Researcher();

Lecturer lec = new Lecturer();

perform(resrcher);

perform(lec);

}

}

 

 

Question 7: (10 marks)

 

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.

 

static BiFunction<String, String, Boolean> find = (s, ch) -> {

System.out.println(“Loading…”);

return s.contains(ch);

};

static BiFunction<Boolean, Boolean, String> checker1 =

(b1, b2) -> b1 && b2 ? “Matched” : “Not matched”;

static BiFunction<Supplier<Boolean>, Supplier<Boolean>,

String> checker2 = (b1, b2)

-> b1.get() && b2.get() ? “Matched” : “Not matched”;

public static void main(String[] args) {

System.out.println(

checker1.apply( find.apply(“abcapu.edu.my”, “@”),

find.apply(“abc@apu.edu.my”, “@” ) ) );

System.out.println(

checker2.apply( () -> find.apply(“abcapu.edu.my” ,”@”),

() -> find.apply(“abc@apu.edu.my”, “@”) ) ); }

 

 

 

Question 8: (10 marks)

 

Consider the following Java code.

 

//add 2% (sale tax) for each unit price

Stream<Double> withSaleTax = unitPrice.stream()

.map( e -> e * (1+0.02) );

//add 6% (goods tax) for each price with saletax

Stream<Double> withSixPercent = withSaleTax

.map( e -> e * (1+0.06) );

//add 10% service charge to the total

double paymentWithTenPercent = withSixPercent

.mapToDouble( Double::doubleValue )

.sum() * (1+0.1);

 

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.

 

int sum = Stream.of(1,2,3).reduce(0, (e1, e2) -> e1 + e2);

 

 

Question 10: (10 marks)

 

Consider the following functional code in Java 8 and answer the question.

 

List<Integer> list = Arrays.asList( 11,2,3,4,5,6 );

 

//display original list

System.out.println( list );

 

//reverse the list

list.stream().collect( Collectors.toCollection( LinkedList::new ) )

.descendingIterator()

.forEachRemaining( n -> System.out.print( n + ” ” ) );

 

Adapt the given program code using Logic programming paradigm, Prolog.  Your solution code should include recursion concept.

 

 

 

Question 11: (10 marks)

 

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 ) );

}

}

 

 

Question 12: (10 marks)

 

Rewrite the program using Prolog achieves the same requirements.

 

import java.util.*;

 

public class ProductController {

 

private TreeMap<String, Double> productLst = new TreeMap();

 

public ProductController() {

productLst.put(“Pen”, 9.9);

productLst.put(“ruler”, 3.9);

productLst.put(“bag”, 58.9);

productLst.put(“testpad”, 11.2);

}

 

public static void main(String[] args) {

ProductController pc = new ProductController();

List<String> cheapItems = pc.findItems( 10 );

cheapItems.stream().forEach(System.out::println);

}

 

public List<String> findItems(double threshold) {

List<String> pName = new ArrayList();

 

for (Map.Entry p : productLst.entrySet()) {

if ( (double)p.getValue() < threshold ) {

pName.add( (String)p.getKey() );

}

}

 

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

 

  • Any Java IDE with JDK 8 onwards
  • SWI-Prolog

 

 

ASSIGNMENT TYPE:

 

Individual Assignment

 

 

HAND-IN DATE:

 

Friday, 22 May, 2020 by 23:59

 

 

GRADING CRITERIA

 

MARKING KEY                                                                          EQUIVALENT MARKS

 

A+  =   Distinction                                                                                       A+  =  80-100

            Superior achievement in assignment,

outstanding quality; complete in every way.

 

 

 

Quick Homework Essays
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.