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) {       ...
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 {   ...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) {...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,1,2}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: " + WordsCharsLetters[1]); System.out.println("Letters: " + WordsCharsLetters[2]); } static int[] calculateAndPrintChars(String sentence) { int[] WCL = new int[3]; String[] sentenceArray=sentence.split(" "); WCL[0] = sentenceArray.length; int letterCount=0; for(int i=0;i<sentence.length();i++) { if(Character.isLetter(sentence.charAt(i))) letterCount++; } WCL[1]...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT