aspose file tools*
The moose likes Beginning Java and the fly likes getter setter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getter setter" Watch "getter setter" New topic
Author

getter setter

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
---------------
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40

-calmoney calls CalculatedMoneyAmount in calculate class
-CalculatedMoneyAmount call getmoney
-CalculatedMoneyAmount send the profit to money variable by setmoney


Basically, the calculate class instantiates a new customer object -- which is not the one that was used to call instantiate and call the calculate object.

So, you do set the customer object, but it's a different one. Furthermore, the calcmoney() method discards the calculate object, so that is also lost, upon return.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
Difficult to read because you haven't preserved indentation.

Confusing. You are adding 20% in the calculate class (that should start with a capital letter) but you are never passing the money back. You are creating a new customer (should read Customer) object, setting the 48000000 on that, then it isn't used because it is in a different class.
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Hi,
I dont think that the value of o.getmoney will ever be 40 000000.
Have you tried debuging your code in an IDE and stepping through each line to see where and how the values of customer
are being set?

This might help you to see where your values are getting set and is a valuable skill for a developer to learn.

Just out of interest, why is i a public field and not a vairable within the calculate method?

hope this helps
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
-----------
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874




Create a calculate() constructor
pass the customer object to calculate() constructor and initialise the customer object
call the CalculatedMoneyAmount , which will now access the same customer object as initialsed in first step

or

Pass the customer object to CalculatedMoneyAmount () method and return the object back. // this more dumb way.



abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
///////
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
abalfazl hossein wrote:May you give me code about this?
Surely you can work that out for yourself?
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
*****
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

abalfazl hossein wrote:May you give me code about this?

No: http://faq.javaranch.com/java/NotACodeMill, http://faq.javaranch.com/java/DoYourOwnHomework


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
---------
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

abalfazl hossein wrote:This is clear question:

I have a method in a class ,(customer class)

I want to access it,This method can not be static.I donot want use it as static

I want to know other than I create new instance ,Is there away to access it?

Balu Sadhasivam said:


Create a calculate() constructor
pass the customer object to calculate() constructor and initialise the customer object
call the CalculatedMoneyAmount , which will now access the same customer object as initialsed in first step


I want to know how is it possible?

Please answer me directly!



No, i dont think its possible


If a method is a part of the class (and its not static),
You would require an object to invoke it.


Question: Why do you want such approach ?

I can see directly that your code would not require any such special logic to run,





My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928




here is my approach

Of course you have to change it a bit to make it work for your senario,

but here is my approach:

since calculation is an operation, i used a method instead of a class.

You can still use a calculation class that does the work, but i prefer this approach.


if you still want external class:

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40

abalfazl hossein wrote:
Balu Sadhasivam said:

Create a calculate() constructor
pass the customer object to calculate() constructor and initialise the customer object
call the CalculatedMoneyAmount , which will now access the same customer object as initialsed in first step


I want to know how is it possible?

Please answer me directly!



Of course, it is possible -- in fact, Balu described it so well, that it is basically pseudo code !!

The issue here (and why no one is giving you exact code), is because you won't learn if we do. What was described is so clear, that you shouldn't have any issues. It is also releated to something basic in Java that you absolutely need to understand it.... Anyway, I suggest that you go back an review the chapter on methods, particularly parameter passing.

Henry
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Henry, i hope i didnt show him too much
i didnt add the logic for calculations.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getter setter