#Adding to a function

27 messages · Page 1 of 1 (latest)

crisp rivet
#

The photo attached I hope shows enough of the code. I need to add an ID to the already coded print statement using a new function with the same name. I am unsure why it does not work correctly and am looking for guidance.

I.e
petName = fluffy
petAge = 5
petID = 1234

printAll() should print:
Fluffy, Age: 5, ID: 1234

rotund wagonBOT
#

This post has been reserved for your question.

Hey @crisp rivet! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

atomic cargo
#

we need to actually, yknow, see your code

#

to help you

rotund wagonBOT
#
Custom Tag List

ask, debug, example, format, js, try, resources, adopt, codelength, null-pointer, restart, homework, comparing-strings, index-out-of-bounds, comparison-assignment-operators, rule11, xyproblem, static, nohello, jre_jdk, learn, help, scanner, pseudocode, class-versions

atomic cargo
#

nvm we dont have an image of code tag

crisp rivet
#

Apologies I should have tagged it

atomic cargo
steep stag
#

```java
code here
```

atomic cargo
#

anyways @crisp rivet can you post the code you already have here

#

or at least give us a clearer screenshot of it

crisp rivet
#

Yeah sure lemme try here

#

So I can only edit between lines 32 and 35, I can add more lines in there but I cannot touch outside of that range. In photo 1 you can see what I've written, in photo 2 you can see the base printAll() and see the class PetData extends AnimalData (PetData is where my written printAll() is) and in the 3rd photo you'll see where the method printAll() is being called.

#

This is through zybook and its like an interactive textbook for learning java

atomic cargo
#

it's basically the instance of the class above you, hierarchy wise

#

eg super.printAll() will invoke the parent's printAll() method

#

you can just invoke that from the PetData printAll method, then print the next data segment out

crisp rivet
#

Yes, I was unaware I could do that in this method. We have only used it at the start of our classes

atomic cargo
#
public void printAll() {
  super.printAll(); // prints Name: xxx, Age: yyy and does not end the line
  System.out.print(", ID: "+idNum); // prints , ID: zzz, resulting in "Name: xxx, Age: yyy, ID: zzz"
}
crisp rivet
#

I see thank you

rotund wagonBOT
# crisp rivet I see thank you

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

crisp rivet
#

I didn't realize you could do that