Login Register






interfaces help filter_list
Author
Message
RE: interfaces help #11
@darthjames226 well yes but maybe it was a bigger value i always use double instead of float int instead of byte ... is that wrong ?

now i moved to start with the next part
i need to make this class
Class Articles: general class of all items
Properties: number (automatically generated during the creation of an article), purchase price, sale price and name.
Methods (other than the manufacturer):
calculating the rate of return ((prixVente - purchasePrice) / purchasePrice)
toString (): return the name and price of the item
This class does not implement any interface.

i did this
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; } }

i didnt understand what he mean with this
Code:
toString (): return the name and price of the item
and why do i need to make this isnt this the same as the get methods i made ?
(This post was last modified: 11-27-2013, 01:22 AM by LordPankake.)
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #12
@darthjames226 well yes but maybe it was a bigger value i always use double instead of float int instead of byte ... is that wrong ?

now i moved to start with the next part
i need to make this class
Class Articles: general class of all items
Properties: number (automatically generated during the creation of an article), purchase price, sale price and name.
Methods (other than the manufacturer):
calculating the rate of return ((prixVente - purchasePrice) / purchasePrice)
toString (): return the name and price of the item
This class does not implement any interface.

i did this
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; } }

i didnt understand what he mean with this
Code:
toString (): return the name and price of the item
and why do i need to make this isnt this the same as the get methods i made ?
(This post was last modified: 11-27-2013, 01:22 AM by LordPankake.)
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #13
The toString() returns a string equivalent. For example:

int value = 30;
System.out.println(value.toString());

This code snippet would print out 30. Notice that value will be displayed as a String and not as an integer.

Maybe this will explain more to you:

Parameters:
Here is the detail of parameters:

i -- An int for which string representation would be returned.

Return Value:
toString(): This returns a String object representing the value of this Integer.

toString(int i): This returns a String object representing the specified integer.

Example:
public class Test{

public static void main(String args[]){
Integer x = 5;

System.out.println(x.toString());
System.out.println(Integer.toString(12));
}
}
This produces the following result:

5
12

Reply

RE: interfaces help #14
The toString() returns a string equivalent. For example:

int value = 30;
System.out.println(value.toString());

This code snippet would print out 30. Notice that value will be displayed as a String and not as an integer.

Maybe this will explain more to you:

Parameters:
Here is the detail of parameters:

i -- An int for which string representation would be returned.

Return Value:
toString(): This returns a String object representing the value of this Integer.

toString(int i): This returns a String object representing the specified integer.

Example:
public class Test{

public static void main(String args[]){
Integer x = 5;

System.out.println(x.toString());
System.out.println(Integer.toString(12));
}
}
This produces the following result:

5
12

Reply

RE: interfaces help #15
@darthjames226 yeah i know that toString but didnt understand the question anw i'll work on it and show you to make sure it's correct

well sry to bother you again but things didn't work well so i have to make a method called toString that return string values for name and for prices ?
but is toString() a method that already exist ?
i'm kind of lost here
(This post was last modified: 11-27-2013, 02:39 AM by LordPankake.)
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #16
@darthjames226 yeah i know that toString but didnt understand the question anw i'll work on it and show you to make sure it's correct

well sry to bother you again but things didn't work well so i have to make a method called toString that return string values for name and for prices ?
but is toString() a method that already exist ?
i'm kind of lost here
(This post was last modified: 11-27-2013, 02:39 AM by LordPankake.)
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #17
Not a problem at all. Yes that method already exists. Every object inherits the toString().

From the Object.toString() docs:

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

Reply

RE: interfaces help #18
Not a problem at all. Yes that method already exists. Every object inherits the toString().

From the Object.toString() docs:

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

Reply

RE: interfaces help #19
ok so if i do this public String toString(){
}
netbeans give me an error this error is fixed by adding @Override before it i have no idea what it does !!
now inside the toString() i need to write
retun name;(name is already a String)
now i tried String purchasePrice=purchasePrice.toString();
i get an error int cannot be dereferenced i have no idea what's wrong here
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: interfaces help #20
ok so if i do this public String toString(){
}
netbeans give me an error this error is fixed by adding @Override before it i have no idea what it does !!
now inside the toString() i need to write
retun name;(name is already a String)
now i tried String purchasePrice=purchasePrice.toString();
i get an error int cannot be dereferenced i have no idea what's wrong here
[Image: blackeagle_zps6ad86521.gif]

Reply