Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

Distinguish between hearing and listening.

Answered: 1 week ago