![]() |
| ||
| Printing from a method I have 3 classes..but i need to print the outcome from the printArray. Right now it is printing from the GetTax Compute class. I am so confused. Class 1... any help would be appreciated |
| ||
| Re: Printing from a method I would rather not be confused. Could you describe your problem? |
| ||
| Re: Printing from a method I'm guessing this is a class assignment and your instructor wants you to modify it. The program has been done for you. All you have to do is retrieve the values associated with the items that are stored in the items array which are already given in the code. First things first, forget about the output that is being done in GetTax.compute. It has nothing to do with what your instructor wants you to do. Focus only on Class1 and Class3. The items array is holding 3 items. Each item is an object that stores the barcode, name and price. These values have been hardcoded into the main method of class PosCalProgram. When the program runs, the main method is the first to be initialized(made active). In this process, 3 item objects are created (initialized). I will walk you through the first initialization of the first item. items[0]=new item("521412", "Shoes", 200)1. During initialization of the first item (we are in class1), the item class(result will be an object on the heap after its initialization) is passed 3 parameters. The fist parameter is a String object, the second a String object and the third is a primitive double value (control temporarily passes to class3). Since an item is being invoked by the main method, the item constructor begins to process all that is within it. Its variables barcode is assigned the String object "521412", name is assigned the String object "Shoes", and price is assigned the primitive double value 200 (control passes back to class1 and the next two items are go through the same initialization process). Control is now back in class1. The method printArray(items); is invoked (called to be used, so control is given to this method which is passed an object reference to the items array (remember, this array holds a reference to the 3 item objects stored in memory. The reference is a bit pattern pointing to the item objects and not the actual objects themselves). It is within this method where you would print the values of each item object to the output screen. It is here where your instructor wants you to learn something valueable, so I won't give you the full details. Try to figure this part out and then report back with your findings. |
| ||
| Re: Printing from a method Ok..well i know in the printArray after item x=y[i]; there should be System.out.println(x.barcode + " " + x. name + " " + x.price); but then I also want the gst, pst and total to print out in this method. i tried to use compute b = new Compute(); then use b.GstTax but that does not seem to work. I need to get the values from the compute method to print from the print array. |
| ||
| Re: Printing from a method Quote:
|
| All times are GMT -4. The time now is 10:44 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC