0% found this document useful (0 votes)
364 views2 pages

Java Collection Management for Gifts

The document outlines requirements for a program to manage gift-giving within a large extended family. It describes: 1) Problems that occurred with uncles duplicating gifts in previous years. 2) The program must allow adding family members and recording birthdays. It must check that each niece receives a unique gift from each uncle and that uncles don't give the same gift to multiple nieces. 3) The document specifies classes - Family, Uncle, and Niece - and their required methods to implement the program requirements without a user interface. The Family class would add/find family members and list them, while the Uncle and Niece classes would add/list assigned gifts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
364 views2 pages

Java Collection Management for Gifts

The document outlines requirements for a program to manage gift-giving within a large extended family. It describes: 1) Problems that occurred with uncles duplicating gifts in previous years. 2) The program must allow adding family members and recording birthdays. It must check that each niece receives a unique gift from each uncle and that uncles don't give the same gift to multiple nieces. 3) The document specifies classes - Family, Uncle, and Niece - and their required methods to implement the program requirements without a user interface. The Family class would add/find family members and list them, while the Uncle and Niece classes would add/list assigned gifts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Problem Scenario
In a large family, there are many uncles (and aunts) and many nieces (and nephews). Each uncle
buys a present for each niece on her birthday every year. Unfortunately, this can cause all sorts of
problems:
• Last year Amy received a charming book (‘The Wonder of Computers’) from Uncle Albert.
Unfortunately, Uncle Bill gave it to her too.
• When Beatrice opened her present from Uncle Charlie, she found it was the same thing he had
given to Claire. “How could he?” she shouted rudely, “I’m not at all like Claire!”.
• Uncle David is getting forgetful. Little Emily was so upset not to get a present.
1.1 Program Requirements
The family decide they need a computer program to manage the giving of presents. The
requirements are:
1. Uncles and nieces can be added to the system. The date of each niece’s birthday is recorded.
2. A list of uncles can be generated – in alphabetical order by name.
3. A list of nieces can be generated – in order of birthday.
4. The system holds a list of the presents selected by each uncle for the next birthday of one of
his nieces. Each present is described in a few words.
5. An uncle can enter the present he intends to give to one of his nieces. The program ensures
that:
i. each niece receives something different from each uncle
ii. each uncles gives something different to each niece.
6. A list of the presents given by one of the uncles can be generated, showing the niece who is to
receive it. The nieces for whom no present has been chosen should also be listed.
7. A list of presents to be received by one of the nieces can be generated, showing the uncle
giving it. The uncles who have no present for the niece should also be listed.
8. The list of presents for a niece can be deleted (that’s done when her birthday is past).

1.2 Your Task


Write a program to meet the requirements. To make a start, write classes to provide the behaviour,
without a user interface. The public classes you should provide are: Family, Niece and Uncle. The
public methods of these classes create an interface (often called an API – Application Program
Interface) to which a user interface could be attached. The API is described below; note that your
program will also contain other classes and methods.

Class Family
Class representing a family.

Constructor Summary
Family()
Create an empty family with no uncles, nieces or presents.

DCS 235 – Lab Exercise 2 (version 1.2, 12 Oct 04) Page 2 of 5


Method Summary
boolean addNiece([Link] name, int day, int month)
Add a new niece. If there is already a niece of this name, false is returned and
nothing is added.
boolean addUncle([Link] name)
Add a new uncle. If there is already an uncle of the name, false is returned and
nothing is added.
Niece findNiece([Link] name)
Lookup a niece by name; return null if not found.
Uncle findUncle([Link] name)
Lookup an uncle by name; return null if not found.
void listNieces()
List (to the console) the nieces recorded.
void listUncles()
List (to the console) the uncles recorded.

Class Uncle
Class representing an uncle. Note that the constructor is not public – use [Link]().

Method Summary
boolean addPresent(Niece recipient,
[Link] description)
Adds a new present, given by this uncle. Return true if the present is allowed.
void listPresents()
Lists (to the console) the presents given by this uncle, showing the recipient.
Nieces with no present from this uncle are also listed.

Class Niece
Class representing a niece. Note that the constructor is not public – use [Link]().

Method Summary
int clearPresents()
Delete all the presents chosen for this niece. Return the number removed.
void listPresents()
Lists (to the console) the presents to be received by this niece, showing the
giver. Uncles with no present for this niece are also listed.

DCS 235 – Lab Exercise 2 (version 1.2, 12 Oct 04) Page 3 of 5

Common questions

Powered by AI

To adapt the system for other celebratory events, modifications could include creating more generalized event classes or methods that handle various celebrations, each with its own present management logic. The system could also adopt a calendar-based approach, allowing any given date to be tied to specific family members and recorded events. This flexibility would require adjusting present assignment and retrieval methods to accommodate a wider array of event types and associated gift transactions .

A console-based implementation might limit user interaction due to its text-only interface, which can be less intuitive and harder to navigate compared to graphical interfaces. Additionally, the lack of persistent storage means all family and gift data is likely lost between sessions unless explicitly implemented otherwise. Lastly, scalability issues may arise as the family grows larger, making it cumbersome to manage and track data solely through console outputs .

Using a class-based structure provides clarity and organization, allowing encapsulation of data and behavior relevant to family dynamics, such as managing familial roles through the 'Family,' 'Niece,' and 'Uncle' classes. However, drawbacks include potential rigidity in adapting to less straightforward family relations and increased complexity in ensuring all required interactions and data flows are accommodated within a fixed class architecture .

The system is designed to ensure that each niece receives a unique present from each uncle by allowing uncles to enter the intended present for each niece and then verifying the uniqueness across all presents for that niece. The method 'addPresent(Niece recipient, java.lang.String description)' in the Uncle class returns true if the present is allowed, meaning it ensures the present is unique for both the niece and the uncle. This mechanism helps avoid duplication issues mentioned in the problem scenario .

The program design employs encapsulation by using classes like 'Family,' 'Uncle,' and 'Niece' to hide the data and operations associated with each type of family member. It also follows the single responsibility principle, as each class handles particular functions: Family for overall management, Uncle for gift-giving functionalities, and Niece for gift-receiving functionalities .

To handle gift duplication more effectively, the system could incorporate a feature that maintains a historical record of gifts each niece has received in past years. This history would be checked against the new gifts being assigned for duplicates. Another approach could be implementing warning mechanisms for uncles when selecting a present that has already been chosen by another uncle for the same niece .

The 'clearPresents()' method is crucial in marking the transition between gift-giving cycles by removing all presents chosen for a niece once her birthday has passed, effectively resetting the system for the next year's giving cycle. This method helps maintain current data integrity and prepares the system to manage upcoming birthday preparations without confusion from outdated or fulfilled gift assignments .

The API design, through public methods for adding, listing, and managing data, allows for easy integration with a user interface. By defining clear and distinct functions for operations such as listing members and managing gifts, it creates a modular structure that can be extended. This separation of interface from logic enhances adaptability, allowing future UI components to interact smoothly with the underlying data processing logic .

Listing uncles and nieces, organized alphabetically or by birthday, can enhance user experience by providing order and logic to what could be large sets of data. It allows users to quickly locate specific individuals or track upcoming events. However, for very large families, generating these lists might become resource-intensive and slow, potentially leading to delays or data overload, which impacts usability negatively .

The 'listPresents()' method provides functionality enhancements by allowing uncles to review the list of presents they have selected and identify any nieces without assigned gifts, thereby reducing the chance of oversight. For nieces, this method helps them understand what gifts are expected and from whom, fostering transparency and preventing disappointment on their birthdays. It also helps in maintaining an organized overview of gift-giving within the family .

1.Problem Scenario
In a large family, there are many uncles (and aunts) and many nieces (and nephews).  Each uncle
buys a pre
Method Summary
 boolean addNiece(java.lang.String name, int day, int month) 
          Add a new niece.  If there is alrea

You might also like