The Student Room Group

Need help with Java Testing Interfaces

Hi,

I have been working for about 3 hours on this peice of code but I still cant get it to test properly. Basically I have made a mobile device that connects to other devices and allows them to send messages. I need to test a Mobile class to see if I can test a connection (basically to see if there is a connection and if so display the receiving message)

I have an interface called Greenfang which allows the object orientated objects to talk to each other

heres my mobile code

/**
public class Mobile {

private String imac;
private GreenFang connection;
private boolean paired;

/**
*Create a Mobile of the type passed in as a String
*/
public Mobile(String type){
this.imac = imac;
paired = false;

}

/**
* Pass in the device that you wish connect to. The device must implement
*the GreenFang interface
*/
public void connect (GreenFang greenFangConnection){
if(greenFangConnection != null ){
connection = greenFangConnection;
paired = true;

}
}

/**
*Disconnect an existing connection. Only successful if already connected
*to the GreenFang passed in
*/
public void disconnect(GreenFang greenFangConnection){
if (connection == greenFangConnection){
connection = null;
paired = false;
}
else{
System.out.println("Can't disconnect - not connected in the first place");
}
}

/**
*Call this method when connected to a GreenFang device to pass your message
*/
public void sendGreenFangMessage(String message){
if (paired){
connection.receiveMessage("Message from "+imac+":"+message);
}
else{
System.out.println("No GreenFang connection present");
}
}



}


heres my GreenFang code

/**
*Devices implementing this interface can communicate
*/

public interface GreenFang{
/**
*receives a message as String
*/
public void receiveMessage(String information);



}


and heres my Tester which I have not yet completed

public abstract class MobileTest implements GreenFang {

public static void main(String[] args) {

Mobile receiveMessage1 = new Mobile();

String answer = receiveMessage1.sendGreenFangMessage();

System.out.println(answer);
}
}




I don't know where I am going wrong, does my tester being abstract have anything to do with the problem as I have changed it, still not working
What about it is not working? All I see is that you are calling sendGreenFangMessage() that takes String as a parameter but you haven't provided a parameter. It would help enormously if I knew what the problem actually is.

Latest

Trending

Trending