|
|||||||
|
|
|
|||||
|
|
|||||||
Implementación de una clase que cacule :
Nombre de la clase : LanzVert
Variables y constantes necesarias
Para realizar los cálculos necesitamos la velocidad inicial y el valor de la constante de gravedad G (9.8).
La velocidad la implementamos con un atributo privado de tipo double y a la constante de gravedad con una
constante estática.
private double vi;
public final static double G = 9.80;
Constructor
public LanzVert(double vi)
{
this.vi = vi;
}
Ecuaciones
Dando por entendido como se llega a las ecuaciones de cinemática, se obtienen cuatro fórmulas ,
que finalmente son implementadas como métodos de la clase.
tiempo de subida : t = vi / G
altura máxima : 0.5 * tiempo de subida * vi
velocidad en función del tiempo : -G * t + vi
Implementación
import java.io.*;
class LanzVert
{
private double vi;
public final static double G = 9.80;
public LanzVert(double vi)
{
this.vi = vi;
}
public double t_subida( )
{
return vi / G;
}
public double alt_max( )
{
return 0.5 * t_subida( ) * vi;
}
public double obtenerVelocidad(double t)
{
return -G * t + vi;
}
public static void main(String arg[ ]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n LANZAMIENTO VERTICAL \n");
System.out.println(" Ingreso de variables");
System.out.println(" ---------------------\n");
System.out.print(" velocidad inicial : ");
double var = Double.parseDouble(in.readLine( ));
LanzVert lanz = new LanzVert(var);
System.out.println("\n tiempo subida = " + Math.round(lanz.t_subida( )) + " s.\n");
System.out.println(" altura maxima = " + Math.round(lanz.alt_max( )) + " m.\n");
System.out.print("\n Ingrese un valor para t : ");
var = Double.parseDouble(in.readLine( ));
System.out.print("\n Velocidad para t : " + Math.round(var) + " = ");
System.out.println(Math.round(lanz.obtenerVelocidad(var)) + " m/s.");
System.out.println("\n G : " + LanzVert.G);
System.out.println( );
}
}
Bajar archivo
Salida del programa