473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

problem with my programme

132 100+
Hello ,

please can any one help me for my this i don't know why didn't gave me my return true he juste return this :les magasins situés dans la ville projetd314.ListeMagasin@a401c2
why see my code
Expand|Select|Wrap|Line Numbers
  1. public interface IMagasin {
  2. public double getLatitude();
  3. public double getLongitude();
  4. public String getCode();
  5. public String getVille();
  6. public void setLatitude(double l);
  7. public void setLongitude(double lon);
  8. public void setCode(String string);
  9. public void setVille(String string);
  10. }
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package projetd314;
  7. import java.sql.*;
  8. import java.sql.PreparedStatement;
  9. import java.lang.Math.*;
  10. import java.util.Vector;
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. public class Magasin {
  18.     static java.sql.Connection c=null;
  19. double latitude=0;
  20. double longitude=0;
  21. String codeville="";
  22. String ville="";
  23. public double getLatitude(){
  24.     return latitude;
  25. }
  26. public double getLongitude(){
  27.         return longitude;
  28.         }
  29. public String getCode(){
  30.     return codeville;
  31. }
  32. public String getVille(){
  33.     return ville;
  34. }
  35. public void setLatitude(double l){
  36.     latitude=l;
  37. }
  38. public void setLongitude(double lon){
  39.     longitude=lon;
  40. }
  41. public void setCode(String string){
  42.     codeville=string;
  43.  
  44. }
  45. public void setVille(String string){
  46.     ville=string;
  47. }
  48.  
  49.  
  50.     }
  51.  
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package projetd314;
  7. import projetd314.IMagasin;
  8. import projetd314.ListeMagasin;
  9. import projetd314.ListeMagasinAdapter;
  10. import projetd314.Magasin;
  11. import java.sql.Connection;
  12. import java.sql.DriverManager;
  13. import java.sql.PreparedStatement;
  14. import java.sql.ResultSet;
  15. import java.sql.SQLException;
  16. import java.util.Vector;
  17.  
  18.  
  19.  
  20.  
  21. public class MagasinServices {
  22.     public  ListeMagasin listeMagasin=new ListeMagasin();
  23.     static java.sql.Connection c=null;
  24.     public static void etablirConnexion(){
  25.         String pilote="com.mysql.jdbc.Driver";
  26.         try{Class.forName(pilote).newInstance();}
  27.         catch(Exception e){System.out.println("echec pilote :"+e);
  28.         }
  29.         String url="jdbc:mysql://localhost:3306/boutiquegeographique";String user="root";String password="";
  30.         try{c=DriverManager.getConnection(url,user,password);
  31.  
  32.         }
  33.         catch(SQLException e){System.out.println("echec connection a la bdd :"+e);}
  34.  
  35.     }
  36.  
  37.         public  ListeMagasin listMagasinsVille(String nomville)
  38.         {
  39.                      double latitude;
  40.                    double l;
  41.                 if(Magasin.c==null) etablirConnexion();
  42.       try{
  43.                         PreparedStatement st=c.prepareStatement("select latitude,longitude,nomville from liste_magasins where nomville=?");
  44.                         st.setString(1, nomville);
  45.                         ResultSet rs=st.executeQuery();
  46.  
  47.                 while(rs.next())
  48.                 {
  49.                         Magasin m=new Magasin();
  50.                         m.setLatitude(rs.getDouble("latitude"));
  51.                         m.setLongitude(rs.getDouble("longitude"));
  52.                         m.setVille(rs.getString("nomville"));
  53.                         listeMagasin.addMagasin(m);
  54.                }
  55.           }catch(Exception e){System.out.println("erreur selection"+e);}
  56.            return  listeMagasin;
  57.     }
  58.  
  59.  
  60.  
  61. }
  62.  
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package projetd314;
  7.  
  8. import java.util.Vector;
  9.  
  10. /**
  11.  *
  12.  * @author kamar
  13.  */
  14. public class ListeMagasinAdapter {
  15. public IMagasin[] liste;
  16. public ListeMagasinAdapter(ListeMagasin obj){
  17.    Vector<IMagasin>  l=obj.getListe();
  18.    liste =l.toArray(new IMagasin[l.size()]);
  19. }
  20. public IMagasin[] getListe(){
  21.     return liste;
  22. }
  23. public void setListe(IMagasin[] liste){
  24.     this.liste=liste;
  25. }
  26. }
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package projetd314;
  7.  
  8. import java.util.Iterator;
  9. import java.util.Vector;
  10.  
  11.  
  12. public class ListeMagasin {
  13.     private Vector liste=new Vector();
  14.     public Magasin getMagasin(int i){
  15.         return (Magasin)liste.get(i);
  16.     }
  17.  
  18.     public Vector getListe(){
  19.         return liste;
  20.     }
  21.     public void setListe(Vector liste){
  22.         this.liste=liste;
  23.  
  24.     }
  25.     public void addMagasin(Magasin m){
  26.         int i;
  27.         for(i=0;i<liste.size();i++)
  28.         {
  29.             liste.add(m);
  30.                 return;
  31.  
  32.         }
  33.         liste.add(m);
  34.     }
  35.     public String listMagasinsVille(String nomville){
  36.  
  37.     Iterator  iterateur=liste.iterator();
  38.     String str="";
  39.     while(iterateur.hasNext())
  40.     {
  41.         Magasin ma=(Magasin)iterateur.next();
  42.         String v=ma.getVille();
  43.         if(nomville==v){
  44.             double lat=ma.getLatitude();
  45.             double lon=ma.getLongitude();
  46.             str+="Latitude:"+lat+"Longitude:"+lon+"\n";}
  47.     }
  48.     return str;
  49.     }
  50.  
  51. }
  52.  
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package projetd314;
  7.  
  8.  
  9. public class Main {
  10.  
  11.     /**
  12.      * @param args the command line arguments
  13.      */
  14.     public static void main(String[] args) {
  15.         MagasinServices c=new MagasinServices();
  16.        System.out.println("les magasins situés dans la ville "+c.listMagasinsVille("Amiens"));
  17.     }
  18.  
  19. }
  20.  
thanks
Nov 23 '09 #1
6 1715
pbrockway2
151 Expert 100+
That's a lot of code for a small question!

Anyway, if you want a ListeMagasin instance to print nicely you need to give the class a toString() method. println() will use this to create the string to be printed.

Expand|Select|Wrap|Line Numbers
  1. public class ListeMagasin {
  2.  
  3.     // other stuff
  4.  
  5.     public String toString() {
  6.         // use a StringBuilder and loop over the Vector contents?
  7.         // or use the vector toString() method
  8.         // or etc
  9.         return "some string that describes the magasin list";
  10.     }
  11. }
  12.  
Why are using Vector rather than one of the other list implementations?
Nov 23 '09 #2
manjava
132 100+
hello,

i want to call my method listMagasinsVille(String nomville) but the return this les magasins situés dans la ville projetd314.ListeMagasin@c51355

why please help me

thanks
Nov 23 '09 #3
Frinavale
9,735 Expert Mod 8TB
Please re-read the suggestion that pbrockway2 posted.

You need to write a ToString() method for your ListeMagasin class. If you do not write a ToString() method for the class then the default ToString method is used. The Default ToString method returns you "projetd314.ListeMagasin@c51355" which doesn't make much sense.

Expand|Select|Wrap|Line Numbers
  1. public class ListeMagasin {
  2. //....Other Stuff .....//
  3. public String ToString(){
  4.    Iterator  iterateur=liste.iterator();
  5.    String str="";
  6.    while(iterateur.hasNext())
  7.    {
  8.          Magasin ma=(Magasin)iterateur.next();
  9.          String v=ma.getVille();
  10.          if(nomville==v){
  11.              double lat=ma.getLatitude();
  12.              double lon=ma.getLongitude();
  13.              str+="Latitude:"+lat.ToString()+" Longitude:"+lon.ToString()+"\n";}
  14.    }
  15.    return str;
  16. }
Then call the ToString Method:
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Main {
  3.  
  4.     /**
  5.      * @param args the command line arguments
  6.      */
  7.     public static void main(String[] args) {
  8.         MagasinServices c=new MagasinServices();
  9.        System.out.println("les magasins situés dans la ville "+c.listMagasinsVille("Amiens").ToString());
  10.     }
  11.  
  12. }
Nov 23 '09 #4
manjava
132 100+
i put my method listMagasinsVille in class and ADD the method ToString but there somme body
Expand|Select|Wrap|Line Numbers
  1. { Iterator  iterateur=liste.iterator();
  2.     String str="";
  3.     while(iterateur.hasNext())
  4.     {
  5.         Magasin ma=(Magasin)iterateur.next();
  6.         String v=ma.getVille();
  7.         if(nomville==v){
  8.             double lat=ma.getLatitude();
  9.             double lon=ma.getLongitude();
  10.             str+="Latitude:"+lat+"Longitude:"+lon+"\n";}
  11.     }
  12.     return str;
  13.     }
CAN YOU TELL ME WHAT I PUT IN MY CLASS listmagasin

thank you for help
Nov 23 '09 #5
pbrockway2
151 Expert 100+
But note that toString() should start with a lower case "t". And the methods cannot be applied to primitive values. So one possible way of building up the string could be:

Expand|Select|Wrap|Line Numbers
  1. //str+="Latitude:"+lat.ToString()+" Longitude:"+lon.ToString()+"\n";
  2. str += "Latitude: "  + lat + " Longitude: " + lon + "\n";
  3.  
(as I think you had)

Also note that you can't really compare strings with ==. So "v.equals(nomville)" not "nomville==v".
Nov 23 '09 #6
manjava
132 100+
thank you for your help
Nov 24 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Markus von Ehr | last post by:
Hi everybody, I use xml_pickle to write xml files. Trying to load them with: xml_str = f.read() xml_pickle.MyClass = MyClass obj = xml_pickle.XML_Pickler().loads(xml_str)) f.close()
1
by: Martin Stettner | last post by:
Hi, when trying to generate the wrapper classes for Microsofts ADO Library (Version 2.8) with makepy, I run into the following problem. Here's what I do (I use ActiveState Python 2.4.1.245) ...
2
by: M Maloney | last post by:
Hey all, I was wondering if anyone could help me with this problem I have: Given a text file like this: 8 =ABC 18.00 Dr Who: Underworld 18.30 Collectors 19.00 News
0
by: Josef Cihal | last post by:
Hi, I get an error, when I am trying to download URL with using Cookies. Where is the Problem? Thank u very much for all ideas!!! sincerely Josef
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
2
by: samar | last post by:
I have a C++ programme in MPI-environment which reads its Input from a file previously made by another C++ programme , but now I face a problem , the new programme can't read that data from the...
17
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the...
3
by: Daniel Loose | last post by:
hello, try to install php 5.2 on apache 1.3 on winxp. apache is fine. php says on start "unable to load dynamic library '<path>' " -- but <path> *does* exist! extension_dir...
4
by: Jon | last post by:
I wrote a VS 2005 C# express programme that accesses a web service. It works fine when there's a direct connection to the internet, but on two different PCs with internet access via a proxy, I get...
1
by: mrsmith221189 | last post by:
Hello everyone. I'm a novice to XML/XSL so it would be great to learn from the experts. The ouput of my xml file is BBC EPG(Electronic Programme Guide) table. I'm having problems defining a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.