I'm not sure whether my title is clear enough, a bit hard for me to explain. Basically, I have this card abstract class. I also have a CreditCard subclass. In my CardSystem, I have different methods. One of them is chargeCard. What it does is simple putting some cash on my card. The thing is that I'm not sure how to do it. How can I get the chosen CreditCard using my Card class?
public abstract class Card {
private int ID;
public double price;
public int next;
public Card(double price) {
ID = next++;
this.price = price;
}
// Get method for price and ID
}
public class CredidCard extends Card {
public static final int price_per_card = 20;
private int balance;
private static int amountSold = 0;
public CreditCard(int balance) {
super(price_per_card);
this.balance = balance;
amountSold++;
}
// Get method for balance and amount sold
public void fill(int sum) {
balance += sum;
}
}
public class CardSystem {
public Card[] cards = new Card[10];
public Card findCard(int id) {
for(int i = 0....) {
if(card[i] != null && card.getID() == id) return card[i];
}
}
public void newCard(Card c) {
for(int i = 0; i < card.length; i++) {
if(card[i] == null) {
card[i] = c;
break;
}
}
}
public CreditCard chargeCard(int id, int sum) {
// Not sure how to do this..
Card findCard = findCard(id);
if(card != null) .... // what to do? how do I choose my CreditCard? I want to be able to use the fill method for selected CreditCard..
}
}