- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomparator.java
More file actions
Latest commit
93 lines (76 loc) · 2 KB
/
Copy pathcomparator.java
File metadata and controls
93 lines (76 loc) · 2 KB
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
importjava.util.Date;
importjava.text.SimpleDateFormat;
importjava.util.Objects;
importjava.util.LinkedList;
importjava.util.List;
importjava.util.*;
importjava.text.ParseException;
publicclassMain
{
publicstaticvoidmain(Stringargs[]) throwsException
{
List<Obst> liste = newLinkedList<>();
liste.add(newObst("31/05/1998", "banane", 4.00));
liste.add(newObst("22/12/1998", "banane", 4.00));
liste.add(newObst("25/12/1998", "banane", 4.00));
liste.add(newObst("24/02/1998", "banane", 4.00));
liste.add(newObst("01/10/1990", "banane", 4.00));
liste.add(newObst("07/09/1991", "banane", 4.00));
Collections.sort(liste, Obst.ObstComparators);
Obst.verfallsdatumAnzeigen(liste);
}
}
classVerfallsdatum
{
Stringdatum;
Verfallsdatum(Stringdatum)
{
this.datum = Objects.requireNonNull(datum," datum can not be null");
}
publicStringgetDatum()
{
returndatum;
}
publicstaticComparator<Obst> ObstComparators = newComparator<Obst>()
{
publicintcompare(Obstobst1, Obstobst2)
{
Datea = null;
Dateb = null;
try
{
a = newSimpleDateFormat("dd/MM/yyyy").parse(obst1.getDatum());
b = newSimpleDateFormat("dd/MM/yyyy").parse(obst2.getDatum());
}
catch (ParseExceptione)
{
System.err.println("leck eier");
}
returna.compareTo(b);
}
};
publicstaticvoidverfallsdatumAnzeigen(List<Obst> liste) throwsException
{
for (Obstobst : liste)
{
StringsDate = obst.getDatum();
Datedate = newSimpleDateFormat("dd/MM/yyyy").parse(sDate);
System.out.println(obst.getBezeichnung() +" "+obst.getDatum());
}
}
}
classObstextendsVerfallsdatum
{
Stringbezeichnung;
doublegewicht;
Obst(Stringdatum, Stringbezeichnung, doublegewicht)
{
super(datum);
this.bezeichnung = Objects.requireNonNull(bezeichnung, "weight can not be null!");
this.gewicht = Objects.requireNonNull(gewicht, "weight can not be null!");
}
publicStringgetBezeichnung()
{
returnbezeichnung;
}
}