Advertisement
Fissko

Untitled

Jul 8th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Taxi {
  4.  
  5. private Human driver;
  6. private Human passengers;
  7. private Taxi[] taxi = new Taxi[5];
  8.  
  9. public Taxi(Human driver){
  10. this.driver = driver;
  11. }
  12.  
  13. public String getDriverName() {
  14. return driver.getForename() + " " + driver.getName();
  15. }
  16.  
  17. public void add(Human x) {
  18. int i = 0;
  19. if(taxi.length <=4 ) {
  20. taxi[i] = this.x; //hier erhalte ich den Fehler:"x cannot be resolved or is not a field" Warum?
  21. i++;
  22.  
  23. System.out.println(x + " gets in.");
  24. }
  25. else {
  26. System.out.println("We are sorry, " + x +"."
  27. + " The taxi is full");
  28. }
  29.  
  30.  
  31. }
  32.  
  33. public static void main(String[] args) {
  34.  
  35. Human driver = new Human("Juergen", "Staub");
  36.  
  37. System.out.println(driver);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement