Hello guys,
I am having trouble understanding the concept of constructors. I have to create the following program as you can see I have greatly messed up. Any help would be greatly appreciated. Thank you!
Problem 2: Card Object
Create a class that represents a playing card. Playing cards have two attributes, a suit and a rank. Include a public
parameterized constructor that sets the card to have a suit and a rank. Include getters to access the suit and rank, but
you should not include setters to change them once they are created.
Include a test main that demonstrates that your class works.
package getcard;
import java.util.Scanner;
class CardObject{
private int suit;
private int rank;
public CardObject(int new_suit,int new_rank){
suit=new_suit;
rank=new_rank;
}
public static void ArrayCard(CardObject c){
String[] suits={"Clubs","Diamonds","Hearts","Spades"};
String[] ranks={"","Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
Scanner in=new Scanner(System.in);
System.out.println("Enter an integer from 1 to 4 for a suit");
int new_suit=in.nextInt();
System.out.println("Enter an integer from 1 to 13 for a rank");
int new_rank=in.nextInt();
System.out.println("Your card is "+ranks[c.rank]+ "of" +suits[c.suit]);