I just need to make sure that the snippet of code is correct. I don't have all the code as I'm still writing it. If it's possible I need help on the assignment. Maybe clues as to how to do it and maybe point to where I can find the answer. I'll add code as I finish it.

1st snippet.

1. A constructor which accepts a suit and a value and, if these are acceptable, initializes the
instance variables accordingly. If the supplied values are not acceptable, default values are used
instead.
2. A toString method which returns the card value followed by a space, followed by the suit
abbreviation in parentheses. For example, the ace of spades would be A (S). If the value to be
used is not “10”, add an extra trailing space. This will allow a printout of the whole deck to line
up nicely in rows and columns since the 10-cards toString result will have an extra character.
3. Methods called isRed and isBlack that return true if the suit of the card is a red one (hearts,
diamonds) or a black one (spades, clubs), respectively.
4. A method called isFaceCard that returns true if the card is a 10, jack, queen, king or ace.
5. A method called isPair that takes in a Card object as a parameter and returns true if the calling
Card object (this) has the same value as the parameter.
6. A method called equals that returns true if the calling Card and the Card parameter have the
same suit and the same value.
7. A method called compareTo that returns the distance between the suits of the calling Card and
the Card parameter, but if they are the same suits then it should return the distance between
the card values. An easy way to do this is to use the indexOf method (below) for suits or values
and subtract the results.
8. Private methods called validSuit and validValue that takes in a String parameter and return true
if the given String is in the constant array of card suits or values, respectively.
9. A private method called indexOf that takes in a String parameter and an array of Strings and
returns the index in the array where the String parameter is found. If it is not found it should
return -1.

public class Card
{
	public static final String[] SUITS = { "S", "H", "C", "D"};
	public static final String[] VALUES = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K",};
	public static final String DEFAULT_SUIT= SUIT[0];
	public static final String DEFAULT_VALUE= VALUES[0];

	private String suit;
	private String value;

	public String Card ( String x, String y)
	{
			suit = s;
			value = v;

				if(v != VALUES)
				v = DEFAULT_VALUE;

				if(s != SUIT)
				s = DEFAULT_SUIT;
	}

	public String toString()
	{
		String str =  v + " " + s;
		return str;

	}


	public boolean isRed()
	{
		for(int i = 0; i<SUIT.length;i+=2)
		return true;
	}

	public  boolean isBlack()
	{
		for(int i = 0; i<VALUE.length;i+=1)
		return true;

	}

	public boolean isFaceCard()
	{


	}

	public boolean equals(Card)
	{

	}

	public int compareTo(Card)
	{

	}

	public boolean isPair(Card)
	{

	}

	private boolean validSuit(Card)
	{

	}

	private boolean validValue ( String z)
	{

	}

	private int indexOf(String a, String[])
	{

	}

}

If you want help ask a specific question. At the very least, point us to a part of your assignment requirements that you don't understand how to implement and ask for clarification. If you don't understand the entire assignment, that's fine, but explain what you don't understand, why you don't understand it, and relevant attempts at solving it, if any.

(I say the above 'cuz it looks to me like you copy pasted your assignment and then your code..)

OK, what i don't understand is #3 and 4. How do i write it so that it checks if whose values specified were inputed.

Prior to #3 and #4, you have #2. In #2, it is assumed that you now have a valid card.

For example you got A (S) (ace of spades). Then you need to construct a method isRed that accepts a String parameter (which is your card) and returns either true or false (boolean).


Method construction is like this :

public returnType methodName (Input parameter) {

Hint ** if isRed is True then isBlack is always false.

Hope this helps in clarifying things (",)

Oh so I write the method twice for isRed and isBlack but I put return true for isRed and return false for isBlack.

No. What I mean is you create a method isRed and isBlack but in your isBlack method you can just return !isRed().

public boolean isRed(String cards) {
   \\your condition for red suits here, return true if red, false otherwise
}


public boolean isBlack() {
     return !isRed(cards);
}

As you can see, you dont have to put the condition in the isBlack method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.