我的一些課程沒有通過自動化測試。不幸的是,所述測試沒有提供關於其失敗原因的任何有用信息。這是我的幾個類的代碼。如果你能告訴我我出錯的地方,我會非常感激。評論應該解釋每種方法應該做什麼。這段代碼在哪裏出錯?
public class CellPhone {
protected String ownerName;
public CellPhone(String owner) {
ownerName = owner;
}
public String receiveCall(CellPhone sender) {
// returns a String of the form:
// owner's name " is receiving a call from " sender's name
String receivingCall = ownerName + " is receiving a call from " + sender;
return receivingCall;
}
public String call(CellPhone receiver) {
// returns a String by using the receiver to invoke receiveCall
// while passing in the current phone
String invokingReceiveCall = receiver.receiveCall(receiver);
return invokingReceiveCall;
}
}
public class TextMessagingPhone extends CellPhone {
private int availMessages;
public TextMessagingPhone(String owner, int messageLimit) {
// invokes the superclass constructor
super(owner);
// sets the new instance variable
availMessages = messageLimit;
}
public TextMessagingPhone(String owner) {
// invokes the other constructor of this class with 15 as the message limit
this(owner, 15);
}
public String receiveText(TextMessagingPhone sender, String message) {
// decreases the number of messages available to send
availMessages--;
// returns a String of the form:
// owner's name " has received TEXT from " sender's name ":" message
String receivedText = ownerName + " has received TEXT from " + sender + ":" + message;
return receivedText;
}
public String sendText(TextMessagingPhone receiver, String message) {
// decreases the number of messages available to send
availMessages--;
// returns a String by using the receiver to invoke receiveText
// while passing in the current phone and the message
String invokingReceiveText = receiver.receiveText(receiver, message);
return invokingReceiveText;
}
}
如果沒有關於失敗的信息,很難告訴你什麼是錯的。你提到他們沒有通過測試......嗯......什麼測試? – 2011-05-04 19:38:45
你有沒有考慮過給ownerName分配一些東西? – Fredrik 2011-05-04 19:39:05
你可以發佈你正在運行的測試,哪些測試失敗? – Jerome 2011-05-04 19:39:45