[Solved] CSIT121 Lab 6- Application that declares an array of elements to prices of items

$25

File Name: CSIT121_Lab_6-_Application_that_declares_an_array_of_elements_to_prices_of_items.zip
File Size: 753.6 KB

SKU: [Solved] CSIT121 Lab 6- Application that declares an array of elements to prices of items Category: Tag:
5/5 - (1 vote)

Following completion of this task, students should be able to:

  • Write Java applications using lambdas and streams.

Write a Java application that declares an array of 20 elements to store the prices of items sold at a grocery store. Initialize the array with 20 prices. Then, using lambda and streams perform the following operations on the array created:

  1. Display all prices sorted in ascending order
  2. Display the total prices.
  3. Display the most expensive price, the cheapest price, and the average price.
  4. Count and display all prices that are above RM100 sorted in ascending order
  5. Increase all prices to 10% of its original price, sort, and display the new prices.
  6. Display all prices that are in the range of RM100 and RM500 inclusive

Declare and implement a class called Invoice with the following fields:

  • part number (an integer value)
  • description (such as hammer, wrench, sugar, flour, etc)
  • type (such as hardware, grocery, etc)
  • quantity (an integer)
  • price (a double value)

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

Use the class Invoice above to create an array of Invoice objects. Use the data given in the data.txt file to set the values for each of the objects in the array. Then, perform the following queries on the array of Invoice objects and display the result.

  1. Use lambdas and streams to sort the Invoice objects by description, then display the results.
  2. Use lambdas and streams to sort the Invoice objects by price, then display the results.
  3. Use lambdas and streams to display the Invoice objects group by type.
  4. Use lambdas and streams to map each Invoice to its description and the value of the invoice (quantity * price). Order the results by Invoice value.
  5. Re-write (d) to select the Invoice values in the range of RM200 to RM500.

Write a recursive method called power(), that takes as parameters two integers x and y such that x is non-zero and returns xy. Use the following recursive definition to calculate xy.

If y 0:

1 if y = 0

xy = x if y = 1

x xy-1 if y 0

If y < 0: xy = 1 .

xy

Write a main method to test your recursive method above. Let the user enters the value for x and y. Call the recursive method and display the result.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSIT121 Lab 6- Application that declares an array of elements to prices of items
$25