Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have defined and implemented the array list and list interface but I\'m stuck

ID: 3844127 • Letter: I

Question

I have defined and implemented the array list and list interface but I'm stuck as to how to proceed from here for the following question from Chapter 8 Lists pg. 264 Problem 2 Data Abstratcions & Problem Solving with C++ (7th edition): Creating a "nice list for children who will receive gifts. Each object in this list contains a name (a string) and a list of that person's gifts (an instance of an ADT list.) Design an ADT for the objects in the nice list. Specify each ADT operation by stating its purpose describing its parameters, and writing preconditions, postconditions, and a pseudocode version of its header. Then write a template interface for the ADT that includes javadoc-style comments.)"

Any help in writing out this program would be greatly appreciated as I have to submit my answers in 3 1/2 hours. Thank you. My nerves are getting in my way right now due to the time crunch. I look forward to hearing from you shortly. Chesley

In regards to your request for more info:

`The java.doc is just a type of C++ comment. No need to worry about that right now. Java.doc is documentation including a. an initial comment at the top of each source code file that includes file name (efile), statement of purpose, Author (@author), Date (@date), optional file version number (@version); 2. Initial comments for each class that includes: name of class and its header file (@class), statement of purpose; 3. Initial comments for each method or function that includes statement of purpose, description of each parameter (@param), precondition (3pre), postcondition @post), exceptions thrown (@throw), return value (@return); Standard C++ comments in the body of each method or function to explain important features or subtle logic.

Hope that helps to understand that the program is still in C++ with just the added java.doc comments like above. Chesley

Explanation / Answer

package com.clairiot;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Random;

public class RandomChristmasGift {

    

    List<Child> children = new ArrayList<Child>();

    

    public RandomChristmasGift() {

        super();

    }

    

    public static void main(String[] args) {

        RandomChristmasGift santa = new RandomChristmasGift();

        santa.addChild(new Child("erik@me.com", "Erik"),

                       new Child("joe@me.com", "Manon"),

                       new Child("jane@me.com", "Marie"),

                       new Child("rogers@me.com", "Melissa"));

        Map<Child, Child> invitations = santa.getInvitations();

        santa.sendInvitations(invitations);

    }

    public void addChild(Child... childrenList) {

        for (Child child : childrenList) {

            if (children.contains(child)) {

                throw new IllegalArgumentException("Child already registered to this Christmas party");

            }

            children.add(child);

        }

    }

    public Map<Child, Child> getInvitations() {

        Collections.shuffle(children, new Random(System.nanoTime()));

        

        Map<Child,Child> invitations = new HashMap<Child,Child>();

        

        for (int i = 0; i < children.size() - 1; i++) {

            invitations.put(children.get(i), children.get(i+1));

        }

        invitations.put(children.get(children.size() - 1), children.get(0));

        return invitations;

    }

    public void sendInvitations(Map<Child, Child> invitations) {

        StringBuilder proofOfValidity = new StringBuilder();

        for (Map.Entry<Child,Child> entry : invitations.entrySet()) {

            proofOfValidity.append(entry.getKey().name + " will offer a gift to " + entry.getValue().secretName + " ");

        }

        for (Map.Entry<Child,Child> entry : invitations.entrySet()) {

            String sender = entry.getKey().email;

            String messageContent = "New order from Santa Claus : ";

            messageContent += "Your mission is to send a gift to " + entry.getValue().name;

            messageContent += " Christmas gifts : ";

            messageContent += proofOfValidity.toString();

            

            sendMail(sender, messageContent, "Christmas party : you received a message from Santa Claus !");

        }

    }

    private void sendMail(String sender, String messageContent,

                          String title) {

        

        System.out.println("Send mail to " + sender + " with content " + messageContent);

    }

}

class Child {

    

    private static int childIndex = 1;

    

    String email;

    String name;

    final int secretName = childIndex++;

    public Child(String email, String name) {

        super();

        this.email = email;

        this.name = name;

    }

    @Override

    public boolean equals(Object object) {

        if (this == object) {

            return true;

        }

        if (!(object instanceof Child)) {

            return false;

        }

        final Child other = (Child)object;

        if (!(email == null ? other.email == null : email.equals(other.email))) {

            return false;

        }

        return true;

    }

    @Override

    public int hashCode() {

        final int PRIME = 37;

        int result = 1;

        result = PRIME * result + ((email == null) ? 0 : email.hashCode());

        return result;

    }

}