I want to search ExArrayList
for a specific gpa? I want an answer of true or false if it exists in ArrayList.
public class ExArrayList {
private String Name;
private double GPA;
public ExArrayList(String name, double gpa) {
this.Name = name;
this.GPA = gpa;
}
public void setGPA(double gpa) {
this.GPA = gpa;
}
public double getGPA() {
return GPA;
}
public void setName(String name) {
this.Name = name;
}
public String getName() {
return Name;
}
@Override
public String toString() {
return String.format("%s\t%f", this.Name, this.GPA);
}
}
public class Main {
public static void main(String[] args) {
ArrayList<ExArrayList> psy101 = new ArrayList<>();
psy101.add(new ExArrayList("Bob", 2.9 ));
psy101.add(new ExArrayList("Steve", 3.9 ));
psy101.add(new ExArrayList("Charles", 4.0 ));
System.out.println();
System.out.printf("Student\tGPA\n");
for(ExArrayList s : psy101) {
System.out.printf("%s\n", s);
}
boolean binFound = psy101.contains(2.9); // This is what I am using to search the ArrayList. It's not working.
System.out.println("Does the list contain GPA of 2.9? " + binFound);`