COURSEWORK SPECIFICATION
OBJECTIVES:
Following completion of this task, students should be able to:
§ Write Java applications using lambdas and streams. § Design and write recursive methods.
Question 1
Write a Java application that declares an array of 20 integers. Populate the array with random numbers in the range of 1 to 100. Then, using IntStream, perform the following operations on the array created:
Show the original content of the array
Show the numbers in the array sorted in ascending order
Display the minimum, maximum, and average of the numbers in the array
Display all numbers that are greater than 50 sorted in ascending order
Count and display all numbers divisible by 5 multiplied by 10 in ascending order Calculate and display the sum of squares of all even numbers
Question 2
Declare and implement a class called Household with the following fields:
id (an integer representing an id of the household record)
location (a String representing the location of the household such as urban, suburban, or rural)
totalMember (an integer representing the number of people in the household)
income (the total income of the household)
Implement the following methods for the class Invoice:
a non-default constructor that takes parameters to set all of its fields
set methods for each of the fields
get methods to retrieve each of the fields
Write a main() method that uses the class Household above to create an array of Household objects. Use the data given in the data.txt file to set the values for each of the objects in the array. Then, use lambdas and streams to perform the following queries on the array of Household objects and display the result.
Sort the
Household
objects by income in ascending order, then display the results.
Sort the Household objects by totalMember in ascending order, then display the results. c) Display all household group by location.
Count the number of households in each location.
Calculate the sum of all household income using the sum method.
Redo question (e) but perform the sum using the reduce method.
Calculate the average household income.
Redo question (g) but produce the average separately for all urban household, suburban household, and rural household.
Display all household with income in the range of RM1000 to RM10000.
Display all household with income more than RM10000.
Question 3
Write a recursive function that takes as a parameter a nonnegative integer representing the number of lines and generates the following pattern of stars. If the nonnegative integer is 4, then the pattern generated is:
****
***
**
**
***
****
Write a program that prompts the user to enter the number of lines and uses the recursive function to generate the pattern.