-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicCardArray.java
42 lines (35 loc) · 944 Bytes
/
DynamicCardArray.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class DynamicCardArray {
private Card[] cards;
private int numOfCards;
public DynamicCardArray(){
this.cards = new Card[1000];
this.numOfCards = 0;
}
public int length(){
return this.numOfCards;
}
public Card getCardAtIndex(int index){
return cards[index];
}
public void addCard(Card card){
this.cards[this.numOfCards] = card;
this.numOfCards++;
}
public void setCardAtIndex(int index, Card card){
this.cards[index] = card;
}
public void removeCardAtIndex(int index){
for(int i = index; i < this.numOfCards; i++){
this.cards[i] = this.cards[i+1];
}
this.numOfCards--;
}
public boolean contains(Card card){
for(int i = 0; i < this.numOfCards; i++){
if(this.cards[i] == card){
return true;
}
}
return false;
}
}