![]() |
|
interfaces help - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Java, JVM, & JRE (https://sinister.ly/Forum-Java-JVM-JRE) +--- Thread: interfaces help (/Thread-interfaces-help) |
RE: interfaces help - darthjames226 - 11-28-2013 (11-27-2013, 02:29 PM)Deque Wrote: @blackeagle: 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. RE: interfaces help - darthjames226 - 11-28-2013 (11-27-2013, 02:29 PM)Deque Wrote: @blackeagle: 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. RE: interfaces help - Deque - 11-28-2013 (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 !! 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 classAnd 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 !! 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. RE: interfaces help - blackeagle - 11-28-2013 @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 RE: interfaces help - Deque - 11-29-2013 (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 !! But you know how to write to a file? Then do something like: Code: for(Article article : vecteur) {
writeToFile("name:" + article.getName());
writeToFile("saleprice:" + article.getSalePrice());
writeToFile("purchaseprice:" + article.getPurchasePrice());
}Note: There is no such method like writeToFile. You would have to create it yourself. It just shows you how to get the articles and their fields. RE: interfaces help - blackeagle - 11-29-2013 @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 !! RE: interfaces help - Psycho_Coder - 11-30-2013 (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 !! http://www.javaprogrammingforums.com/object-oriented-programming/3158-importance-interfaces.html#post8399 interfaces help us implementing polymorphism and Open/Closed principle. http://en.wikipedia.org/wiki/Open/closed_principle Read this : http://www.artima.com/interfacedesign/SigInterface.html RE: interfaces help - Deque - 11-30-2013 (11-29-2013, 11:00 PM)blackeagle Wrote: what i dont now is how to check if the article is primeur or electromenager !! Code: if (article instanceof Primeur) |