Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Plane {
- private boolean grounded;
- private Airport airport;
- public Plane(){
- grounded = true;
- }
- public Airport getAirport(){
- return this.airport;
- }
- public void setAirport(Airport airport){
- this.airport = airport;
- }
- public boolean isGrounded(){
- return this.grounded;
- }
- private void ground(){
- this.grounded = true;
- }
- private void fly(){
- this.grounded = false;
- }
- public void land(Airport airport) throws RuntimeException{
- if(this.grounded){
- throw new RuntimeException("Plane already grounded");
- }
- ground();
- setAirport(airport);
- }
- public void takeoff() throws RuntimeException{
- if(!this.grounded){
- throw new RuntimeException("Plane already flying");
- }
- fly();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement