(11-27-2013, 02:07 AM)darthjames226 Wrote: 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.
This code snippet is wrong and the problems above actually came from your example. If you provide snippets to programming beginners, make sure they are working and do not create more problems than helping.
(11-27-2013, 03:36 AM)darthjames226 Wrote: 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.
That is nonsense.
Sorry about that. My value variable should have been declared as type Integer instead of int in my code snippet. The second explanation under that original post was perfectly fine. As for all the advice I provided, I am no pro Java programmer. I was just trying to help a fellow programmer troubleshoot a bug in his program at a time of need. No one else was trying to help him so I took the initiative and intervened. If my advice is wrong then let me know so I can learn from my mistakes. I was simply trying to help.
(11-27-2013, 02:07 AM)darthjames226 Wrote: 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.
This code snippet is wrong and the problems above actually came from your example. If you provide snippets to programming beginners, make sure they are working and do not create more problems than helping.
(11-27-2013, 03:36 AM)darthjames226 Wrote: 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.
That is nonsense.
Sorry about that. My value variable should have been declared as type Integer instead of int in my code snippet. The second explanation under that original post was perfectly fine. As for all the advice I provided, I am no pro Java programmer. I was just trying to help a fellow programmer troubleshoot a bug in his program at a time of need. No one else was trying to help him so I took the initiative and intervened. If my advice is wrong then let me know so I can learn from my mistakes. I was simply trying to help.
(11-27-2013, 02:58 PM)blackeagle Wrote: @Deque ok thank you very much still have 1 more question on my mind if i have 3 classes is it possible to use the same method name inside the 3 classes !!
i.e:in first class
public void info(){
}
second class
public void info(){
super.info()
and i add something more}
i want to do this but netbeans tell me in the second class that the method already exist and i need to override it!!
if i do so i wont be able to use the first 1 ?
Yes, you can use methods with the same name in different classes.
But in your case--if Netbeans wants you to put an override annotation--you have used inheritance.
That means you inherit the method of the parent class and making another method with the same name means you override it (you create a new implementation).
You can still use the method of the parent class by using super.
I.e.
Code:
super.info() //calls method info() of the parent class
And if you want to use the method of your current class you just call
Code:
info()
(11-28-2013, 12:39 AM)blackeagle Wrote: i was able to do this part !! i did everything and i guess everything is fine !!
Spoiler:
Code:
Write an application to manage the stock of a store.
Here is a specification of the program in terms of classes and interfaces:
interfaces
Salable per kilogram : the interface for selling items per kilogram
methods:
Sale : This method receives the quantity sold of the item and change the stock
Salable piece : the interface for items that sell by pieces
methods:
Sale : This method receives the number of rooms sold the item and change the stock
Likely to be sold in balance
methods:
start balance : This method lowers the price of the item by the given percentage
complete the balance : This method increases the price of the item by the given percentage
classes
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 - prixAchat ) / prixAchat )
toString (): return the name and price of the item
This class does not implement any interface.
Two derived class Articles classes:
Class artciles Appliance
Aditional property : the number of items in stock
Additional methods ( other than the manufacturer):
Add a number of pieces in stock
toString (): return the name , the price of the item and the number of parts
You must implement the corresponding interfaces this class .
Class articles futures
Additional property : quantity in stock
Additional methods:
Add the stock quantity
toString (): return the name , the price of the item and the quantity in stock
You must implement the corresponding interfaces this class , knowing that the items futures can not be sold on sale.
now i have a new part
Spoiler:
Code:
class Store
Properties: a vector (Vector)
Methods (other than the manufacturer):
Add product to the vector
Save name, purchase price and selling price of all items in the futures vector "Primeurs.data" file properties
Save all items appliances (as instances) of the vector in the "Electro.data" file
Save the information generated by toString all items in the vector file "info.data"
Print file information "info.java"
Read "Primeurs.data" file and print the name and the performance of each primary article.
Read "Electro.data" file and print the number and performance of each article appliances.
can some1 give me and exemple n how to do this ? i know how to save to a file and read from a file i have it in a course thats not my problem but what i did here is :
Code:
import java.util.Vector;
public class Store {
Vector vecteur = new Vector();
public Store(){
vecteur=null;
}
public void addArticle(Article article){
vecteur.addElement(article);
}
i need to know how should i do this step: Save name, purchase price and selling price of all items in the futures vector "Primeurs.data" file properties
hope any1 can help and i'm sry i feel like i'm a pain to every1 here
I am not sure that I understand the task correctly.
Are you supposed to save the information (name, purchase price, selling price) in the vector or in the file? What are file properties for you?
I guess the translation is a bit akward.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.
@Deque sry for this i used google translate but i'll make a summery of what i need !!
in the class shop i need to create a vector a method to add an article to the vector article is an item for exemple tv ...
i have a class article already made and 2 classes articles electromenager and article primeur that extands from articles and inheritate some interfaces electromenager is for exemple a tv that we can make a sold on end the quantty is always an int!!
article primeur is sold in kilogram !! so it inheritates the interface salable by kilo!!
now i need to save name salePrice purchasePrice of every primeur article in the vecteur in a file called Primeur.data
i dont know how to get all the primeur articles from the vecteur and save them
(This post was last modified: 11-28-2013, 10:28 PM by LordPankake.)
(11-28-2013, 10:27 PM)blackeagle Wrote: @Deque sry for this i used google translate but i'll make a summery of what i need !!
in the class shop i need to create a vector a method to add an article to the vector article is an item for exemple tv ...
i have a class article already made and 2 classes articles electromenager and article primeur that extands from articles and inheritate some interfaces electromenager is for exemple a tv that we can make a sold on end the quantty is always an int!!
article primeur is sold in kilogram !! so it inheritates the interface salable by kilo!!
now i need to save name salePrice purchasePrice of every primeur article in the vecteur in a file called Primeur.data
i dont know how to get all the primeur articles from the vecteur and save them
But you know how to write to a file?
Then do something like:
@Deque yes it wont be that big problem to write to a file but what i want is :
the article has to subclass articleprimeur and articleelectromenager i want to search the vecteur right the info abot articleprimeur in a file primeur and the info of artile electromenager in a file called electromenager!!
what i dont now is how to check if the article is primeur or electromenager !!
(11-27-2013, 02:18 PM)blackeagle Wrote: 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 ?