|
-
May 11th, 2009, 03:02 AM
#1
getter setter
class calculate {
private int profitRate=20;
public long i;
customer obj=new customer("Mr.Stevens",189745329,40000000);
public void CalculatedMoneyAmount(){
i=( obj.getmoney() +( obj.getmoney()*profitRate)/100);
obj.setmonney(i);
}
}
class customer{
private String customerName;
private int accountNumber;
private long money;
public customer(String name,int number,long amount)
{
this.customerName=name;
this.accountNumber=number;
this.money=amount ;
}
public customer()
{
}
public long getmoney(){
return money;
}
public void setmonney(long i){
this.money=i;
}
public void calmoney() {
calculate obj=new calculate();
obj.CalculatedMoneyAmount();
}
}
public class Main {
/** Creates a new instance of Main */
/**
* @param args the command line arguments
*/
public static void main(String[] args){
customer o=new customer("Mr.Stevens",189745329,40000000);
o.calmoney();
System.out.println (o.getmoney());
}
}
It must retuern and show to output 48000000
But only shows 40 000000
-In the main mehtod I careate an instance of customer class
-After that I call calmoney
-calmoney calls CalculatedMoneyAmount in calculate class
-CalculatedMoneyAmount call getmoney
-CalculatedMoneyAmount send the profit to money variable by setmoney
-Now this line System.out.println (o.getmoney()); must print 48 000 000
But I see 40 000 000 !!
-
May 11th, 2009, 04:29 AM
#2
Re: getter setter
Your calculate class creates a customer of its own. It does not matter, if you create another customer, with identical values in your main method. That IS NOT the same customer instance. You should have the calculations as a method in your calculate class, where the customer is given as a parameter. That way the right customers money would change.
-
May 12th, 2009, 01:09 PM
#3
Re: getter setter
I know ,But I want to use getter setter to learn about this matter .
class calculate {
private int profitRate=20;
public long i,j;
public void CalculatedMoneyAmount(customer obj){
i=( obj.getmoney() +( obj.getmoney())/100);
System.out.println( "i = " + i );
}
class customer {
private String customerName;
private int accountNumber;
private long money;
public customer(String name,int number,long amount)
{
this.customerName=name;
this.accountNumber=number;
this.money=amount ;
}
public customer()
{
}
public long getmoney(){
return money;
}
public void setmoney(long i){
this.money=i;
}
}
}
public class Main {
/** Creates a new instance of Main */
/**
* @param args the command line arguments
*/
public static void main(String[] args){
customer o=new customer("Mr.Stevens",189745329,40000000);
calculate l=new calculate();
l.CalculatedMoneyAmount( o );
o.setmoney(l.i);
System.out.println (o.getmoney());
}
}
I have problem in these lines :
l.CalculatedMoneyAmount( o );
o.setmoney(l.i);
Please answer to this question
- How to pass an object as a parameter in a method?
-
May 12th, 2009, 02:28 PM
#4
Re: getter setter
It would help if you used code tags when posting code, which after 79 posts you should be aware of. It would also help if you used the Java capitalisation conventions.
I have problem in these lines :
l.CalculatedMoneyAmount( o );
o.setmoney(l.i);
And it would help if you took the trouble to explain your problem in detail.
What is obvious is the customer class doesn't have a field 'i' so trying to use l.i isn't going to work. What were you trying to do?
-
May 12th, 2009, 08:47 PM
#5
Re: getter setter
What is obvious is the customer class doesn't have a field 'i' so trying to use l.i isn't going to work. What were you trying to do?
Sir , What is obvious is you answer carelessly .
Code:
class calculate {
private int profitRate=20;
public long i,j;
public void CalculatedMoneyAmount(customer obj){
i=( obj.getmoney() +( obj.getmoney())/100);
System.out.println( "i = " + i );
}
Good luck friend!
-
May 13th, 2009, 06:35 AM
#6
Re: getter setter
Sir , What is obvious is you answer carelessly
Apologies, your code is somewhat confusing to read.
So what exactly is your problem? Please state what you are trying to achieve, what is going wrong and give complete copies of any compiler/runtime error messages.
-
May 13th, 2009, 09:09 AM
#7
Re: getter setter
No problem Sir, The problem of that has been solved
But Thank you very much indeed for your help,
The most important thing is you decide to help others
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|