Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public class Plane {
  2. private boolean grounded;
  3. private Airport airport;
  4.  
  5. public Plane(){
  6. grounded = true;
  7. }
  8.  
  9. public Airport getAirport(){
  10. return this.airport;
  11. }
  12.  
  13. public void setAirport(Airport airport){
  14. this.airport = airport;
  15. }
  16.  
  17. public boolean isGrounded(){
  18. return this.grounded;
  19. }
  20.  
  21. private void ground(){
  22. this.grounded = true;
  23. }
  24.  
  25. private void fly(){
  26. this.grounded = false;
  27. }
  28.  
  29. public void land(Airport airport) throws RuntimeException{
  30. if(this.grounded){
  31. throw new RuntimeException("Plane already grounded");
  32. }
  33. ground();
  34. setAirport(airport);
  35. }
  36.  
  37. public void takeoff() throws RuntimeException{
  38. if(!this.grounded){
  39. throw new RuntimeException("Plane already flying");
  40. }
  41. fly();
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement