Question

In: Computer Science

Implement a class named Parade using an ArrayList, which will manage instances of class Clown. Each...

  1. Implement a class named Parade using an ArrayList, which will manage instances of class Clown. Each Clown only needs to be identified by a String for her/his name. Always join a new Clown to the end of the Parade. Only the Clown at the head of the Parade (the first one) can leave the Parade. Create a test application to demonstrate building a parade of 3 or 4 clowns (include your own name), then removing 1 or 2, then adding another 1 or 2.

Solutions

Expert Solution

Thanks for the question.

Here is the completed code for this problem. Comments are included so that you understand whats going on. Let me know if you have any doubts or if you need anything to change.

Thank You !!

Note: Please add your name in the placeholder given in the main class

and please do up Vote : )

===================================================================================================

public class Clown {

    private String clownName;

    public Clown(String clownName) {
        this.clownName = clownName;
    }

    public String getClownName() {
        return clownName;
    }

    @Override
    public String toString() {
        return "Clown: " + getClownName();
    }
}

======================================================================================

import java.util.ArrayList;

public class Parade {

    private ArrayList<Clown> clowns;

      public Parade() {

        this.clowns = new ArrayList<Clown>();
    }
    
    
    // add clown at the end

    public void addClown(Clown clown){
          clowns.add(clown);
        System.out.println(clown+" added.");
    }



    
    public void removeClown(){

        // remove the clown at index 0 always if there is at least one clown
        if(clowns.size()!=0){
            Clown  c = clowns.get(0);
            clowns.remove(0);
            System.out.println(c+" removed.");
        }else{
            System.out.println("There are no clowns.");
        }
    }
}

======================================================================================

public class Boulevard {


    public static void main(String[] args) {


        Parade march = new Parade();

        // add 4 clowns
        march.addClown(new Clown("Zeus"));
        march.addClown(new Clown("Othello"));
        march.addClown(new Clown("<My Name>"));
        march.addClown(new Clown("Dino"));

        // remove the first two that is Zeus and Othello
        march.removeClown();
        march.removeClown();

        // add two more
        march.addClown(new Clown("Frankestine"));
        march.addClown(new Clown("Macbeth"));

        // remove all clowns
        march.removeClown();
        march.removeClown();
        march.removeClown();
        march.removeClown();
        march.removeClown();


    }
}

======================================================================================


Related Solutions

class Company uses an ArrayList of class Employee to manage its employees. Your job is to...
class Company uses an ArrayList of class Employee to manage its employees. Your job is to create two classes , Company and Employee, with appropriate instance fields, constructors, and methods as been described in the set of questions that follows . A sample use case of the classes is shown below: public class CompanyTester{ public static void main(String[] args){ Company myCompany = new Company(); myCompany.add( new Employee("james","gasling")); myCompany.add( new Employee("bill","gate")); myCompany.add( new Employee("dennis","ritchie")); System.out.println(myCompany); } } The sample output of...
You shall implement six static methods in a class named BasicBioinformatics. Each of the methods will...
You shall implement six static methods in a class named BasicBioinformatics. Each of the methods will perform some analysis of data considered to be DNA. DNA shall be represented arrays of chars containing only the characters A, C, G and T. In addition to the six methods you will implement, six other methods exist in the class, which use Strings instead of char arrays to represent DNA. These other methods simply invoke the methods you are to implement, so all...
Problem Statement: Implement the MyString class using a header and implementation file named MyString.h and MyString.cpp...
Problem Statement: Implement the MyString class using a header and implementation file named MyString.h and MyString.cpp respectively. Make sure to properly test your code on your own by creating a test driver that tests every function created in the MyString class. Deliverables: proj3-MyString.h proj3-MyString.cpp proj3-testMain.cpp Memory Requirements: Your MyString should start with 10 bytes of allocated memory and should grow in size by doubling. So, we should be able to predict the capacity of your MyString as acquiring a patten...
Implement a class named stack pair that provides a pair of stacks. Make the class a...
Implement a class named stack pair that provides a pair of stacks. Make the class a template class. So, you will have two files: stack pair.h and stack pair.template, following the style of the text. The basic idea is that two stacks can share a single static array. This may be advantageous if only one of the stacks will be in heavy use at any one time. • The class should have various methods to manipulate the stack: T pop...
1.Implement the generic PriorityQueueInterface in a class named PriorityQueue. Note: it must be named PriorityQueue The...
1.Implement the generic PriorityQueueInterface in a class named PriorityQueue. Note: it must be named PriorityQueue The priority queue MUST be implemented using a linked list. 2 test program checks that a newly constructed priority queue is empty o checks that a queue with one item in it is not empty o checks that items are correctly entered that would go at the front of the queue o checks that items are correctly entered that would go at the end of...
#data structure 1.Implement the generic PriorityQueueInterface in a class named PriorityQueue. Note: it must be named...
#data structure 1.Implement the generic PriorityQueueInterface in a class named PriorityQueue. Note: it must be named PriorityQueue The priority queue MUST be implemented using a linked list. 2 test program checks that a newly constructed priority queue is empty o checks that a queue with one item in it is not empty o checks that items are correctly entered that would go at the front of the queue o checks that items are correctly entered that would go at the...
You shall implement a class named DnaSequence, which models a sequence of DNA. Requirements: You must...
You shall implement a class named DnaSequence, which models a sequence of DNA. Requirements: You must implement all public constructors and methods described in this documentation. Your class must have only 1 field, and it must be a private char[]. No print statements are allowed anywhere in your class. The constructors require you to discard any character that is not 'A', 'C', 'G', or 'T'. This is very easily accomplished using a regular expression in String.replaceAll: // returns a String...
Implement a Binary tree using an array using class.
Implement a Binary tree using an array using class.
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement the compareTo method to compare the triangles on the basis of similarity. Draw the UML diagram for your classes. Write a Driver class (class which instantiates the comparableTriangle objects) to determine if two instances of ComparableTriangle objects are similar (sample output below). It should prompt the user to enter the 3 sides of each triangle and then display whether or not the are similar...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title,...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title, an author, and a publisher. Create appropriate constructor(s) and accessor and mutator methods for the Book class. Add a static variable to the Book class and set its initial value to 100000000. When a new book is created, this static variable is automatically incremented by 1 and the new value is assigned as the serial number of the new book. Design and implement a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT