Lp2A - Td2 Array, Tree, Collections, List : Exercise 1
Lp2A - Td2 Array, Tree, Collections, List : Exercise 1
Exercise 1
We wish to develop a system for managing groups of students. To do this, we will
create a class that will handle an array that will contain information about students:
- Last name,
- First name,
- Age,
- …
Exercise 2
We want to develop a system for the management of the staff of a company. This
system must be able to manage the hierarchy between people. Thus, for a given
person, the system must be able to return a list of his subordinates and the name of its
leader.
To do that, we will construct an n-ary tree that will manage the information of people
(name, salary, etc.)
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, NavigableSet<E>, Set<E>,
SortedSet<E>
The elements are ordered using their natural ordering, or by a Comparator provided
at set creation time, depending on which constructor is used.
E ceiling(E e)
Returns the least element in this set greater than or equal to the given element,
or null if there is no such element.
E floor(E e)
Returns the greatest element in this set less than or equal to the given element,
or null if there is no such element.
E higher(E e)
Returns the least element in this set strictly greater than the given element, or
null if there is no such element.
E lower(E e)
Returns the greatest element in this set strictly less than the given element, or
null if there is no such element.
Exercise 4
We want to develop an application for classifying the DVD, CD, book, etc. To do this,
we will use a collection of type Set: HashSet.
Our system should be able to accept new books, CDs or DVDs and a function, call
periodically by the user, will allow to clean the structure. This function will ask, for
each book, CD or DVD, if it’s still exists. If this is not the case, the item will be removed
from the structure.
o Create a class that handles the media of all types. This class must have the
following methods:
§ A method for adding a new media.
§ A method that displays on the screen a list of all the media content
from the structure according to their type.
§ A method that ask the user for each media, whether or not there
are still. If not the item is deleted from the HashSet.
§ Write the Java program.
Our application is now able to manage the loan of books, CDs or DVDs. To do that, we
will create a class to manage person who can borrow media. Our application will be able
to return a list of borrowed media for a given person, but also return for a media, if it is
taken or not and if so, by whom.
Preliminary information:
Scanner class can parse primitives types and string using regular expressions. For our
exercise, we’ll use it to allow us to retrieve easily the keystrokes of the users.
This example shows how to use the Scanner class to read the information entered by the
user:
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
In this example, we read an integer by the method nextInt(). But this class allows us to
read others types of data with methods:
nextFloat() : float
nextDouble() : double
nextLong() : long
nextLine() : String
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>
HashSet()
Constructs a new, empty set; the backing HashMap instance has default
initial capacity (16) and load factor (0.75).
boolean add(E e)
Adds the specified element to this set if it is not already present.