This method takes an arraylist of objects, each with three parameters, and is supposed to return true or false depending on if the parameters of any two objects in the array add up to 11.
private boolean containsPairSum11(List<Integer> selectedCards) {
int g = 0;
for(int i = 0; i < selectedCards.size(); i++){
for(int h = 0; h < selectedCards.size(); h++){
if(Integer.valueOf(selectedCards.get(i)).rank() + Integer.valueOf(selectedCards.get(h)).rank() == 11){
g++;
}
}
}
if(g <= 0){
return false;
}
else{
return true;
}
}
method I want to call:
public class Card{
public Card(String cardRank, String cardSuit, int cardPointValue) {
//initializes a new Card with the given rank, suit, and point value
rank = cardRank;
suit = cardSuit;
pointValue = cardPointValue;
}
public String rank() {
return rank;
}`
the error this throws:
./ElevensBoard.java:80: error: cannot find symbol
if(Integer.valueOf(selectedCards.get(i)).rank() + Integer.valueOf(selectedCards.get(h)).rank() == 11){
^
symbol: method rank()
location: class Integer
I tried creating a new instance of the Card class in the ElevensBoard class so I could call the method like this:
Card c = new Card();
public void callMethod(){
c.rank();
}
But this did not work either and threw these errors:
./ElevensBoard.java:74: error: constructor Card in class Card cannot be applied to given types;
Card c = new Card();
^
required: String,String,int
found: no arguments
reason: actual and formal argument lists differ in length
./ElevensBoard.java:84: error: cannot find symbol
if(Integer.valueOf(selectedCards.get(i)).c.rank() + Integer.valueOf(selectedCards.get(h)).rank() == 11){
^
symbol: variable c
location: class Integer
Christian McClintock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.