I have a project for a structured exercise in three packages:
-
Application (Main)
package aplicacion; import mountainbike.MountainBike; public class ProbandoMountainBike { public static void main(String[] args) { MountainBike mb = new MountainBike(); mb.setTamanoRueda(1); mb.setNumPlatos(1); mb.setNumPinones(11); mb.setNumDientes() //************************** double diametro = 0; // Declaro esta variable para sacar el valor en pulgados según tamaño de rueda if (mb.getTamanoRueda() == 1) { // Damos valor al diametro según el tamaño rueda diametro = 26; } else if (mb.getTamanoRueda() == 2) { diametro = 27.5; } else if (mb.getTamanoRueda() == 3) { diametro = 29; } System.out.println("Objeto utilizando el constructor parametrizado"); System.out.println("\nDiámetro de la rueda: " + diametro); } }
-
Bike (father)
package bicicleta; public class Bicicleta { private int tamanoRueda ; // 1 - 2 - 3 para tamaños 26 - 27.5 - 29 private double velocidad; // Velocidad Bicicleta private int numPlatos; // Platos que tiene la bicicleta private int numPinones; // Piñones que tiene la bicicleta public Bicicleta() { } public Bicicleta(int tamanoRueda, double velocidad, int numPlatos, int numPinones) { this.tamanoRueda = tamanoRueda; this.velocidad = velocidad; this.numPlatos = numPlatos; this.numPinones = numPinones; } public int getTamanoRueda() { return tamanoRueda; } public void setTamanoRueda(int tamanoRueda) { this.tamanoRueda = tamanoRueda; } public double getVelocidad() { return velocidad; } public void setVelocidad(double velocidad) { this.velocidad = velocidad; } public int getNumPlatos() { return numPlatos; } public void setNumPlatos(int numPlatos) { this.numPlatos = numPlatos; } public int getNumPinones() { return numPinones; } public void setNumPinones(int numPinones) { this.numPinones = numPinones; } public void acelera(double aceleracion) { this.velocidad += aceleracion; } public void frena(double desaceleracion) { this.velocidad -= desaceleracion; }
}
-
Mountain Bike (subclass inherits Bike properties)
package mountainbike; import bicicleta.Bicicleta; import java.lang.reflect.Array; public class MountainBike extends Bicicleta { private int [] numDientes = new int [15]; private int plato; private int pinon; public MountainBike() { } public MountainBike(int[] numDientes, int plato, int pinon, int tamanoRueda, double velocidad, int numPlatos, int numPinones) { super(tamanoRueda, velocidad, numPlatos, numPinones); this.plato = plato; this.pinon = pinon; } public int[] getNumDientes() { return numDientes; } public void setNumDientes(int[] numDientes) { this.numDientes = numDientes; } public int getPlato() { return plato; } public void setPlato(int plato) { this.plato = plato; } public int getPinon() { return pinon; } public void setPinon(int pinon) { this.pinon = pinon; } public double cmAvanza(){ double cm = 0; cm = (numDientes[plato-1] / numDientes[pinon+2])* 2 * Math.PI * ((getTamanoRueda()*2.54)/2);; return cm; }
}
The problem is that one of the properties of Mountain Bike is a private Array [15] which is not initialized in the Main. Since in the enenunciado of the problem I am told:
Schedule a MountainBike name class, which inherits from Bicycle, and Also add the following properties and methods: Properties (private):
- numDientes: array of 15 integers that will store in its first three positions the number of teeth of each of the three possible dishes that can have a Mountain Bike. In the case of having less than three plates will only have values the necessary positions of the array. In the remaining positions, the number of teeth of the pine nuts that have the bicycle
So the array I must declare as private in MoutainBike
and then in the last point I'm asked:
Make a program that declares an object of the class
MountainBike
Create the object using the default constructor. Assign the values to the object: sizeRave: 1 numPlates: 1 numPinons: 11 numDientes: 22-xx-xx-11-13-15-17-19-21-24-28-32-36-42-xx (xx could have any value, since in this object it is not use) plate: 1 pinon: 5Visualize the data of this bicycle, and the centimeters it advances in each pedalada.
Create another object by passing its initial values through the builder. The values will be: sizeRave: 3 numPlates: 2 numPinons: 11 numDientes: 22-36-xx-11-13-15-17-19-21-24-28-32-36-42-xx (xx could have any value, since in this object it is not use) plate: 2 pinon: 1