Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1.  public Ship(String name, String ayFront, String ayBack)
  2.             throws BadCoordException, CoordsBadShipException {
  3.  
  4.         this.name = name;
  5.  
  6.         this.coordAvant = new Coord(ayFront);
  7.         this.coordArriere = new Coord(ayBack);
  8.  
  9.  
  10.         if(this.coordAvant.getX() == this.coordArriere.getX()){
  11.             int size = Math.abs(this.coordArriere.getY() - this.coordAvant.getY() +1);
  12.             if(size != this.getSize()){
  13.                 throw new CoordsBadShipException();
  14.             }
  15.         }else if(this.coordAvant.getY() == this.coordArriere.getY()){
  16.             int size = Math.abs(this.coordArriere.getX() - this.coordAvant.getX()) +1;
  17.  
  18.             if(size != this.getSize()){
  19.                 throw new CoordsBadShipException();
  20.             }
  21.         }else{
  22.             throw new CoordsBadShipException();
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement