Create a method cled checkUniform() tgat returns true or false and checks if the filled bottles in the watersort game are identical or not
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;
}
}
Comments
Leave a comment