Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CarTree extends BinarySearchTree<Car>{
- public void addCar(Car car) {
- this.add(car);
- }
- public void inputCar() {
- boolean repeated;
- Car car = new Car();
- do {
- String numberPlate = Helper.getStringAlphaNum("Matícula: ").toUpperCase();
- car.setNumberPlate(numberPlate);
- if (search(car) != null) {
- repeated = true;
- System.err.println("La matrícula está repetida, ingrese otra");
- }
- else repeated = false;
- }while (repeated != false);
- String brand = Helper.getString("Marca");
- String version = Helper.getString("Versión: ");
- Integer year = Helper.getYear("Año: ");
- car.setBrand(brand);
- car.setVersion(version);
- car.setYear(year);
- addCar(car);
- System.out.println("Automóvil agregado");
- }
- public void generate() {
- Integer count = Helper.getPositiveInt("Cuántos registros quiere generar? ");
- for(int i = 0; i< count; i++) {
- Car randomCar = TestData.generateCar();
- this.add(randomCar);
- }
- System.out.println("Automóviles generados: " + count);
- this.InOrder();
- }
- public Car searchByNumberPlate() {
- String numberPlateSearch = Helper.getStringAlphaNum("Matícula: ").toUpperCase();
- Car carResult = (Car) this.search(new Car(numberPlateSearch,null,null,null));
- if (carResult == null) {
- System.out.println("No hay resultado para la matrícula " + numberPlateSearch);
- }
- else {
- System.out.println(carResult.toString());
- }
- return carResult;
- }
- public Car removeByNumberPlate() {
- Car carToDelete = this.searchByNumberPlate();
- if (carToDelete != null) {
- if (Helper.yesOrNo("Eliminar? S/N") == 'S') {
- this.remove(carToDelete);
- System.out.println("Automóvil eliminado");
- }
- }
- else {
- System.out.println("No existe registro de ese automóvil");
- }
- return carToDelete;
- }
- }
Add Comment
Please, Sign In to add comment