Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.blaky.ship;
- public class Ship {
- private double positionX;
- private double positionY;
- private double direction;
- public Ship(double positionX, double positionY, double direction) {
- this.direction = direction;
- this.positionX = positionX;
- this.positionY = positionY;
- }
- private double calculateXAxisDistance(double distance){
- return (distance * Math.sin(getRadFromDegrees(90 - this.direction))) / Math.sin(getRadFromDegrees(90));
- }
- private double calculateYAxisDistance(double distance){
- return (distance * Math.sin(getRadFromDegrees(this.direction))) / Math.sin(getRadFromDegrees(90));
- }
- private double getRadFromDegrees(double degrees) {
- return degrees * (Math.PI / 180);
- }
- public double getPositionX() {
- return positionX;
- }
- public double getPositionY() {
- return positionY;
- }
- public double getDirection() {
- return direction;
- }
- public void turn(double degree) {
- this.direction = (this.direction + degree) % 360;
- }
- public void move(double distance) {
- this.positionX += calculateXAxisDistance(distance);
- this.positionY += calculateYAxisDistance(distance);
- }
- public void printStatus(){
- System.out.println("This ship is at X:" + positionX +" Y:" + positionY + " and facing " + direction + "*.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement