Question: Need help on the ArrayFrog class to get it to pass the tests in the tester! (DO NOT USE try-catch or parse methods, please follow

Need help on the ArrayFrog class to get it to pass the tests in the tester!

(DO NOT USE try-catch or parse methods, please follow the directions in the comments) Thank you

(I posted the question before and got random answer, please respond to this question only if you know how to do this please)!!!!

ArrayFrog class:

// Step 1: Import class Arrays import java.util.Arrays; public class ArrayFrog { // Step 2: Declare two instance variables to // manage a partial array of Frog. // Step 3: Complete the first constructor /** * Constructs an ArrayFrog object with an array of * Frog and the number of frogs in the array. * * @param array the array of class Frog to be managed * @param count the number of frogs in the array */ public ArrayFrog(Frog[] array, int count) { }

// Step 4: Complete the second constructor /** * Constructs an ArrayFrog object by creating an * empty array of Frog and setting the number of * frogs to zero. * * @param length the length of the array */ public ArrayFrog(int length) {

}

// Step 5: Complete the first add() method /** * Adds a frog at the end of the array if the array * is not full and does nothing otherwise. * * @param frog the frog to be added */ public void add(Frog frog) { if(currentSize < frogArray.length) { frogArray[currentSize] = frog; currentSize++; } } // Step 6: Complete the second add() method /** * Inserts the specified frog at the specified index * position in the array and shifts the element currently * at that position and any subsequent elements (if any) * to the right (adds one to their indices) if the array * is not full and the index is valid. * The method does nothing otherwise. * * @param index the position to insert the frog * @param frog the frog to insert */ public void add(int index, Frog frog) {

} // Step 7: Complete method delete() /** * Deletes and returns the frog at the specified position * if the specified index is valid. It also shifts the * element at the position and all subsequent elements * (if any) to the left to maintain the element order. * The method does nothing otherwise. * * @param index the index of the frog to be deleted * from the array * @return the frog deleted from the array if index is valid * null otherwise */ public Frog delete(int index) { } // Step 8: Complete method toString() /** * Gets a string representation for the array. * * No if statements inside the loop. * * @return a String containing all frogs in the array * in the format * [Frog[...], Frog[...], ..., Frog[...]] * where each Frog[...] is the string returned * from method toString on a frog in the array */ @Override public String toString() { }

// Step 9: Complete method sort() /** * Calls a static method to sort the array. */ public void sort() { } }

ArrayFrogTester class: public class ArrayFrogTester { public static void main(String[] args) { Frog[] arrayOne = new Frog[5]; int count = 3; arrayOne[0] = new Frog("12345", 15.5); arrayOne[1] = new Frog("66666", 20.0); arrayOne[2] = new Frog("55555", 16.6); ArrayFrog managedArrayOne = new ArrayFrog(arrayOne, count); ArrayFrog managedArrayTwo = new ArrayFrog(5); // Testing method toString() System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=12345,Weight=15.5,Legs=2], " + "Frog[ID=66666,Weight=20.0,Legs=2], Frog[ID=55555,Weight=16.6,Legs=2]]"); System.out.println(managedArrayTwo.toString()); System.out.println("Expected: []"); // Testing method sort() managedArrayOne.sort(); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=12345,Weight=15.5,Legs=2], " + "Frog[ID=55555,Weight=16.6,Legs=2], Frog[ID=66666,Weight=20.0,Legs=2]]"); managedArrayTwo.sort(); System.out.println(managedArrayTwo.toString()); System.out.println("Expected: []"); // Testing method add() managedArrayOne.add(new Frog("88888", 15.5)); managedArrayOne.add(new Frog("44444", 16.6)); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=12345,Weight=15.5,Legs=2], " + "Frog[ID=55555,Weight=16.6,Legs=2], Frog[ID=66666,Weight=20.0,Legs=2], " + "Frog[ID=88888,Weight=15.5,Legs=2], Frog[ID=44444,Weight=16.6,Legs=2]]"); managedArrayTwo.add(new Frog("99999", 4.5)); System.out.println(managedArrayTwo.toString()); System.out.println("Expected: [Frog[ID=99999,Weight=4.5,Legs=0]]");

// Testing method sort() managedArrayOne.sort(); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=12345,Weight=15.5,Legs=2], " + "Frog[ID=88888,Weight=15.5,Legs=2], Frog[ID=44444,Weight=16.6,Legs=2], " + "Frog[ID=55555,Weight=16.6,Legs=2], Frog[ID=66666,Weight=20.0,Legs=2]]"); // Testing invalid adding managedArrayOne.add(new Frog("99999", 14.4)); managedArrayOne.add(new Frog("00000", 14.4)); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=12345,Weight=15.5,Legs=2], " + "Frog[ID=88888,Weight=15.5,Legs=2], Frog[ID=44444,Weight=16.6,Legs=2], " + "Frog[ID=55555,Weight=16.6,Legs=2], Frog[ID=66666,Weight=20.0,Legs=2]]");

// Testing valid deleting Frog frog = managedArrayOne.delete(4); System.out.println(frog); System.out.println("Expected: Frog[ID=66666,Weight=20.0,Legs=2]"); frog = managedArrayOne.delete(0); System.out.println(frog); System.out.println("Expected: Frog[ID=12345,Weight=15.5,Legs=2]"); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=88888,Weight=15.5,Legs=2], " + "Frog[ID=44444,Weight=16.6,Legs=2], Frog[ID=55555,Weight=16.6,Legs=2]]"); // Testing invalid deleting frog = managedArrayOne.delete(3); System.out.println(frog); System.out.println("Expected: null"); frog = managedArrayOne.delete(-1); System.out.println(frog); System.out.println("Expected: null"); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=88888,Weight=15.5,Legs=2], " + "Frog[ID=44444,Weight=16.6,Legs=2], Frog[ID=55555,Weight=16.6,Legs=2]]"); // Testing the second add() method with invalid index managedArrayOne.add(-1, new Frog("99999", 14.4)); managedArrayOne.add(4, new Frog("66666", 20.4)); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=88888,Weight=15.5,Legs=2], " + "Frog[ID=44444,Weight=16.6,Legs=2], Frog[ID=55555,Weight=16.6,Legs=2]]"); // Testing the second add() method with valid index managedArrayOne.add(0, new Frog("99999", 14.4)); managedArrayOne.add(4, new Frog("66666", 20.4)); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=99999,Weight=14.4,Legs=2], " + "Frog[ID=88888,Weight=15.5,Legs=2], Frog[ID=44444,Weight=16.6,Legs=2], " + "Frog[ID=55555,Weight=16.6,Legs=2], Frog[ID=66666,Weight=20.4,Legs=4]]"); // Testing the second add() method when the array is full managedArrayOne.add(0, new Frog("abcde", 14.4)); System.out.println(managedArrayOne.toString()); System.out.println("Expected: [Frog[ID=99999,Weight=14.4,Legs=2], " + "Frog[ID=88888,Weight=15.5,Legs=2], Frog[ID=44444,Weight=16.6,Legs=2], " + "Frog[ID=55555,Weight=16.6,Legs=2], Frog[ID=66666,Weight=20.4,Legs=4]]"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!