Besoin d'aide pr l'affichage d'un treemap contenant un arraylist
Résolu
Euphoria S'
Messages postés
4
Statut
Membre
-
KX Messages postés 19031 Statut Modérateur -
KX Messages postés 19031 Statut Modérateur -
package tdRévision;
import java.util.*;
class Td {
public static void main(String args[]) {
// Create a tree map
TreeMap tm = new TreeMap();
// Put elements to the map
tm.put("John Doe", new Abonne(null, null, null, 0, 0));
tm.put("Tom Smith", new Abonne(null, null, null, 0, 0));
tm.put("Jane Baker", new Abonne(null, null, null, 0, 0));
tm.put("Todd Hall", new Abonne(null, null, null, 0, 0));
tm.put("Ralph Smith", new Abonne(null, null, null, 0, 0));
// Get a set of the entries
Set set = tm.entrySet();
// Get an iterator
Iterator i = set.iterator();
// Display elements
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.print("voila " +me.getKey() + ": ");
System.out.println(" revoila"+me.getValue());
}
System.out.println();
}
et voilà la classe Abonne
package tdRévision;
import java.util.ArrayList;
public class Abonne {
private String leNom,lePrenom,Adresse;
private double Salaire;
private long NumTelephone;
public Abonne(String nom ,String prenom,String adr,long numphon,double salary){
leNom=nom;
lePrenom=prenom;
NumTelephone=numphon;
Adresse=adr;
Salaire=salary;
}
public Abonne(String leNom, String lePrenom) {
super();
this.leNom = leNom;
this.lePrenom = lePrenom;
}
public String getLeNom() {
return leNom;
}
public void setLeNom(String leNom) {
this.leNom = leNom;
}
public String getLePrenom() {
return lePrenom;
}
public void setLePrenom(String lePrenom) {
this.lePrenom = lePrenom;
}
public String getAdresse() {
return Adresse;
}
public void setAdresse(String adresse) {
Adresse = adresse;
}
public double getSalaire() {
return Salaire;
}
public void setSalaire(double salaire) {
Salaire = salaire;
}
public long getNumTelephone() {
return NumTelephone;
}
public void setNumTelephone(long numTelephone) {
NumTelephone = numTelephone;
}
public static void main(String[] args) {
ArrayList<Abonne> tabAbonne=new ArrayList<Abonne>();
new Abonne("amira","aouissate");
Abonne a1=new Abonne("amira","aouissate");
Abonne a2=new Abonne("sara","Euphoria");
Abonne a3=new Abonne("steph","soux");
Abonne a4=new Abonne("cel", "hill");
Abonne a5=new Abonne("nanou","dumb");
Abonne a6=new Abonne("mawa","lilou");
Abonne a7=new Abonne("ptere","sander");
Abonne a8=new Abonne("charles","mccathienevile");
tabAbonne.add(a1);
tabAbonne.add(a2);
tabAbonne.add(a3);
tabAbonne.add(a4);
tabAbonne.add(a5);
tabAbonne.add(a6);
tabAbonne.add(a7);
tabAbonne.add(a8);
if(! tabAbonne.isEmpty()){
for(int i=0;i< tabAbonne.size();i++);
System.out.println(a1);
}
}
et voila ce qui s'affiche sur ma console :/
voila Jane Baker: revoila tdRévision.Abonne@19821f
voila John Doe: revoila tdRévision.Abonne@addbf1
voila Ralph Smith: revoila tdRévision.Abonne@42e816
voila Todd Hall: revoila tdRévision.Abonne@9304b1
voila Tom Smith: revoila tdRévision.Abonne@190d11
pourquoi ?
}
import java.util.*;
class Td {
public static void main(String args[]) {
// Create a tree map
TreeMap tm = new TreeMap();
// Put elements to the map
tm.put("John Doe", new Abonne(null, null, null, 0, 0));
tm.put("Tom Smith", new Abonne(null, null, null, 0, 0));
tm.put("Jane Baker", new Abonne(null, null, null, 0, 0));
tm.put("Todd Hall", new Abonne(null, null, null, 0, 0));
tm.put("Ralph Smith", new Abonne(null, null, null, 0, 0));
// Get a set of the entries
Set set = tm.entrySet();
// Get an iterator
Iterator i = set.iterator();
// Display elements
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.print("voila " +me.getKey() + ": ");
System.out.println(" revoila"+me.getValue());
}
System.out.println();
}
et voilà la classe Abonne
package tdRévision;
import java.util.ArrayList;
public class Abonne {
private String leNom,lePrenom,Adresse;
private double Salaire;
private long NumTelephone;
public Abonne(String nom ,String prenom,String adr,long numphon,double salary){
leNom=nom;
lePrenom=prenom;
NumTelephone=numphon;
Adresse=adr;
Salaire=salary;
}
public Abonne(String leNom, String lePrenom) {
super();
this.leNom = leNom;
this.lePrenom = lePrenom;
}
public String getLeNom() {
return leNom;
}
public void setLeNom(String leNom) {
this.leNom = leNom;
}
public String getLePrenom() {
return lePrenom;
}
public void setLePrenom(String lePrenom) {
this.lePrenom = lePrenom;
}
public String getAdresse() {
return Adresse;
}
public void setAdresse(String adresse) {
Adresse = adresse;
}
public double getSalaire() {
return Salaire;
}
public void setSalaire(double salaire) {
Salaire = salaire;
}
public long getNumTelephone() {
return NumTelephone;
}
public void setNumTelephone(long numTelephone) {
NumTelephone = numTelephone;
}
public static void main(String[] args) {
ArrayList<Abonne> tabAbonne=new ArrayList<Abonne>();
new Abonne("amira","aouissate");
Abonne a1=new Abonne("amira","aouissate");
Abonne a2=new Abonne("sara","Euphoria");
Abonne a3=new Abonne("steph","soux");
Abonne a4=new Abonne("cel", "hill");
Abonne a5=new Abonne("nanou","dumb");
Abonne a6=new Abonne("mawa","lilou");
Abonne a7=new Abonne("ptere","sander");
Abonne a8=new Abonne("charles","mccathienevile");
tabAbonne.add(a1);
tabAbonne.add(a2);
tabAbonne.add(a3);
tabAbonne.add(a4);
tabAbonne.add(a5);
tabAbonne.add(a6);
tabAbonne.add(a7);
tabAbonne.add(a8);
if(! tabAbonne.isEmpty()){
for(int i=0;i< tabAbonne.size();i++);
System.out.println(a1);
}
}
et voila ce qui s'affiche sur ma console :/
voila Jane Baker: revoila tdRévision.Abonne@19821f
voila John Doe: revoila tdRévision.Abonne@addbf1
voila Ralph Smith: revoila tdRévision.Abonne@42e816
voila Todd Hall: revoila tdRévision.Abonne@9304b1
voila Tom Smith: revoila tdRévision.Abonne@190d11
pourquoi ?
}
A voir également:
- Besoin d'aide pr l'affichage d'un treemap contenant un arraylist
- Double affichage sur un seul écran - Guide
- Windows 11 affichage classique - Guide
- Problème affichage fenêtre windows 10 - Guide
- Excel sélectionner toutes les lignes contenant un mot ✓ - Forum Excel
- Affichage youtube trop grand ✓ - Forum YouTube
voila Jane Baker: revoilaAbonne [leNom=null, lePrenom=null, Adresse=null, Salaire=0.0, NumTelephone=0]
voila John Doe: revoilaAbonne [leNom=null, lePrenom=null, Adresse=null, Salaire=0.0, NumTelephone=0]
voila Ralph Smith: revoilaAbonne [leNom=null, lePrenom=null, Adresse=null, Salaire=0.0, NumTelephone=0]
voila Todd Hall: revoilaAbonne [leNom=null, lePrenom=null, Adresse=null, Salaire=0.0, NumTelephone=0]
voila Tom Smith: revoilaAbonne [leNom=null, lePrenom=null, Adresse=null, Salaire=0.0, NumTelephone=0]
et quand par exemple j'essaye de changer la ligne 1 :
tm.put("John Doe", new Abonne(null, null, null, 0, 0));
de façon à remplacer les valeurs null par des chaines de caractéres et les 0 par des int un message d'erreur est signalé !