jeudi 20 avril 2017

Calculating PLANE SPEED and TIME in Java

Im currently trying to do an exercise for upcoming exam. But unfortunately he is already asleep and I have an exam tomorrow.

this is my code that I have done. Im not sure what to do with resetSpeed and I think there is also something wrong in trying to calculate timeToTravel method

package comp6700.mse;
/**
 * COMP6700 Mid-Semester Exam, Question 3
 */
public class Q3Plane {
    private String name;
    private int speed;
    private long distance;
    private int time;
    /**
     * Constructor
     *
     * @param name The name of the plane
     * @param speed The speed of the plane (in km/h),
     */
    Q3Plane(String name, int speed) {
        this.name = name;
        this.speed = speed;
    }


    /** Return the speed of the plane */
    int getSpeed() {
        return speed;
    }
    /**
     * Reset the speed of the plane according to the argument speed
     * @param speed The new speed of the plane
     */
    void resetSpeed(int speed) {


    }
    /**
     * Calculate the time to travel the specified distance at the current speed.
     * @param distance The distance (in km)
     * @return The time to travel the distance (in minutes)
     */
    int timeToTravel(int distance) {
        this.distance = distance;
        this.time = time;

        time = distance/speed;

        return time ;
    }
    /**
     * Return a string describing the plane and its speed,
     * in the format
     *    "Plane NAME is travelling S km/h"
     * where NAME is replaced by the plane's name, and S is replaced by
     * the plane's speed.
     *
     * @return A string describing the plane and its speed
     */
    @Override
    public String toString() {
        return ("Plane"+" "+name+" "+ "is travelling" +" " +speed+ " " + "km/h");  // FIXME 3g: complete this method
    }
}

the error that i got is this

java.lang.AssertionError: Expected string 'Plane NA1557 is travelling 692 km/h', but got 'Plane NA1557 is travelling 662 km/h'

java.lang.AssertionError: Expected time of '61', but got '0'

java.lang.AssertionError: Expected speed of '632', but got '691'






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire