Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


interfaces help filter_list
Author
Message
RE: interfaces help #21
Okay. The @override is how you override a method in Netbeans. Override simply means that the method is inherited but you don't want to use the inherited code, you want to use your own code which you provide.

Next, what is the scope of the name variable? is it local or an instance variable? If its local in another method you can't use it in a different method.

Lastly, since you did an override on toString() I'm not sure if you can use it in the same manner. You may have to use it as a regular method (i.e. toString(purchasePrice);

This seems weird because from what you are saying you need to create a toString() when one already exists.

Maybe you can choose a different method name other than toString but use toString() in that method. You will get the result you need without the headache and without overriding toString().

Reply

RE: interfaces help #22
Okay. The @override is how you override a method in Netbeans. Override simply means that the method is inherited but you don't want to use the inherited code, you want to use your own code which you provide.

Next, what is the scope of the name variable? is it local or an instance variable? If its local in another method you can't use it in a different method.

Lastly, since you did an override on toString() I'm not sure if you can use it in the same manner. You may have to use it as a regular method (i.e. toString(purchasePrice);

This seems weird because from what you are saying you need to create a toString() when one already exists.

Maybe you can choose a different method name other than toString but use toString() in that method. You will get the result you need without the headache and without overriding toString().

Reply

RE: interfaces help #23
well thats all i did cant figure whats wrong
Code:
public class Articles {
    private int nbr;
    private int purchasePrice;
    private int salePrice;
    private String name;
    
    public Articles(int nbr,int purchasePrice,int salePrice,String name){
        this.nbr=nbr;
        this.purchasePrice=purchasePrice;
        this.salePrice=salePrice;
        this.name=name;
    }
    
    public  int getNbr(){
        return nbr;
    }
    public void setNbr(int nbr){
        this.nbr=nbr;
    }
    public int getPurchasePrice(){
        return purchasePrice;
    }
    public void setPurchasePrice(int purchasePrice){
        this.purchasePrice=purchasePrice;
    }
    public int getSalePrice(){
        return salePrice;
    }
    public void setSalePrice(int salePrice){
        this.salePrice=salePrice;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public double calculateRateOfReturn(){
        double tauxRendement=((salePrice-purchasePrice)/purchasePrice);
        return tauxRendement;
    }
    
@Override
    public String toString(){
        return name;
      
       return purchasePrice.toString();
       return salePrice.toString():
        
        
    }
i still get int cannot be dereferenced error for
return purchasePrice.toString();
return salePrice.toString():
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #24
well thats all i did cant figure whats wrong
Code:
public class Articles {
    private int nbr;
    private int purchasePrice;
    private int salePrice;
    private String name;
    
    public Articles(int nbr,int purchasePrice,int salePrice,String name){
        this.nbr=nbr;
        this.purchasePrice=purchasePrice;
        this.salePrice=salePrice;
        this.name=name;
    }
    
    public  int getNbr(){
        return nbr;
    }
    public void setNbr(int nbr){
        this.nbr=nbr;
    }
    public int getPurchasePrice(){
        return purchasePrice;
    }
    public void setPurchasePrice(int purchasePrice){
        this.purchasePrice=purchasePrice;
    }
    public int getSalePrice(){
        return salePrice;
    }
    public void setSalePrice(int salePrice){
        this.salePrice=salePrice;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public double calculateRateOfReturn(){
        double tauxRendement=((salePrice-purchasePrice)/purchasePrice);
        return tauxRendement;
    }
    
@Override
    public String toString(){
        return name;
      
       return purchasePrice.toString();
       return salePrice.toString():
        
        
    }
i still get int cannot be dereferenced error for
return purchasePrice.toString();
return salePrice.toString():
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #25
Only thing I can see that could be wrong is this:
@Override
public String toString(){
return name;

return purchasePrice.toString(); //calls your override method
return salePrice.toString(): //uses colon instead of semicolon
//calls your override method


}

You used a colon instead of a semicolon on your last statement. Since you did a override on toString(), you are calling your method on the statements inside of your method.

Don't override toString(). Change its name to something else and try to compile. That will let you know if that's the problem.

Reply

RE: interfaces help #26
Only thing I can see that could be wrong is this:
@Override
public String toString(){
return name;

return purchasePrice.toString(); //calls your override method
return salePrice.toString(): //uses colon instead of semicolon
//calls your override method


}

You used a colon instead of a semicolon on your last statement. Since you did a override on toString(), you are calling your method on the statements inside of your method.

Don't override toString(). Change its name to something else and try to compile. That will let you know if that's the problem.

Reply

RE: interfaces help #27
well i changed the name the method name fixed the semicolon but still i get int cannot be dereferenced

anw i searched for the exercice on the net and found it he changed in the question it shouldnt b toString i'll work on the original 1 unless some1 tell me it is possible to do it for his wuestion
(This post was last modified: 11-27-2013, 01:40 PM by LordPankake.)
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #28
well i changed the name the method name fixed the semicolon but still i get int cannot be dereferenced

anw i searched for the exercice on the net and found it he changed in the question it shouldnt b toString i'll work on the original 1 unless some1 tell me it is possible to do it for his wuestion
(This post was last modified: 11-27-2013, 01:40 PM by LordPankake.)
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #29
i just have 1 question in my mind for now maybe @Deque could give me a good explanation to this !!
why do i need to make interfaces then inplement them couldnt i just make those methodes inside the class ?
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #30
i just have 1 question in my mind for now maybe @Deque could give me a good explanation to this !!
why do i need to make interfaces then inplement them couldnt i just make those methodes inside the class ?
[Image: blackeagle_zps6ad86521.gif]

Reply







Users browsing this thread: 2 Guest(s)