wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Get/Set method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Get/Set method" Watch "Get/Set method" New topic
Author

Get/Set method

Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
I am working my way through a text book, trying to self-teach during my spare time. One of the exercises has me setting up a class called Purchase, with get and set methods. It then wishes me to set up a method in that class called display, to display the stored info (I've blocked out the code starting on lines 30-34 of the second class where this should happen). In the second class, called CreatePurchase, I create the info to send to set methods, with loops and exception handling.

I am stuck on how to do the display part of the exercise. I am attaching code. HELP!




Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
Anybody?
Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

I didn't look deeply in your code but what I understand is that you want to show value of Purchase object and you want a Display method in Purchase Class.
You should declare a Display() method without any argument list like public void Display(). You can call this method from your CreatePurchase class with Purchase class object like onePurch.display();

Inside this method just place the System.out.print statement to print the values of the object like System.out.print("Value of invoice is: " +invNumber);

Hope this help.


Do not wait to strike till the iron is hot; but make it hot by striking....
Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

You have created 2 purchase class objects , but you have not stored them any where. Try to retain the objects in a collection object. Then iterate the collection and get the purchase object and get the values from the object.

Regards
Santhosh
Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
@Manoj Kumar Jain

This help got me close enough to soling my problem. I had some other logic errors to deal with as well as I was out of scope when I tried to execute.

Anyways, Thank you to those who answered.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get/Set method
 
Similar Threads
Class and Object Problem
endless loop
try...catch blocks giving <identifier> expected error
StackOverflowError
Java Validation! Field should be Integer