Forums Register Login

Calling Classes and Methods

+Pie Number of slices to send: Send
Hello! I'm working on an assignment and have constructed the following classes and methods, including an application to utilize the classes and methods. However, I get some strange lines printed when the application executes. I've debugged and can't seem to figure out what is going on. The lines that should read the invoiceNumber are showing as:

kft1task1.Invoice@48d593f7
kft1task1.Invoice@3de5627c
kft1task1.Invoice@1ea4daa3

Here is the application:


Here is the code for the classes / methods:


Thanks for your help!
+Pie Number of slices to send: Send
It is now good time for you to understand the Object class and the methods that it has. Have a look at what a toString method means in Java. If you understand that, you will understand why you see those strange characters and you will be in a position to fix it so that you see what you wanted when you println your invoice objects.
+Pie Number of slices to send: Send
Hey Joe!

I thought about that and tried to add toString() by System.out.println(inv1.toString());, but it didn't do anything. It ran fine, but didn't output correctly. Am I missing something?
+Pie Number of slices to send: Send
This seems to work well...I created a second constructor class and did all my string formation there:



Then, I just referenced that in my application:



Thoughts?
+Pie Number of slices to send: Send
You could override the toString() method in your class Invoice, then whenever you call it you'd get whatever you put in there, instead of something that looks like Invoice@4898ae
I love a good mentalist. And so does this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 619 times.
Similar Threads
Basic question about constructors
Class and Object Problem
Formating issues
Accessing a session scoped variable anywhere outside the session scoped context
problem with millisecond date calculation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:24:55.