Question

In: Computer Science

import java.util.ArrayList; import java.util.Collections; public class BirthdayList { /** * This is the main process for...

import java.util.ArrayList;
import java.util.Collections;

public class BirthdayList
{
/**
* This is the main process for class BirthdayList
*/
public static void main()
{
System.out.println("\n\tBegin Birthday List Program\n");
  
System.out.println("Declare an ArrayList for Birthday objects");
// 1. TO DO: Declare an ArrayList to store Birthday objects (3 Pts)
  
  
// 2. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts)
System.out.printf("\nBirthday List is empty: %s\n",
xxx.xxxx() ? "True" : "False");
  
System.out.println("Add at least five Birthdays to the list");
// 3. TO DO: Add five or more Birthday objects to the Birthday list (5 Pts)
// Format is: xxxxx.add(new Birthday("mm/dd","name")):
  
  
  
  
  
  
  
System.out.printf("Birthday List is empty: %s\n",
bdayList.isEmpty() ? "True" : "False");
  
// 4. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts)
System.out.printf("Birthday list has %d entries\n", xxx.xxxx());
  
System.out.println("\nDisplay unsorted Birthday list");
listBirthdays(bdayList);
  
System.out.println("\nDisplay 3rd Birthday in the listlist");
// 5. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts)
System.out.printf("%s\n", xxx.xxxx());
  
// 6. TO DO: Remove a Birthday object from the list by index;
// Replace the xxx.xxxx() with the appropriate method (2 Pts)
System.out.printf("%s was removed from the list\n", xxx.xxxx());
System.out.printf("Birthday list has %d entries\n", bdayList.size());
  
// 7. TO DO: declare a new Birthday object to replace one in the list (1 Pts)
  
  
// 8. TO DO: Replace (set) an element in the ArrayList with the new Birthday
// object and complete the System.out.printf statement to display the original
// Birthday object and the new (replacement) Birthday object (5 Pts)
System.out.printf("\nChange %s to %s\n", xxx.xxxx(), xxx.xxxx());
  
System.out.println("\nCopy original Birthday list to new Birthday list");
// 9. TO DO: Copy the original ArrayList to a new one called newList (3 Pts)
  
  
System.out.println("\nSort new Birthday list");
// 10. TO DO: sort the new ArrayList (2 Pts)
  
  
System.out.println("\nDisplay new sorted Birthday list");
listBirthdays(newList);
  
System.out.println("\n\tEnd Birthday List Program\n");
}
  
/**
* This function lists all the Birthdays in the list
* @param list - reference to the Birthday ArrayList
*/
public static void listBirthdays(ArrayList<Birthday> list)
{
int number = 1;
for(Birthday bDay : list)
System.out.printf("%3d - %s\n", number++, bDay.toString());
}
}

import java.lang.String;

public class Birthday implements Comparable<Birthday>
{
private String date; // Format mm/dd
private String name;

/**
* Constructor for objects of class Birthday
* @param date - in the format mm/dd
* @param name - name associated with date
*/
public Birthday(String date, String name)
{
this.date = date;
this.name = name;
}

/**
* This method provides the comparison function for sorting
* It uses the compareTo method supplied with the String class
* @param other - reference to the Birthday to be compared to
* @return positive value if host date > other date
* negative value if host date < other date
* zero (0) if dates are equal
*/
public int compareTo(Birthday other)
{
return date.compareTo(other.date);
}
  
/**
* This method overrides the toString() method of the Object class
* It returns a String with the Birthday informtion
* @return Birthday information as a String
*/
@Override
public String toString()
{
return date + " - " + name;
}
}

Solutions

Expert Solution

As only BirthdayList class was changed so posting that class only

import java.util.ArrayList;
import java.util.Collections;

public class BirthdayList {
        /**
         * This is the main process for class BirthdayList
         */
        public static void main(String args[]) {
                System.out.println("\n\tBegin Birthday List Program\n");

                System.out.println("Declare an ArrayList for Birthday objects");
                // 1. TO DO: Declare an ArrayList to store Birthday objects (3 Pts)
                ArrayList<Birthday> bdayList = new ArrayList<>();

                // 2. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts)
                System.out.printf("\nBirthday List is empty: %s\n", bdayList.isEmpty() ? "True"
                                : "False");

                System.out.println("Add at least five Birthdays to the list");
                // 3. TO DO: Add five or more Birthday objects to the Birthday list (5
                // Pts)
                // Format is: xxxxx.add(new Birthday("mm/dd","name")):
                bdayList.add(new Birthday("03/26", "Sam"));
                bdayList.add(new Birthday("07/01", "Nitya"));
                bdayList.add(new Birthday("06/15", "Meena"));
                bdayList.add(new Birthday("12/25", "Neeraj"));
                bdayList.add(new Birthday("07/13", "Lipsy"));
                bdayList.add(new Birthday("11/17", "Manisha"));

                System.out.printf("Birthday List is empty: %s\n",
                                bdayList.isEmpty() ? "True" : "False");

                // 4. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts)
                System.out.printf("Birthday list has %d entries\n", bdayList.size());

                System.out.println("\nDisplay unsorted Birthday list");
                listBirthdays(bdayList);

                System.out.println("\nDisplay 3rd Birthday in the listlist");
                // 5. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts)
                System.out.printf("%s\n", bdayList.get(2));

                // 6. TO DO: Remove a Birthday object from the list by index;
                // Replace the xxx.xxxx() with the appropriate method (2 Pts)
                System.out.printf("%s was removed from the list\n", bdayList.remove(1));
                System.out.printf("Birthday list has %d entries\n", bdayList.size());

                // 7. TO DO: declare a new Birthday object to replace one in the list (1
                // Pts)
                Birthday newObj = new Birthday("09/04", "Sushant");

                // 8. TO DO: Replace (set) an element in the ArrayList with the new
                // Birthday
                // object and complete the System.out.printf statement to display the
                // original
                // Birthday object and the new (replacement) Birthday object (5 Pts)
                Birthday oldObj = bdayList.set(4, newObj);
                System.out.printf("\nChange %s to %s\n", oldObj, bdayList.get(4));

                System.out
                                .println("\nCopy original Birthday list to new Birthday list");
                // 9. TO DO: Copy the original ArrayList to a new one called newList (3
                // Pts)
                ArrayList<Birthday> newList = new ArrayList<>(bdayList);
                System.out.println("\nSort new Birthday list");
                // 10. TO DO: sort the new ArrayList (2 Pts)
                Collections.sort(newList);
                System.out.println("\nDisplay new sorted Birthday list");
                listBirthdays(newList);

                System.out.println("\n\tEnd Birthday List Program\n");
        }

        /**
         * This function lists all the Birthdays in the list
         * 
         * @param list
         *            - reference to the Birthday ArrayList
         */
        public static void listBirthdays(ArrayList<Birthday> list) {
                int number = 1;
                for (Birthday bDay : list)
                        System.out.printf("%3d - %s\n", number++, bDay.toString());
        }
}

Output


   Begin Birthday List Program

Declare an ArrayList for Birthday objects

Birthday List is empty: True
Add at least five Birthdays to the list
Birthday List is empty: False
Birthday list has 6 entries

Display unsorted Birthday list
1 - 03/26 - Sam
2 - 07/01 - Nitya
3 - 06/15 - Meena
4 - 12/25 - Neeraj
5 - 07/13 - Lipsy
6 - 11/17 - Manisha

Display 3rd Birthday in the listlist
06/15 - Meena
07/01 - Nitya was removed from the list
Birthday list has 5 entries

Change 11/17 - Manisha to 09/04 - Sushant

Copy original Birthday list to new Birthday list

Sort new Birthday list

Display new sorted Birthday list
1 - 03/26 - Sam
2 - 06/15 - Meena
3 - 07/13 - Lipsy
4 - 09/04 - Sushant
5 - 12/25 - Neeraj

   End Birthday List Program


Related Solutions

import java.util.ArrayList; import java.util.Collections; import java.lang.Exception; public class ItemList { /** This is the main process...
import java.util.ArrayList; import java.util.Collections; import java.lang.Exception; public class ItemList { /** This is the main process for the project */ public static void main () { System.out.println("\n\tBegin Item List Demo\n"); System.out.println("Declare an ArrayList to hold Item objects"); ArrayList<Item> list = new ArrayList<Item>(); try { System.out.println("\n Add several Items to the list"); list.add(new Item(123, "Statue")); list.add(new Item(332, "Painting")); list.add(new Item(241, "Figurine")); list.add(new Item(126, "Chair")); list.add(new Item(411, "Model")); list.add(new Item(55, "Watch")); System.out.println("\nDisplay original Items list:"); listItems(list); int result = -1; // 1....
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public...
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public static void main(String[] args)    {        max_cards=45;        arr->new ArraryList        col=1;        card=0;        left=max_cards;        do{            col->random number            row->new ArrayList;            for i=0 to i<col            {                card++                add card into row            }   ...
import java.util.LinkedList; import java.util.ListIterator; public class ProjectList { /** This is the main function for the...
import java.util.LinkedList; import java.util.ListIterator; public class ProjectList { /** This is the main function for the program */ public static void main() { System.out.println("\n\tBegin ProjectList demo program");    // 1. TO DO: Describe your project (1 Pt) System.out.println("Project: . . . . . . \n"); System.out.println("Create a LinkedList to store the tasks"); // 2. TO DO: Declare a LinkedList of String objects called "tasks" (1 Pt)       System.out.println("Add initial tasks into the list"); // 3. TO DO: Add initial...
import java.util.LinkedList; import java.util.Queue; import java.time.*; public class CheckOutLine { /** This is the main function...
import java.util.LinkedList; import java.util.Queue; import java.time.*; public class CheckOutLine { /** This is the main function for the program */ public static void main() { System.out.println("\n\tBegin CheckOutLine Demo\n"); System.out.println("\nCreating a Queue called \"register\" based on a LinkedList"); Queue<Customer> register = new LinkedList<Customer>();    System.out.println("\nAdding Customers to the Register queue"); // 1. TO DO: add five or more customers to the register line (5 Pts) // format: register.add(new Customer(name, checkout time));                System.out.printf("Register line has %d customers\n",...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        } System.out.println(""+getAvg(new_stack));    }     public static int getAvg(Stack s) {        //TODO: Find the average of the elements in the...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
import java.lang.UnsupportedOperationException; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc...
import java.lang.UnsupportedOperationException; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in);    // parse the number of strings int numStrings = Integer.parseInt(sc.nextLine());    // parse each string String[] stringsArray = new String[numStrings]; for (int i = 0; i < numStrings; i++) { stringsArray[i] = sc.nextLine(); }    // print whether there are duplicates System.out.println(hasDuplicates(stringsArray)); }    private static boolean hasDuplicates(String[] stringsArray) { // TODO fill this in and remove the below line...
This is the class that needs to be written... import java.util.ArrayList; /** * Deals out a...
This is the class that needs to be written... import java.util.ArrayList; /** * Deals out a game of 5-card-stud. * * @author PUT YOUR NAME HERE * @version PUT THE DATE HERE */ public class FiveCardStud { private Deck myDeck; private ArrayList<Hand> players; /** * Constructor for objects of class FiveCardStud */ /* Write a constructor for the FiveCardStud class. The constructor accepts a single integer parameter for the number of players. The number of players should be from 2...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's cart. Items of Type T can be added * or removed from the cart. A hashmap is used to keep track of the number of items * that have been added to the cart example 2 apples or 4 shirts. * @author Your friendly CS Profs * @param -Type of items that will be placed in the Cart. */ public abstract class AbstractCart {...
import java.util.ArrayList; public class Workouts { public enum Muscle {ABS, BACK, BICEPS, CHEST, FOREARM, GLUTES, LOWERLEG,...
import java.util.ArrayList; public class Workouts { public enum Muscle {ABS, BACK, BICEPS, CHEST, FOREARM, GLUTES, LOWERLEG, SHOULDER, TRICEPS, UPPERLEG, NONE} // Why didn't I have to declare this static? public enum Equipment {BARBELL, BODYWEIGHT, DUMBBELL, CABLE, HAMMERSTRENGTH}    private final ArrayList<Workout> workoutList = new ArrayList<Workout>();    // You will need to create a number of methods for the inner class. You are not limited to    // only the methods listed inside this class.    private class Workout {   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT