Question: one of the array is size 3 the second one is size 2 and 1 first one is size 1 it creates array of size
one of the array is size 3 the second one is size 2 and 1 first one is size 1 it creates array of size 3 only not 1 and 2 or zero
how to create array of different sizes
I have edited my code it passes all the test but can't pass this section can you please help ASAP it is not updating the second and first list and the length 0
assertTrue(list2.length == 2 && list2[0] == mark && list2[1] == tom); assertTrue(list3.length == 1 && list3[0] == tom); /* non-existing course */ assertTrue(school.getParticipants("How to Make Fish and Chips").length == 0);
Please help with a java code ASAP please finish this ASAP please
this is the class
package model;
public class OnlineSchool { Participant [] participant; // this one should be of length 0 int size = 0; Participant[] newArray = new Participant[5];
int i = 0;
public Participant[] getParticipants(String name) { this.participant = new Participant[size]; // this determine that the size of array is 0 for(int findingLength = 0; findingLength < size; findingLength++) { participant[findingLength] = newArray[findingLength]; } return participant; }
public void addParticipant(Participant alan) { if(size < 5) { newArray[i] = alan; size++; i++; participant = new Participant[size]; // this updates it with the new participant i guess } }
}
@Test public void test_04() { OnlineSchool school = new OnlineSchool(); /* courses not existing (yet) */ Participant[] list1 = school.getParticipants("Intro. to OOP"); Participant[] list2 = school.getParticipants("Heavy Metal Music"); Participant[] list3 = school.getParticipants("Chamber Music"); assertTrue(list1.length == 0 && list2.length == 0 && list3.length == 0); Participant alan = new Participant("A. Wassyng"); Participant mark = new Participant("M. Lawford"); Participant tom = new Participant("T. Maibaum"); school.addParticipant(alan); school.addParticipant(mark); school.addParticipant(tom); tom.addRegistration("Heavy Metal Music"); tom.addRegistration("Chamber Music"); tom.addRegistration("Intro. to OOP"); alan.addRegistration("Intro. to OOP"); mark.addRegistration("Heavy Metal Music"); mark.addRegistration("Intro. to OOP"); /* Order in which participants appear in the returned array of `getParticipants` should be * the same as how they appear in the school's list of participants (e.g., alan, mark, tom). */ list1 = school.getParticipants("Intro. to OOP"); list2 = school.getParticipants("Heavy Metal Music"); list3 = school.getParticipants("Chamber Music"); assertTrue(list1.length == 3 && list1[0] == alan && list1[1] == mark && list1[2] == tom); assertTrue(list2.length == 2 && list2[0] == mark && list2[1] == tom); assertTrue(list3.length == 1 && list3[0] == tom); /* non-existing course */ assertTrue(school.getParticipants("How to Make Fish and Chips").length == 0); } /* You may want to write a test similar to test03b: * an online school can be added up to 100 participants. */ }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
