WhisperTheGhost
WhisperTheGhost

Reputation: 1

Symbol varible errors and imcopatible types errors

I am very new to using Bluej but am currently working on an assignment that involves test classes and inheritance. The test class that I am currently having issues with is Coach. It has come up saying that Coach is an incompatible type that cannot be converted to java.lang.String.

As I am very new I am unsure of what I have tried is correct but I have tried changing the format of the code, adding it in other places on the code itself.

public class CoachTest extends junit.framework.TestCase 
{
   private String Coach;
   Private String coach1; 

   public void setup() 
   {
      coach1 = new Coach("Amy Blunt", "0004");
   }

   /** 
   * Tears down the test fixture. 
   *
   * Called after every test case method. 
   */ 
   protected void teardown()
   {
   }

   public void testGetName() 
   {
     assertEquals("Amy Blunt", coach1.getName()); 
   }

   public void testMembership()
   {
     assertEquals("0004", coach1.getMembership());
   }
}

I expect it to be able to correctly show the membership number and name when it is run through a test.

There are three error messages that occur, one is "incompatible types: Coach cannot be converted to java.lang.String" which is centred around the public void setup(). The next one is "cannot find symbol - method getName()" which is centred around the public void testGetName() as well as this the public void getMembership has the same error.

Upvotes: 0

Views: 47

Answers (1)

Jorge C.M
Jorge C.M

Reputation: 393

You are declaring coach1 as a String, not as a Coach. Also you have at the upper line a definition stating 'private String Coach'that makes no sense as it's a class not a variable name and moreover seems that there are more brackets than needed (at least at your example).

Here's the fixed code:

public class CoachTest extends junit.framework.TestCase { 

   private Coach coach1; 


   public void setup() 

   {

      coach1 = new Coach("Amy Blunt", "0004");

   }

   /** 
   * Tears down the test fixture. 
   *
   * Called after every test case method. 
   */ 

   protected void teardown()

   {

   }

   public void testGetName() 

   {

     assertEquals("Amy Blunt", coach1.getName()); 

   }

   public void testMembership()

   {

      assertEquals("0004", coach1.getMembership());

   }
}

Hope this helps you!

Upvotes: 0

Related Questions