I\'m trying to run this code on java but it show this: the code DalmutiCard.java
ID: 3875328 • Letter: I
Question
I'm trying to run this code on java but it show this:
the code
DalmutiCard.java
public class DalmutiCard {
private String cardName;
private int cardRank;
public DalmutiCard(int cardRank) {
setCard(cardRank);
}
public String getCardName() {
return cardName;
}
public int getCardRank() {
return cardRank;
}
public void setCard(int cardRank) {
if(cardRank < 1 || cardRank > 13) {
this.cardRank = 0;
this.cardName = "Unknonwn";
}
else {
this.cardRank = cardRank;
String cardNames[] = {"", "Dalmuti", "Archbishop", "Earl Marshal", "Baroness", "Abbess", "Knight",
"Seamstress", "Mason", "Cook", "Shepherdess", "Stonecutter", "Peasant", "Jester"};
this.cardName = cardNames[cardRank];
}
}
@Override
public String toString() {
return cardRank + " - " + cardName;
}
}
Explanation / Answer
Basically to execute a Java file there should be a main method in the class so you should have a main method with signature as shown in the error.
So just add a main method in which you can make an object of your class and test the methods that you have implemented in the class.