Bonjour..... Comment faire utiliser le résultat d'une classe dans une autre classe ...j'ai cette classe qui affiche le maximum et minimum et le pas des entier (Long) qui sont dans un fichier ...
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 package jh; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class AltitudeReading { private static final String FILENAME = "D:\\Doc\\java\\eq\\jh\\src\\jh\\altitude.in"; public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) { String sCurrentLine; long n; long maxVal = Long.MAX_VALUE; long minVal = Long.MIN_VALUE; long somme = 0; long pas = 0; int j = 0; while ((sCurrentLine = br.readLine()) != null) { n = Long.valueOf( sCurrentLine).longValue(); long array[]= {n}; for(int i = 0; i < array.length; i++){ j++; if(array[i] < maxVal) maxVal = array[i]; if(array[i] > minVal) minVal = array[i]; somme = somme+array[i]; pas=somme/38; } } System.out.print("\nValeur minimale = "+maxVal); System.out.print("\nValeur maximale = "+minVal); System.out.print("\nLa somme = "+somme); System.out.print("\nLe nombre de valeurs = "+j); System.out.print("\nLe pas = "+pas); } catch (IOException e) { e.printStackTrace(); } } }
Je veut utiliser le variable ''maxVal'' ; minVal ; ''pas'' dans une autre classe qui est la suivante :
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 package application; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.chart.AreaChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage stage) { stage.setTitle("Area Chart Sample"); long a,b,pas; AltitudeReading Rd =new AltitudeReading(); a=Rd.minVal; //valeur minimal dans le fichier utilisée comme valeur min dans le barre d'abscisse b=Rd.maxVal; //valeur maximale dans le fichier utilisée comme valeur max dans le barre d'abscisse c=Rd.pas; //valeur correspand au pas dans le barre d'abscisse final NumberAxis xAxis = new NumberAxis(a, b, c); // a,b,c correspand aux minVal ,maxVal ,pas; final NumberAxis yAxis = new NumberAxis(-5, 27, 5); final AreaChart<Number,Number> ac = new AreaChart<Number,Number>(xAxis,yAxis); xAxis.setForceZeroInRange(true); ac.setTitle("Temperature Monitoring (in Degrees C)"); XYChart.Series series1 = new XYChart.Series(); series1.setName("Graph1"); series1.getData().add(new XYChart.Data(0, -2)); series1.getData().add(new XYChart.Data(3, -4)); series1.getData().add(new XYChart.Data(6, 0)); series1.getData().add(new XYChart.Data(9, 5)); XYChart.Series series2 = new XYChart.Series(); series2.setName("Graph2"); series2.getData().add(new XYChart.Data(0, 4)); series2.getData().add(new XYChart.Data(3, 10)); series2.getData().add(new XYChart.Data(6, 15)); series2.getData().add(new XYChart.Data(9, 8)); XYChart.Series series3 = new XYChart.Series(); series3.setName("Graph3"); series3.getData().add(new XYChart.Data(0, 20)); series3.getData().add(new XYChart.Data(3, 15)); series3.getData().add(new XYChart.Data(6, 13)); series3.getData().add(new XYChart.Data(9, 12)); Scene scene = new Scene(ac,800,600); //scene.getStylesheets().add("areachartsample/Chart.css"); ac.setHorizontalZeroLineVisible(true); ac.getData().addAll(series1, series2, series3); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
le fichier altitude est remplie par ces valeurs :
Code TXT : 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 15 50 55 556 484558 187897 585866 654589 693285 639878 364598 821430 473106 165720 458231 562314 109876 1098687662214 8765695522266 5544456569889 3021558966321 1111122233333333332 2222222222222222222 3333333333333333333 4444444444444444444 5555555555555555555 6666666666666666666 7777777777777777777 8888888888888888888 1111111111111111111 5555555555555555555 7777777777777777777 3333333333333333333 1111111111111111111 9000000000000000000 9000000000000000001 9099999999999999999 9199999999999999999
Partager