1. A table manager manages a table. A table consists of several rows. Each row has a row header followed by a collection of data entries. For example:
Header |
Data |
|||
Monday |
task3 |
task4 |
task5 |
|
Tuesday |
task1 |
task6 |
|
|
Wednesday |
task2 |
task1 |
task2 |
task7 |
Thursday |
task3 |
task4 |
task4 |
|
Friday |
task1 |
|
|
|
We can implement a table using Java's Map interface:
Map<Header, Collection<Data>> table;
Here's a partial implementation of a table manager:
For each of the following descriptions of a table, write a test driver that uses the table manager to create and print a sample table. Note that in some cases the choice of implementation for the data rows will depend on if the rows should be sets, sorted sets, or multi-sets.
A work schedule is a table. Each row is a collection of tasks that must be performed by a person.
A grade book is a table. Each row is a collection of integer grades received by a person.
2. In a two- dimensional table each row is a one-dimensional table that associates a column header with a data value. For example, here's a two-dimensional table representing a domestic budget:
ROW HEADERS |
|
|||
|
JAN |
FEB |
MAR |
APRIL |
food |
$400.00 |
$350.00 |
$412.00 |
$386.00 |
rent |
$1,200.00 |
$1,200.00 |
$1,200.00 |
$1,200.00 |
gas |
$375.00 |
$300.00 |
$289.00 |
$310.00 |
utilities |
$110.00 |
$122.00 |
$95.00 |
$89.00 |
We can look up and set individual entries in a two dimensional table:
budget.put(gas, May, 300);
budget.get(gas, May); // returns 300
Implement and test a generic Table class.
(What would the declaration of a three-dimensional table look like?)