Advertisement
Guest User

Untitled

a guest
May 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. class Sitz {
  2. private char sType;
  3.  
  4. public char getType() {
  5. return this.sType;
  6. }
  7. public Sitz() {}
  8. public Sitz(char sType) {
  9. this.sType = sType;
  10. }
  11. public String toString() {
  12. switch (sType) {
  13. case 's':
  14. case 'S': return "Sport";
  15. case 'd':
  16. case 'D': return "Default";
  17. case 'c':
  18. case 'C': return "Comfort";
  19. default: return "Invalid type";
  20. }
  21. }
  22. } // EndOfSitz
  23.  
  24. // neue Auto Methode
  25.  
  26. public Auto (String name, char typ, char sType) {
  27. if (typ == 'e'||typ=='o'||typ=='d') {
  28. if(sType=='d'||sType=='s'||sType=='c') {
  29. this.name=name;
  30. this.motor = new Motor(typ);
  31. this.sitz = new Sitz(sType);
  32. } else {
  33. System.out.println("Auto konnte nicht gebaut werden! Es fehlt der korrekte Sitztyp (s,d,c)");
  34. }
  35. } else
  36. System.out.println("Auto konnte nicht gebaut werden! Es fehlt der korrekte Motortyp (e,d,o)!");
  37. }
  38.  
  39. // neue toString Methode
  40.  
  41. public String toString() {
  42. 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.");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement