java - I am getting an error on the test for some classes I wrote but I cant figure out what I did wrong? -
public class cellphone { //reminder: protected fields can accessed directly // class extends 1 protected string ownername; public cellphone(string ownernamein) { //initialize ownername ownernamein ownername = ownernamein; } public string receivecall(cellphone sender) { //return string of form: // receiver's name " receiving call " sender's name //you can implement using receiver invoke receivecall // while passing in current phone string receivecall = sender.ownername + " receiving call " + ownername; return receivecall; } public string call(cellphone receiver) { //return string using receiver invoke receivecall // while passing in current phone return this.receivecall(receiver); } } package cellphones; public class textmessagingphone extends cellphone { //number of messages owner can send , receive //reminder: private fields can't accessed class extends 1 private int availmessages; public textmessagingphone(string owner) { //initialize ownername owner , availmessage 15 invoking // two-parameter constructor of class. this(owner,15); } public textmessagingphone(string owner, int messagelimit) { //initialize ownername owner , availmessage messagelimit //part of require invoking superclass constructor // , setting new instance variable super(owner); availmessages = messagelimit; } public string receivetext(textmessagingphone sender, string message) { //the owner receives message sender. //decrease number of messages available receive //return string of form: // owner's name " has received text " sender's name ":" message availmessages --; string receivedtext = ownername + " has received text " + sender + ":" + message; return receivedtext; } public string sendtext(textmessagingphone receiver, string message) { //decrease number of messages available send //return string using receiver invoke receivetext // while passing in current phone , message availmessages --; string invokingreceivetext = receiver.receivetext(receiver, message); return invokingreceivetext; } } package cellphones; public class smartphone extends textmessagingphone { public smartphone(string ownerin) { //invoke super class' copy constructor , send owner //note: there's nothing else since smartphone adds no // new fields. super(ownerin); } public string displaypicture(string picturesubject) { //return string of form: // owner's name " displaying picture of " picturesubject string picture = ownername + " displaying picture of " + picturesubject; return picture; } /* * method overrides inherited receivecall method. * smartphones "display" photo of caller. */ public string receivecall(cellphone sender) { //return string built from: // result of calling displaypicture sender's owner's name // concatenated dash , concatenated // result of invoking superclass' receivecall sender string call = this.displaypicture(ownername) + "-" + sender.ownername; return call; } public string receivepictureandtextmessage( smartphone sender, string messagetext, string picdescription) { //owner receives messagetext sender picdescription //return string built from: // result of calling displaypicture picdescription // concatenated dash , concatenated // result of invoking receivetext method sender // , messagetext string pictext = this.displaypicture(picdescription) + "-" + this.receivetext(sender,messagetext); return pictext; } public string sendpictureandtextmessage( smartphone receiver, string messagetext, string picdescription) { //owner sends messagetext receiver picdescription //return string built having receiver invoke // receivepictureandtextmessage method, sending in // current phone, messagetext, , picture description return receiver.receivepictureandtextmessage(receiver, messagetext, picdescription); } }
the error getting second , third classes , says "received text [cellphones.textmessagingphone@842e3b]:what r u doing?> was:<... received text [cindy's text phone]:what r u doing?> ". know how fix this?
you need print textmessagingphone.ownername
, rather textmessagingphone
object itself. or can override tostring()
method return ownername
.
Comments
Post a Comment