CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Java->Aide pour une ArrayList

spideyback
spideyback
Niveau 6
05 février 2009 à 21:39:39

:salut:
deja c'est gentil de venir voir de quoi il en retourne,
donc en fait j'ais fait un mini repertoire en java, mais le prof veut que l'on utilise une arraylist a la place d'un tableau o_O..
pui aussi ajouter quelques fonction, si quelqu'un qui si connait en langage java pouvait me degager mon tableau et m'installer une arraylist ba ça serait vraiment simpa, le prof veut aussi que nous ajoutions une fonction supprimer, et le pire, une fonction qui sauvgarder et retaure les donnée du repertoire.

Je poste les sources :

----Class repertoire:

import java.io.*;
import java.util.*;
public class repertoire {
public static void main(String[] args) throws IOException {

Individu tab[];
tab = new Individu[100];
int nbreIndividu = 0;
int choix;
do {
choix = menu();
switch( choix ) {
case 1:
nbreIndividu = ajouter( tab, nbreIndividu );
break;
case 2:
afficher( tab, nbreIndividu );
break;
case 3:
moyenne( tab, nbreIndividu );
break;
case 4:
chercher( tab, nbreIndividu );
break;
case 5:
return;
default:
System.out.println(
"erreur : saisissez un choix entre 1 et 5 SVP.");
}
} while( choix != 5 );
}
public static int menu() throws IOException {
BufferedReader clavier = new BufferedReader(
new InputStreamReader( System.in ));
String reponse;
int choix;
System.out.println( "1 - ajouter une fiche" );
System.out.println( "2 - afficher les fiches" );
System.out.println( "3 - calculer la moyenne d'age" );
System.out.println( "4 - rechercher une fiche" );
System.out.println( "5 - quitter le programme" );
System.out.println( "tapez un nombre entre 1 et 5 SVP" );
reponse = clavier.readLine();
choix = Integer.parseInt( reponse );
return choix;
}
public static int ajouter( Individu tab[], int nbreIndividu )
throws IOException {
BufferedReader clavier = new BufferedReader(
new InputStreamReader( System.in ));
String n,p,a,t;
int ag;
System.out.println( "entrez le nom :" );
n = clavier.readLine();
System.out.println( "entrez le prenom :" );
p = clavier.readLine();
System.out.println( "entrez l'adresse :" );
a = clavier.readLine();
System.out.println( "entrez le telephone :" );
t = clavier.readLine();
System.out.println( "entrez l'age :" );
ag = Integer.parseInt( clavier.readLine() );
tab[nbreIndividu] = new Individu( n, p, a, t, ag );
nbreIndividu++;
return nbreIndividu;
}
public static void afficher( Individu tab[], int nbreIndividu )
throws IOException {
BufferedReader clavier = new BufferedReader(
new InputStreamReader( System.in ));
int i;
for( i = 0; i < nbreIndividu; i++ ) {
tab[i].affiche();
System.out.println( "appuyer sur entrée pour voir la suite" );
clavier.readLine();
}
}
public static void moyenne( Individu tab[], int nbreIndividu ) {
int i;
int somme = 0;
float moyenne;
for( i = 0; i < nbreIndividu; i++ ) {
somme = somme + tab[i].getAge();
}
moyenne = (float)somme / nbreIndividu ;
System.out.println( "moyenne d'age : " + moyenne );
}
public static void chercher( Individu tab[], int nbreIndividu )
throws IOException {
BufferedReader clavier = new BufferedReader(
new InputStreamReader( System.in ));
int i;
String n;
System.out.println( "entrez le nom de la personne a rechercher " );
n = clavier.readLine();
for( i = 0; i < nbreIndividu; i++ ) {
if( n.compareTo(tab[i].getNom() ) == 0 ) {
tab[i].affiche();
System.out.println(
"appuyer sur entrée pour voir la suite" );
clavier.readLine();
}
}
}
}

----Classe Individu:

class Individu {
private String nom;
private String prenom;
private String adresse;
private String telephone;
private int age;
public Individu( String n, String p, String a, String t, int ag ) {
nom = n;
prenom = p;
adresse = a;
telephone = t;
age = ag;
}
public void affiche() {
System.out.println( "nom : " + nom );
System.out.println( "prenom : " + prenom );
System.out.println( "adresse : " + adresse );
System.out.println( "telephone : " + telephone );
System.out.println( "age : " + age );
}
public int getAge() {
return age;
}
public String getNom() {
return nom;
}
}

:merci:

Thommas
Thommas
Niveau 7
05 février 2009 à 22:22:17

Tu veux aussi qu'on fasse le café ?

Thommas
Thommas
Niveau 7
05 février 2009 à 22:23:48

Un peu de lecture :
http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html

Et ce soir tu t'endormiras un peu moins bête ;-)

Sous forums
  • Aide à l'achat Mac
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Internet
  • Steam Deck
  • Macintosh
  • Hardware
La vidéo du moment