Answer to Question #256382 in Java | JSP | JSF for Ntokozo

Question #256382

Create a method cled checkUniform() tgat returns true or false and checks if the filled bottles in the watersort game are identical or not


1
Expert's answer
2021-10-25T16:55:11-0400


SOLUTION FOR THE ABOVE QUESTION


//For easy undestanding, we will define our function checkUniform() inside a class
class MyArrayList<E> {
    // Number of elements in the list
    private int size; 
    private E[] data;
    private int maximum_elements = 10;


     // Create an empty list
    public MyArrayList() {
        data = (E[]) new Object[maximum_elements];
        // Number of elements in the list
        size = 0;
    }
    //Our intended or target function checkUniform() that checks if the 
    // filled bottles in the watersort game are identical or not
    public boolean checkUniform() {
        if (size == 0) {
            return true;
        }

        E temp = this.data[0];

        for (int i = 1; i < size; i++) {
            if (!temp.equals(data[i])) {
                return false;
            }
        }

        return true;

    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS