Bonjour,
Je souhaite créer un petit programme qui permettrait de simuler un magasin.
J'ai donc commencé par la classe relative aux données des clients, et je rencontre un problème que je n'arrive pas à résoudre :/
Pour l'âge du client, peu importe celui que je rentre, la donnée qu'il me ressort à la fin est -1. (soit la donnée par défaut de ma classe client). J'ai essayé en int et en double, aucun des deux ne résout le problème.
Je suis un pur débutant en programmation et je suis donc venu chercher de l'aide ici, j'espère que vous pourrez m'aidez à résoudre ce problème qui me donne envie de m'arracher les cheveux...
Donc voilà ma classe main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 import java.util.ArrayList;
import java.util.Scanner;
public class main {
 
	public static void main(String[] args) {
//-----------------------------------------------------------------------------
		ArrayList listeClients = new ArrayList();
		Scanner ss = new Scanner(System.in);
		Scanner si = new Scanner(System.in);
		Scanner sd = new Scanner(System.in);
		Scanner sb = new Scanner(System.in);
		double age;
		String nom = "";
		String commune ="";
		double tarif = 0;
		boolean restart = true;
		boolean tf;
//----------------------------------------------------------------------
		while (restart==true)
		{
			System.out.println("Age du client?");
			age = sd.nextDouble();
			System.out.println("Nom du client?");
			nom = ss.nextLine();
			System.out.println("Commune du client?");
			commune = ss.nextLine();
			System.out.println("Tarif client?");
			tarif = sd.nextDouble();
			Client addClient = new Client(age, nom, commune, tarif);
			listeClients.add(addClient);
			addClient.setAgeClient(age);
			System.out.println("Introduire un autre client?(true/false)");
				tf = sb.nextBoolean();
				if (tf == false)
				{
					restart = false;
				}
		}
//------------------------------------------------------------------------
		System.out.println("Souhaitez vous revoir un client en particulier?(true/false)");
		boolean revoirClients = sb.nextBoolean();
		boolean revoirTousClients;
		Client allTemp = new Client();
		int iFocus = 0;
		int iAll=0;
		if (revoirClients == true)
		{
			System.out.println("Quel est le numéro du client que vous souhaitez revoir? (En commençant à 0)");
			System.out.println("Pour rappel vous avez enrengistré "+listeClients.size()+" client(s).");
			iFocus = si.nextInt();
			Client focus = (Client) listeClients.get(iFocus);
			printClient(focus);
		}
		else if (revoirClients == false)
		{
			System.out.println("Souhaitez vous revoir tous les clients?(true/false)");
			revoirTousClients = sb.nextBoolean();
			if (revoirTousClients == true)
			{
				while(iAll < listeClients.size())
				{
					allTemp = (Client) listeClients.get(iAll);
					printClient(allTemp);
					iAll = iAll+1;
				}
			}
			else if(revoirTousClients==false)
			{
				System.out.println("Au revoir !");
			}
		}
 
 
//------------------------------------------------------------------------
 
 
//-----------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
	}
 
	public static void printClient(Client client)
	{
		double age = Client.getAgeClient();
		System.out.println("Monsieur/madame "+client.getNomClient()+", originaire de la commune de "+client.getCommuneClient()+" et agé(e) de "+age+" ans, nous doit "+client.getTarifClient()+" euros.");
	}
}
Et ma classe Client :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
public class Client {
 
	private static double ageClient;
	private String nomClient;
	private String communeClient;
	private double tarifClient;
	//----------------------------------------------------------
		public Client()
		{
			ageClient = -1;
			nomClient = "inconnu";
			communeClient = "inconnue";
			tarifClient = 0;
		}
	//-----------------------------------------------------------
		public Client(double pAgeClient, String pNomClient, String pCommuneClient, double pTarifClient)
		{
			ageClient = pAgeClient;
			nomClient = pNomClient;
			communeClient = pCommuneClient;
			tarifClient = pTarifClient;
		}
	//---------------------------------------------------------------
		//GET
		public static double getAgeClient()
		{
			return ageClient;
		}
 
		public String getNomClient()
		{
			return nomClient;
		}
 
		public String getCommuneClient()
		{
			return communeClient;
		}
 
		public double getTarifClient()
		{
			return tarifClient;
		}
 
	//------------------------------------------------------------------
		//SET
		public void setAgeClient(double newAge)
		{
			ageClient = newAge;
		}
 
		public void setNomClient(String newName)
		{
			nomClient = newName;
		}
 
		public void setCommuneClient(String newCommune)
		{
			communeClient = newCommune;
		}
 
		public void setTarifClient(double newTarif)
		{
			tarifClient = newTarif;
		}
	//-------------------------------------------------------------------
 
 
 
 
 
 
 
}