Problem with exercises in java [closed]

0

The truth is I'm just learning and I do not even know how to start

Create a class called Automobile with two private variables distance and time. The program will have a method, which will return the calculation of the speed, for it use the following formula: v=d/t (Where: v = speed, d = distance, t = time) . Implement the class and create an object and invoke the method.

    
asked by Dev. Joel 08.11.2017 в 06:37
source

1 answer

0

A small prototype of the kind you need is:

public class Automovil{ 
    private int distancia;
    private int tiempo; 

    //Constructor: cuando se cree un objeto automóvil se ejecutará el código que incluyamos en el constructor
    public Automovil (int dist, int tiem) {
        distancia = dist; // se mide en km
        tiempo = tiem;  // se mide en horas
    } 

    //Método para calcular y devolver la velocidad del vehículo
    public void getVelocidad () {
       return distancia/tiempo;
    }
}

Now you need another class that will be the main class and the program entry:

public class Ejercicio {
    //Esta es la entrada al programa 
    public static void main (String [ ] args) {
        Automovil car = new car (100,1);
        System.out.println(“Va a una velocidad de “ + car.getVelocidad() + “km/h”);

    } 
} 
    
answered by 08.11.2017 / 08:16
source