public class CellPhone {
//REMINDER: protected fields can be accessed directly by any
// class which extends this one
protected String ownerName;
public CellPhone(String ownerNameIn) {
//initialize ownerName as ownerNameIn
ownerName = ownerNameIn;
}
public String receiveCall(CellPhone sender) {
//return a String of the form:
// receiver's name " is receiving a call from " sender's name
//you can implement this by using the receiver to invoke receiveCall
// while passing in the current phone
String receiveCall = sender.ownerName + " is receiving a call from " + ownerName;
return receiveCall;
}
public String call(CellPhone receiver) {
//return a String by using the receiver to invoke receiveCall
// while passing in the current phone
return this.receiveCall(receiver);
}
}
package cellPhones;
public class TextMessagingPhone extends CellPhone {
//number of messages owner can send and receive
//REMINDER: private fields can't be accessed by class which extends this one
private int availMessages;
public TextMessagingPhone(String owner) {
//Initialize ownerName as owner and availMessage as 15 by invoking the
// two-parameter constructor of this class.
this(owner,15);
}
public TextMessagingPhone(String owner, int messageLimit) {
//initialize ownerName as owner and availMessage as messageLimit
//part of this will require invoking the superclass constructor
// and then setting the new instance variable
super(owner);
availMessages = messageLimit;
}
public String receiveText(TextMessagingPhone sender, String message) {
//The owner receives message from sender.
//decrease the number of messages available to receive
//return a String of the form:
// owner's name " has received TEXT from " sender's name ":" message
availMessages --;
String receivedText = ownerName + " has received TEXT from " + sender + ":" + message;
return receivedText;
}
public String sendText(TextMessagingPhone receiver, String message) {
//decrease the number of messages available to send
//return a String by using the receiver to invoke receiveText
// while passing in the current phone and the message
availMessages --;
String invokingReceiveText = receiver.receiveText(receiver, message);
return invokingReceiveText;
}
}
package cellPhones;
public class SmartPhone extends TextMessagingPhone {
public SmartPhone(String ownerIn) {
//Invoke the super class' copy constructor and send it owner
//NOTE: There's nothing else to do since SmartPhone adds no
// new fields.
super(ownerIn);
}
public String displayPicture(String pictureSubject) {
//return a String of the form:
// owner's name " now displaying picture of " pictureSubject
String picture = ownerName + " now displaying picture of " + pictureSubject;
return picture;
}
/*
* This method OVERRIDES the inherited receiveCall method.
* Smartphones "display" a photo of the caller.
*/
public String receiveCall(CellPhone sender) {
//return a String built from:
// the result of calling displayPicture with the sender's owner's name
// concatenated with a dash and then concatenated with the
// result of invoking the superclass' receiveCall with the sender
String call = this.displayPicture(ownerName) + "-" + sender.ownerName;
return call;
}
public String receivePictureAndTextMessage(
SmartPhone sender, String messageText, String picDescription) {
//owner receives messageText from sender with picDescription
//return a String built from:
// the result of calling displayPicture with the picDescription
// concatenated with a dash and then concatenated with the
// result of invoking the receiveText method with the sender
// and the messageText
String picText = this.displayPicture(picDescription) + "-" + this.receiveText(sender,messageText);
return picText;
}
public String sendPictureAndTextMessage(
SmartPhone receiver, String messageText, String picDescription) {
//owner sends messageText to receiver with picDescription
//return a String built by having the receiver invoke the
// receivePictureAndTextMessage method, sending in the
// current phone, the messageText, and the picture description
return receiver.receivePictureAndTextMessage(receiver, messageText, picDescription);
}
}
私が得ているエラーは 2 番目と 3 番目のクラスに関するもので、「[cellPhones.TextMessagingPhone@842e3b] から TEXT を受信しました:What ru doing?> but was:<... received TEXT from [Cindy's text phone]:What ru と表示されます。やってる?>」。これを修正する方法を知っている人はいますか?