First, create a new class named

It should have a (static) main method.

Create two fields (non-static) of type int and String named count and name. Set Protected.
Create a constructor for this class that takes as parameters an int and String then saves those values to fields you made in the last step.

Write a simple method named "output" that returns nothing, has no parameters, and prints out the name count times (using a loop). For example, if count is 5 and name is "Bob", "Bob" is printed out (one per line) five times to System.out. Hint: This is NOT a static method.

Create a getter and setter method for the count. Write an if-statement as part of the setter to not set the count to the parameter value if the parameter value is less than 0.

In your main method, create an array of 10 Example objects and initialize each of them to any count and name you would like (you may create a random count or not, your choice) using a loop.
Last, call output on each element of the array of Example in a loop.

Now create a new class named ExampleTest that has a static main method. Besides this main method, you should have no other static methods or variables in ExampleTest. ExampleTest should have the following methods (with the field(s) you decide are needed):

A default constructor that creates and stores an empty array of type Example (so, data type Example[])_ with 10 slots.

A constructor that takes as parameter an array of Example and stores it.

A getter method for your array of Example.
An add method that takes as parameter an Example and stores it in the array. NOTE: If there is no space to store the parameter in the array, I highly suggest/require you have a private method to (a) create a new array that is larger than the current field's size, (b) copy over the old elements into the new array, and (c) set the field variable to point to this new array. This is done in any intro textbook in the array manipulation section. You can also use an array list in the class but still need to return arrays when asked!

A sort method that either selection or insertion sorts the array of Example (it should have no parameters or return type, otherwise you are thinking about this procedurally instead of OO!). For simplicity, one Example is larger than another if it has a higher value for its count. Regardless of which sort you decide to implement, here is an example: A field of Examples with counts 5,3,4,1,2,4 should change the array to have a field of Examples with counts 1,2,3,4,4,5 (where the two Example with count of 4 can be in any order).

In your main method, write test cases for all methods above in the ExampleTest class. The constructors and getter should require only a single test but think carefully about what cases the add and sort method can encounter. Recall the format given in intro for tests: initialize variable(s), call the method, and then output only if the test fails.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class ExampleTest {
    private Example [] examples;
    private int size;
    * A default constructor that creates and
    * stores an empty array of type Example (so
    * , data type Example[])_ with 10 slots.
    public ExampleTest() {
       examples = new Example[10];
       size = 0;

    * A constructor that takes as parameter an array of Example and stores it.
    * @param examples
    public ExampleTest(Example[] examples) {
       this.examples = examples;
       size = 0;
       for (int i = 0; i < examples.length; i++) {
            if (examples[i] == null) {
$18.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats