Answer to Question #7546 in Java | JSP | JSF for Janice

Question #7546
Write a main program class that instantiates a Deck and several Card objects and calls each of their methods. The purpose of this class is to verify that your supporting classes work correctly.
1
Expert's answer
2012-03-22T09:27:33-0400
Class Card
public class Card {
private String color;
private String grade;
Card(){
}
Card(String color, String grade){
this.color = color;
this.grade = grade;
}
public void setColor(String color) {
this.color = color;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getColor() {
return color;
}
public String getGrade() {
return grade;
}
}
Class Deck
public class Deck {
private Card[] card;
Deck(){
}
Deck(Card[] card){
this.card = card;
}
public Card[] getCard() {
return card;
}
public void setCard(Card[] card) {
this.card = card;
}
public void showCards(){
for(Card c: card)
System.out.println("Color: "+c.getColor()+", grade: "+c.getGrade());
}
}
Main Class
public class Main{
static Card c1 = new Card("Spades","King");
static Card c2 = new Card("Hearts","Queen");
static Card[] c = {c1,c2};
static Deck deck = new Deck();
public static void main(String[] args) {
deck.setCard(c);
deck.showCards();
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal