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...
Create a class named Employee and its child class named Salesperson. Save each class in its...
Create a class named Employee and its child class named Salesperson. Save each class in its own file. Name your class and source code file containing the main method homework.java. Make sure each class follows these specifications: 1. An employee has a name (String), employee id number (integer), hourly pay rate (double), a timesheet which holds the hours worked for the current week (double array) and email address (String). A salesperson also has a commission rate, which is a percentage...
JAVA Implement a public class method named comparison on a public class Compare that accepts two...
JAVA Implement a public class method named comparison on a public class Compare that accepts two Object arguments. It should return 0 if both references are equal. 1 if both objects are equal. and -1 otherwise. (SUPER IMPORTANT) Either reference can be null, so you'll need to handle those cases carefully! Here is what I have so far: public class Compare { public static int comparison(Object a, Object b) {   if (a == null || b == null) {    return...
Implement a Binary tree using an array using class.
Implement a Binary tree using an array using class.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT