Question: Here are some JAVA Problems - - For each of the following exercises provide a solution that uses methods of the Stream interface. 1 Write

Here are some JAVA Problems
--For each of the following exercises provide a solution that uses methods of
the Stream interface.
1
Write a method getElement implementing a partial function that given an
array arr and an int index returns arr[index] if defined. Use Optional as the result
type. Next write methods implementing the following partial functions:
sqrt, that applied to an integer returns its square root as a double, if the
argument is not negative;
half, that applied to an integer returns its half as an integer, if the argument is
even.
Finally write a method that composing getElement, sqrt and half, when applied to an
array of integers arr and to an int index, returns the square root of the half
of arr[index], if defined.
2
Consider the attached csv file people.csv. This file stores information about people
subscribed to a simple service. Each line of the file represents a record. The fields of
each record are separated by a comma "," and have the following meaning
id,firstname,surname,title,address,town,country,postcode,subscription
paid,gender,date of birth
In a record the fields id, firstname, surname, date of birth, subscription paid are
mandatory, while the others are optional (denoted by "-" in the file). Implement a
class Subscriber representing a subscriber, providing a property for each field. Use
the Optional class to denote optional fields.
Write a static method loadDatabase that returns a List containing the
records of the file subscriber.csv. Furthermore, implement another static
method PaymentFromGB that given a List prints the subscribers from GB
that have paid the annual fee.
Hint: Use the methods of Optional class to deal with optional values.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!