0 Replies - 429 Views - Last Post: 28 April 2009 - 05:12 PM Rate Topic: -----

#1 twoneight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-April 09

Set Game isSet method. Need advice on how to start

Post icon  Posted 28 April 2009 - 05:12 PM

  

public class Set
{
	// Instance variable
	String errorMessage;

	/**
	 * Constructor for objects of class Set
	 */
	public Set()
	{
	}
	//-------------------------------------------------
	/**
	 * Tests if cards form a set
	 * 
	 * @param  3 cards to test
	 * @return True if the cards form a set
	 */
	 public boolean isSet(Card[] testCards)
	 {
		 /* This method has to check the 3 cards passed in,
		  * testCards, to see if they form a set.  There is
		  * an easy way to do this, and there are harder ways.
		  * Find a way you understand and can get to work.
		  * If the cards are a set, return true.  If they are
		  * not a set, return false and set the errorMessage
		  * variable to say what was wrong.  There are
		  * methods to deal with the error message - call the 
		  * appropriate one.
		  */
		// Default to false until all tests passed
		boolean bSet = false;
		errorMessage = "OK"; // A non-error default message
		
		
		return bSet;
	}

	//-------------------------------------------------
	/**
	 * Returns the error message
	 */
	public String getErrorMessage()
	{
		return errorMessage;
	}
	//-------------------------------------------------
	/**
	 * Works out the error message when shapes do not form a set
	 * @param Array of 3 cards
	 */
	private void setShapesErrorMessage(Card[] testCards)
	{
		/*
		 * We want the error message to say:
		 *  Two are xxx, but one is not.
		 */
		String message = "Not a set, two are ";
		int theTwo = testCards[0].getShapeValue();
		
		/*
		 * The tests here are the same for all 4 attributes.  If the
		 * first card is equal to either of the other cards, then its
		 * property if the "two".  Only if cards 2 and 3 are the same
		 * is that not the case.  All 3 cannot be equal or the cards
		 * would be a set!
		 */
		if(testCards[1].getShapeValue() == testCards[2].getShapeValue())
		{
			theTwo = testCards[2].getShapeValue();
		}
		
		// Find the text for the "two" and complete the message
		message += Card.SHAPES[theTwo];
		errorMessage = message + "s but one is not.";
	}
	//-------------------------------------------------
	/**
	 * Works out the error message when numbers do not form a set
	 * @param Array of 3 cards
	 */
	private void setNumbersErrorMessage(Card[] testCards)
	{
		String message = "Not a set, two are ";
		int theTwo = testCards[0].getNumber();
		
		if(testCards[1].getNumber() == testCards[2].getNumber())
		{
			theTwo = testCards[2].getNumber();
		}
		
		message += theTwo;
		errorMessage = message + "s but one is not.";
	}	
	//-------------------------------------------------
	/**
	 * Works out the error message when colours do not form a set
	 * @param Array of 3 cards
	 */
	private void setColoursErrorMessage(Card[] testCards)
	{
		String message = "Not a set, two are ";
		int theTwo = testCards[0].getColourValue();
		
		if(testCards[1].getColourValue() == testCards[2].getColourValue())
		{
			theTwo = testCards[2].getColourValue();
		}
		
		message +=  Card.COLOURS[theTwo];
		errorMessage = message + " but one is not.";
	}	//-------------------------------------------------
	/**
	 * Works out the error message when fillingss do not form a set
	 * @param Array of 3 cards
	 */
	private void setFillingErrorMessage(Card[] testCards)
	{
		String message = "Not a set, two are ";
		int theTwo = testCards[0].getFillValue();
		
		if(testCards[1].getFillValue() == testCards[2].getFillValue())
		{
			theTwo = testCards[2].getFillValue();
		}
		
		message +=  Card.FILLS[theTwo];
		errorMessage = message + " but one is not.";
	}
	//-------------------------------------------------
} 


I just need advice on where to start the method and how to tackle the method. would i start of with a IF statement testing the cards shape then colour then number or could i compare each cards properties at once??

Is This A Good Question/Topic? 0
  • +

Page 1 of 1