NEED A PERFECT PAPER? PLACE YOUR FIRST ORDER AND SAVE 15% USING COUPON:

CSIT121/821 Lab Exercises

CSIT121/821 Lab Exercises.

CSIT121/821 Lab Exercises
Lab 6
Deadline: 8 Nov 2020, 10 PM
Objectives
• Familiar with Lambda, Stream and Recursive.
Use Lambda and Stream to convert Q1 and Q2.
Q1 (1 Mark):
int[] values=12,2,9,8,4,65,7,4,2,66,88,11,33,44,55;
double result = 0;
for(int e : values)
result = result +e;

result=result/values.length;
Q2 (1 Mark):
Integer[] values=12,2,9,8,4,65,7,4,2,66,88,11,33,44,55;
Set<Integer> a = new TreeSet<>(Arrays.asList(values));
for(int e : a)
System.out.println(e);

Q3: Write the following code and use Lambda and Stream to process its instances. (1.5 marks)
Given the following CarEngine class
public class CarEngine
private String engineName;
private int cylinderVolumn; // example 2.4L
private int numberOfCylinder;
private String fuelType;
public CarEngine(String engineName, int cylinderVolumn, int numberOfCylinder, String fuelType)
this.engineName = engineName;
this.cylinderVolumn = cylinderVolumn;
this.numberOfCylinder = numberOfCylinder;
this.fuelType = fuelType;

public String getEngineName()
return engineName;

public void setEngineName(String engineName)
this.engineName = engineName;

public int getCylinderVolumn()
return cylinderVolumn;

public void setCylinderVolumn(int cylinderVolumn)
this.cylinderVolumn = cylinderVolumn;

public int getNumberOfCylinder()
return numberOfCylinder;

public void setNumberOfCylinder(int numberOfCylinder)
this.numberOfCylinder = numberOfCylinder;

public String getFuelType()
return fuelType;

public void setFuelType(String fuelType)
this.fuelType = fuelType;

Write the following code in the main method.
1. Create 5 objects of the car and save them to the HashMap where the key is an engine name.
2. Write the code to search the object by the engine name (using Lambda and Stream)
3. Write the code to search for the engine that the cylinder volume between 1000 cc. to 2400 cc. and
display them to the console. (using Lambda and Stream)
Q4: Tower of Hanoi (1.5 marks)
Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is
to move the entire stack to another rod, obeying the following simple rules:
1) Only one disk can be moved at a time.
2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e.
a disk can only be moved if it is the uppermost disk on a stack.
3) No disk may be placed on top of a smaller disk.
Approach :
Take an example for 2 disks :
Let rod 1 = ‘A’, rod 2 = ‘B’, rod 3 = ‘C’.
Step 1: Shift first disk from ‘A’ to ‘B’.
Step 2: Shift second disk from ‘A’ to ‘C’.
Step 3: Shift first disk from ‘B’ to ‘C’.
Image illustration for 3 disks :
Write a recursion program to solve the Tower of Hanoi. The program shall ask user to input the number of disks
(n) and output the steps to solve the problem (You must use the recursion).
Examples:
Input: 2
Output: Disk 1 moved from A to B
Disk 2 moved from A to C
Disk 1 moved from B to C
Input: 3
Output: Disk 1 moved from A to C
Disk 2 moved from A to B
Disk 1 moved from C to B
Disk 3 moved from A to C
Disk 1 moved from B to A
Disk 2 moved from B to C
Disk 1 moved from A to C
Submission:
• Please submit your solution to Moodle. Email submission is not accepted.
• Please submit an individual PDF document to contains all your solutions for all tasks.
• For Q1 and Q2, please just paste the java code.
• For Q3 and Q4, please paste the whole program and the compilation and the execution of your program.
Note: Turnitin will be used to check similar submissions. Plagiarism will be reported to the school, and all
involving students will receive the zero mark or other penalties based on the university’s regulation.

CSIT121/821 Lab Exercises

Solution:

15% off for this assignment.

Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!

Why US?

100% Confidentiality

Information about customers is confidential and never disclosed to third parties.

Timely Delivery

No missed deadlines – 97% of assignments are completed in time.

Original Writing

We complete all papers from scratch. You can get a plagiarism report.

Money Back

If you are convinced that our writer has not followed your requirements, feel free to ask for a refund.