when i try to remove element there is an error, i have uploaded the error in the image section. any help to fix? of any other way to get the code fixed and working smoothly and it it works while deleting the middle element not the first or second duplication issue ,fixed using iterator. hatsooff to stack overflow . all good
import java.util.*;
public class EarthquakeList {
private ArrayList<EarthquakeNode> records;
public EarthquakeList() {
records = new ArrayList<EarthquakeNode>();
}
public boolean isempty() {
return true;
}
public void add(String EarthquakeLo,String EarthquakeDt, double EarthquakeSgth, int EarthquakeDu) {
EarthquakeNode en = new EarthquakeNode(EarthquakeLo, EarthquakeDt, EarthquakeSgth, EarthquakeDu);
records.add(en);
}
public boolean remove(String EarthquakeLo,String EarthquakeDt) {
boolean flag= false;
for(EarthquakeNode earthquake: records)
{
if(earthquake.getLocation().equalsIgnoreCase(EarthquakeLo))
{
if(earthquake.getDate().equals(EarthquakeDt))
{
records.remove(earthquake);
flag=true;
}
}
}
return flag;
}
public EarthquakeNode search(String EarthquakeLo,String EarthquakeDt) {
EarthquakeNode node= null;
for(EarthquakeNode earthquake: records)
{
if(earthquake.getLocation().equalsIgnoreCase(EarthquakeLo))
{
if(earthquake.getDate().equals(EarthquakeDt))
{
node=earthquake;
}
}
}
return node;
}
public boolean clear() {
int count=records.size();
for(EarthquakeNode earthquake: records)
{
count=count-1;
records.remove(earthquake);
}
if(count==0)
{
System.out.println("already empty");
return false;}
else
System.out.println("every thing is removed");
return true;
}
public boolean isempty(String EarthquakeLo,String EarthquakeDt) {
boolean flag= false;
for(EarthquakeNode earthquake: records)
{
if(earthquake.getLocation().equalsIgnoreCase(EarthquakeLo))
{
if(earthquake.getDate().equals(EarthquakeDt))
{
flag=true;
}
}
}
return flag;
}
public void print() {
for(EarthquakeNode earthquake: records)
{
System.out.println( earthquake.getLocation() +" - "
+ earthquake.getDate()+ " - "
+ earthquake.getStrength() + " on rector scale"+
"-" + earthquake.getDuration() + "mins");
}
}
}