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...
Define and implement a class named Coach, which represents a special kind of person. It is...
Define and implement a class named Coach, which represents a special kind of person. It is to be defined by inheriting from the Person class. The Coach class has the following constructor: Coach(string n, int sl) // creates a person with name n, whose occupation // is “coach” and service length is sl The class must have a private static attribute static int nextID ; which is the unique personID of the next Coach object to be created. This is...
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...
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist...
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist to store/ add product in stock 3. Product must have name, code number and quantity in stock 4. Print list of the products and their stock quantity 5. Search products based on their name 6. Remove product based on their code number 7. Sell product and deduct quantity from stock 8. Stock Class contains methods of search product, add product and check quantity of...
In Lecture 8(ArrayList, Generics) , we discussed about creating a MyStack<E> class using the ArrayList<E> class...
In Lecture 8(ArrayList, Generics) , we discussed about creating a MyStack<E> class using the ArrayList<E> class that has the stack methods ( isEmpty(), getSize(), peek(), pop(), push(Object o), and toString( ) ) as shown in the following: public class MyStack<E> { private ArrayList<E> list = new ArrayList<>(); public int getSize() {     return list.size(); } public E peek() {     return list.get(getSize() - 1); } public void push(E o) {     list.add(o); } public E pop() {     E o = list.get(getSize()...
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist...
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist to store/ add product in stock 3. Product must have name, code number and quantity in stock 4. Print list of the products and their stock quantity 5. Search products based on their name 6. Remove product based on their code number 7. Sell product and deduct quantity from stock 8. Stock Class contains methods of search product, add product and check quantity of...
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...
in java Design and implement a class named Person and its two subclasses named Student and...
in java Design and implement a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name,address, phone number, and email address. A student has a class status (year 1,year 2,year 3,or year 4). An employee has an office, salary, and date hired. Use the Date class from JavaAPI 8 to create an object for date hired. A faculty member has office hours and a rank. A staff...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT