# The operator \> is undefined for the argument - HOW TO RESOLVE ERROR (OOP)

**URL:** <https://discourse.processing.org/t/the-operator-is-undefined-for-the-argument-how-to-resolve-error-oop/38705>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [September 11, 2022, 5:27am UTC](https://discourse.processing.org/t/the-operator-is-undefined-for-the-argument-how-to-resolve-error-oop/38705 "2022-09-11T05:27:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sosophia10](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@sosophia10](https://discourse.processing.org/u/sosophia10)\
**Post date:** [September 11, 2022, 5:27am UTC](https://discourse.processing.org/t/the-operator-is-undefined-for-the-argument-how-to-resolve-error-oop/38705/1 "2022-09-11T05:27:23Z")

</div>

**Why is this error occuring and what can I do to solve it?**

> The operator \> is undefined for the argument type(s) int Main.Cards

is indicated where cardX, cardY, cardH, and cardW are being called in **mousePressed();**  
and it’s also indicated as

> The operator += is undefined for the argument type(s) int Main.Cards

where cardX and cardY are being called in **mouseDragged();**

_This is just snippets of the overall code:_

```auto
//Cards array
Cards[] card = new Cards[22];

//variables from Cards class
Cards cardX;
Cards cardY;
Cards cardH;
Cards cardW;
//is the mouse on the card
boolean mouseOnCard = false;

void mousePressed() {
  //check if mouse position is within bounds of card
  if (mouseX > cardX && mouseX < cardX + cardW && mouseY > card.y && mouseY < cardY + cardH) { 
    mouseOnCard = true;
  }
}

void mouseDragged() {
  //selected card follows when dragged
  if (mouseOnCard) {
    float deltaX = mouseX - pmouseX;
    float deltaY = mouseY - pmouseY;

    cardX += deltaX;
    cardY += deltaY;
  }
}

```

```auto
//Class in a separate file
class Cards {
  //card size
  public int cardW = 250 / 6;
  public int cardH = 350 / 6;

  //initial location of first card
  public float cardX = 0;
  public float cardY = 0;

  //card face
  int value = 0;

  public Cards(float x, float y, int v) {
    value = v;
    cardX = x;
    cardY= y;
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 12, 2022, 8:35pm UTC](https://discourse.processing.org/t/the-operator-is-undefined-for-the-argument-how-to-resolve-error-oop/38705/4 "2022-09-12T20:35:29Z")

</div>

Please read the text tutorial  
about objects

See [Objects / Processing.org](https://processing.org/tutorials/objects)

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 13, 2022, 12:32pm UTC](https://discourse.processing.org/t/the-operator-is-undefined-for-the-argument-how-to-resolve-error-oop/38705/5 "2022-09-13T12:32:05Z")

</div>

It is obvious that from your code you don’t understand the concept of classes and objects and this is too big a topic to be covered in a single answer. Before you go any further your should look at Processing tutorial on object orientation/classes/objects also the videos on the Coding Train youtube channel.

But to get you started here is a quick guide to your problem

```auto
Cards[] card = new Cards[22];

```

You have declared an array of 22 cards and I assume you have created them with the `new` statement in your setup function.

Each card has 5 attributes / fields as defined in your class

```auto
//card size
  public int cardW = 250 / 6;
  public int cardH = 350 / 6;

  //initial location of first card
  public float cardX = 0;
  public float cardY = 0;

```

Now in your mousePressed function I assume that you want to find out which card the mouse is over so we will declare a global integer variable which will hold the index position of the card we want.  
`int overCard = -1;`  
If the mouse is not over the card then `overCard` will be set to -1 which is an invalid array index.

```auto
void mousePressed() {
    overCard = -1; // assume mouse is not over a card
    // now check each card on turn and see if mouse position is within its bounds 
    for(int i = 0; i < card.length; i++){
        if (mouseX > card[i].cardX && mouseX < card[i].cardX + card[i].cardW && mouseY > card[i].cardY && mouseY < card[i].cardY + card[i].cardH) { 
            overCard = i;
            mouseOnCard = false;
            break; // Exit for loop since we havve found a card
        }
    }
    mouseOnCard = true;
}

```

Now delete the following lines because they make no sense at all.

```auto
//variables from Cards class
Cards cardX;
Cards cardY;
Cards cardH;
Cards cardW;

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 13, 2022, 3:56pm UTC](https://discourse.processing.org/t/the-operator-is-undefined-for-the-argument-how-to-resolve-error-oop/38705/6 "2022-09-13T15:56:31Z")

</div>

If you wish you can take a look at a very old deck of cards implementation I did a long time ago:

- [Picking cards at random, then excluding those from further picking. - Processing 2.x and 3.x Forum](https://forum.Processing.org/two/discussion/2801/picking-cards-at-random-then-excluding-those-from-further-picking-#Item_2)

It’s split into 2 sketches:  
1 creates & saves the “.csv” file, while the other loads it and makes a deck of cards out of it.

For convenience I’ve merged them now into 1 sketch w/ 4 “.pde” tabs:

## “Table\_CSV\_Card\_Pack.pde”:

```auto
/** 
 * Table CSV Card Pack (v1.0.1)
 * by GoToLoop (2022/Sep/13)
 *
 * https://discourse.Processing.org/t/
 * the-operator-is-undefined-for-the-argument-type-s-int-
 * how-to-resolve-error/38705/6
 *
 * https://forum.Processing.org/two/discussion/2801/
 * picking-cards-at-random-then-excluding-those-from-further-picking-#Item_2
 */

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

static final String ARCHIVE = "Cardpack.csv", EXT = ".jpg";
static final int NUM = 5, GAP = 040, FPS = 60, FILL = 0200;

final List<Card> myHand = new ArrayList<Card>(NUM);
Card[] cards;

void setup() {
  size(600, 900);
  frameRate(FPS);
  noLoop();

  fill(FILL);
  textSize(GAP);
  textAlign(CENTER);

  cards = loadCards(ARCHIVE, EXT, true, false);
  //cards = loadCards(ARCHIVE, EXT, true, true);

  showDeckContent(true, cards);
  println(ENTER);

  mousePressed();
}

void draw() {
  clear();

  for (int i = myHand.size(); i-- != 0; 
    myHand.get(i).displayAt(width >> 1, i*GAP + GAP));
}

void mousePressed() {
  final int btn = mouseButton;
  final int len = myHand.size();

  if (btn == RIGHT & len > 0) myHand.remove(len - 1);
  else if (btn == LEFT) pickCard();
  else PickNewRandomHand(NUM);

  println(myHand);
  println();

  redraw();
}

```

## “Card\_Class.pde”

```auto
class Card implements Comparable<Card> {
  short x, y;

  final byte w, h;
  final byte value, group;
  final int hash;

  final String rank, suit, info;
  final PImage img;

  Card(final int val, final String r, final String s, final PImage pic) {
    value = (byte) abs(val);
    rank = r;
    suit = s;
    img = pic;

    group = (byte) suit.charAt(0);
    hash = group<<020 | value;

    w = (byte) (img == null? 0 : img.width);
    h = (byte) (img == null? 0 : img.height);

    info = rank + " of " + suit;
  }

  Card setPos(final int xx, final int yy) {
    x = (short) xx;
    y = (short) yy;

    return this;
  }

  Card display() {
    return displayAt(x, y);
  }

  Card displayAt(final int x, final int y) {
    if (img != null) set(x, y, img);
    else text(info, x, y);

    return this;
  }

  String toString() {
    return info;
  }

  int hashCode() {
    return hash;
  }

  boolean equals(final Object o) {
    return o instanceof Card? ((Card) o).hash == hash : false;
  }

  int compareTo(final Card o) {
    return value != o.value? 
      Integer.signum(value - o.value) :
      Integer.signum(group - o.group);
  }
}

```

## “Card\_Functions.pde”:

```auto
Card[] loadCards(
  final String name, final String ext, 
  final boolean gotHeader, final boolean toLoadImages)
{
  final Table table;

  if (!dataFile(name).isFile()) table = createAndSaveTableFile(name);
  else {
    table = loadTable(name, gotHeader? "header" : "");
    table.setColumnType(0, Table.INT);
  }

  final Card[] deck = new Card[table.getRowCount()];

  for (int i = 0; i != deck.length; ++i) {
    final TableRow row = table.getRow(i);

    final int num = row.getInt(0);
    final String rank = row.getString(1), suit = row.getString(2);
    final PImage img = toLoadImages? loadImage(row.getString(3) + ext) : null;

    deck[i] = new Card(num, rank, suit, img);
  }

  return deck;
}

static final void showDeckContent(final boolean toSort, final Card... cards) {
  println();
  println(cards);
  println();

  if (toSort) {
    Arrays.sort(cards);
    println(cards);
    println();
  }

  for (final Card c : cards) {
    final int rank = c.hash & 0xFF;
    final char suit = (char) (c.hash >> 020);
    print(" - " + rank + suit);
  }
}

void pickCard() {
  if (myHand.size() >= cards.length) return;

  Card c;

  do c = cards[(int) random(cards.length)];
  while (myHand.contains(c));

  myHand.add(c);
  Collections.sort(myHand);
}

void PickNewRandomHand(int qty) {
  if ((qty = min(abs(qty), cards.length))
    == (cards.length | myHand.size())) return;

  myHand.clear();

  if (qty == cards.length) {
    myHand.addAll(Arrays.asList(cards));
    return;
  }

  while (qty != 0) {
    final Card c = cards[(int) random(cards.length)];

    if (!myHand.contains(c)) {
      myHand.add(c);
      --qty;
    }
  }

  Collections.sort(myHand);
}

```

## “Table\_CSV\_File\_Creation.pde”:

```auto
static final String[] RANKS = {
  "Ace", "Two", "Three", "Four", "Five", 
  "Six", "Seven", "Eight", "Nine", "Ten", 
  "Jack", "Queen", "King"
};

static final String[] SUITS = {
  "Clubs", "Diamonds", "Hearts", "Spades"
};

Table createAndSaveTableFile(final String filename) {
  final Table table = new Table();

  table.addColumn("Number", Table.INT);
  table.addColumn("Rank");
  table.addColumn("Suit");
  table.addColumn("Image");

  for (int r = 0, s = 0; s != SUITS.length; ++s, r = 0)
    while (r != RANKS.length) {
      final TableRow newRow = table.addRow();

      newRow.setString("Rank", RANKS[r]);
      newRow.setString("Suit", SUITS[s]);

      newRow.setInt("Number", ++r);

      newRow.setString("Image", str(r) + 
        Character.toLowerCase(SUITS[s].charAt(0)));
    }

  saveTable(table, dataPath(filename));
  return table;
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 13, 2022, 7:01pm UTC](https://discourse.processing.org/t/the-operator-is-undefined-for-the-argument-how-to-resolve-error-oop/38705/7 "2022-09-13T19:01:29Z")

</div>

here is my version,  
based on your code

```auto

//Cards array
Card[] cards = new Card[22];

//is the mouse on the card
boolean mouseOnCard = false;
int overCard=-1; 

// --------------------------------------------------------------------

void setup() {
  size(1400, 400);

  background(0); 
  for (int i=0; i<cards.length; i++) { 
    cards[i]=new Card( 30 + i * (250 / 6 + 7), 
      30, 
      i );
  }
}

void draw() {
  background(0); 
  for (Card currentCard : cards) {
    currentCard.display();
  }
}

// -------------------------------------------------------------------------------------------------------

void mousePressed() {
  overCard = -1; // assume mouse is not over a card

  // now check each card on turn and see if mouse position is within its bounds
  int i=0; 
  for (Card currentCard : cards) {
    if (currentCard.mouseInside()) {
      // start dragging 
      overCard = i;
      mouseOnCard = true;
      return; // Exit FUNC since we havve found a card
    }//if
    i++;
  }//for
  mouseOnCard = false;
}//func 

void mouseDragged() {
  //selected card follows when dragged

  if (overCard==-1) 
    return; // Exit FUNC 

  if (mouseOnCard) {
    float deltaX = mouseX - pmouseX;
    float deltaY = mouseY - pmouseY;

    cards[overCard].cardX += deltaX;
    cards[overCard].cardY += deltaY;
  }
}

void mouseReleased() {
  // end dragging
  overCard = -1; // release card 
  mouseOnCard = false;
}

///===================================================

//Class in a separate file
class Card {

  //card size
  int cardW = 250 / 6;
  int cardH = 350 / 6;

  //initial location of card
  float cardX = 0;
  float cardY = 0;

  //card face
  int value = 0;

  //constr --------------
  Card(float x, float y, 
    int v) {

    cardX = x;
    cardY = y;

    value = v;
  }//constr --------------

  void display() {
    fill(255); 
    rect(cardX, cardY, 
      cardW, cardH);

    fill(0); 
    text(value, 
      cardX+18, cardY+17);
  }

  boolean mouseInside() {
    return
      mouseX > cardX &&
      mouseX < cardX + cardW && 
      mouseY > cardY &&
      mouseY < cardY + cardH;
  }//method
  //
}//class
//

```
