-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL8Auto.java
More file actions
114 lines (96 loc) · 2.96 KB
/
Copy pathL8Auto.java
File metadata and controls
114 lines (96 loc) · 2.96 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
public class L8Auto extends L8Fahrzeug {
private String fahrgestellNr;
private int ps;
private String typ;
private float hubraum;
private int gewicht;
//Constructor
public L8Auto(){
}
public L8Auto(String fahrgestellNr, int ps, String typ, float hubraum) {
this(fahrgestellNr);
this.ps = ps;
this.typ = typ;
this.hubraum = hubraum;
}
public L8Auto(String hersteller, String fahrgestellNr, int ps, String typ, float hubraum) {
super(hersteller);
this.fahrgestellNr = fahrgestellNr;
this.ps = ps;
this.typ = typ;
this.hubraum = hubraum;
}
public L8Auto(int ps, int gewicht){
}
public L8Auto(int ps){
this.ps = ps;
}
// Überladen funktioniert nur mit ungleichen parameterlisten
// Würde nicht funktionieren, weil es 2 Konstruktoren mit Strings gibt
// public L8Auto(String fahrgestellNr){
// this.fahrgestellNr = fahrgestellNr;
// }
public L8Auto(String fahrgestellNr){
this();
this.fahrgestellNr=fahrgestellNr;
}
//setter
public void setPs(int ps) {
this.ps = ps;
}
public void setTyp(String typ) {
this.typ = typ;
}
public void setHubraum(float hubraum) {
this.hubraum = hubraum;
}
public void setFahrgestellNr(String fgnr) {
this.fahrgestellNr = fgnr;
}
public void setGewicht(int gewicht){
this.gewicht= gewicht;
}
//gibt objekt als string aus
public String toString(){
return "Fahrgestellnummer:" + this.fahrgestellNr + ", " + this.typ + " mit " + this.hubraum + "l Hubraum und " + this.ps + "PS" + " von " + this.hersteller + "und wiegt in kg: " + this.gewicht;
}
//Leistungsgewicht berechnen, Exeption Beispiel
//Exception wird direkt im Programm gecatcht.
/*public float berechneLeistungsgewicht(int gewicht){
float lg = 0;
try{ //kritische anweisung
lg = this.ps / gewicht;
}
catch(Exception e) {
System.out.println("division durch 0");
} //alles nach dem catch block, wird nicht ausgeführt, wenn fehler gefangen wird.
finally {
return lg;
}
}
*/
//Exception wird per throw gehandled
public float berechneLeistungsgewicht(int gewicht) throws ArithmeticException{
float lg = 0;
lg = this.ps / (float)gewicht;
return lg;
}
//Leistungsberechnung mit eigener Exception
public float berechneLeistungsgewichtMeldung(int gewicht) throws L8GewichtNullException{
if(gewicht>0) {
float lg = this.ps / (float)gewicht;
return lg;
} else {
throw new L8GewichtNullException();
}
}
//Leistungsberechnung mit eigener Exception
public float berechneLeistungsgewichtEigeneMeldung(int gewicht) throws L8GewichtNullException{
if(gewicht>0) {
float lg = this.ps / (float)gewicht;
return lg;
} else {
throw new L8GewichtNullException("Fehler in der Methode L8BerechneLeistungsgewichtMeldung!");
}
}
}