Okay, so what I'm trying to do is go through the ArrayList called theDateArray, do a search for a particular item in that list, and output how many times that item appears. When I test it in the main class, it just outputs the number 0 no matter what date as a String I enter in. Here is part of the class which the methods are in. I don't think as of now it's necessary to include the entire class unless it is confusing...
public ArrayList<String> getTicketDates(){
int i;
for (i=0; i <tickets.size(); i++){
if(tickets .get(i).getPurchased()== false){
theDateArray.add(tickets.get(i).getDate());
}
}
for(int f=0; f<theDateArray.size();f++){
System.out.println(theDateArray.get(f)+ " ");
}
return theDateArray;
}
public int getTickets(String date){
int tix= theDateArray.indexOf(date);
int occurrences= Collections.frequency(theDateArray, tix);
if (tix>=0){
System.out.println(occurrences);
}
return occurrences;
}
Here is the made up tickets that I'm testing in my test class....
public class AmusementParkTester {
public static void main(String[] args) {
AmusementPark park1= new AmusementPark("Walden University Park");
park1.addTicket(777, "Child", "Noah Johnson","2017-06-09" , 27.99, false);
park1.addTicket(777, "Child", "Zachary Gibson","2017-06-09" , 27.99, false);
System.out.println("The dates in which tickets are available are as follows: ");
park1.getTicketDates();
park1.getTickets("2017-06-09");
}
}
Here is the output I'm getting....
The dates in which tickets are available are as follows:
2017-06-09
2017-06-09
0
I want the 0 to be a 2.