Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sitz {
- private char sType;
- public char getType() {
- return this.sType;
- }
- public Sitz() {}
- public Sitz(char sType) {
- this.sType = sType;
- }
- public String toString() {
- switch (sType) {
- case 's':
- case 'S': return "Sport";
- case 'd':
- case 'D': return "Default";
- case 'c':
- case 'C': return "Comfort";
- default: return "Invalid type";
- }
- }
- } // EndOfSitz
- // neue Auto Methode
- public Auto (String name, char typ, char sType) {
- if (typ == 'e'||typ=='o'||typ=='d') {
- if(sType=='d'||sType=='s'||sType=='c') {
- this.name=name;
- this.motor = new Motor(typ);
- this.sitz = new Sitz(sType);
- } else {
- System.out.println("Auto konnte nicht gebaut werden! Es fehlt der korrekte Sitztyp (s,d,c)");
- }
- } else
- System.out.println("Auto konnte nicht gebaut werden! Es fehlt der korrekte Motortyp (e,d,o)!");
- }
- // neue toString Methode
- public String toString() {
- return (motor!= null? "Der " + name + " besitzt einen " + (motor.toString() + "-Motor"): "Das Auto beitzt keinen Motor")+(sitz!=null? " und hat " + sitz.toString() + "-Sitze.": "und keine Sitze.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement