feat: Ejercicio de repaso creado.

main
KyMAN 2 months ago
parent 927c4d51c5
commit 5eedda2739
  1. 49
      README.md
  2. 73
      build.xml
  3. 4
      build/built-jar.properties
  4. 0
      build/classes/.netbeans_automatic_build
  5. 0
      build/classes/.netbeans_update_resources
  6. BIN
      build/classes/repasopoocoches/Abstracciones/Coche.class
  7. BIN
      build/classes/repasopoocoches/Interfaces/Coches.class
  8. BIN
      build/classes/repasopoocoches/Marcas/Ford.class
  9. BIN
      build/classes/repasopoocoches/Marcas/Peugeut.class
  10. BIN
      build/classes/repasopoocoches/Marcas/Renault.class
  11. BIN
      build/classes/repasopoocoches/Marcas/Toyota.class
  12. BIN
      build/classes/repasopoocoches/RepasoPOOCoches.class
  13. 32
      dist/README.TXT
  14. BIN
      dist/RepasoPOOCoches.jar
  15. 3
      manifest.mf
  16. 1771
      nbproject/build-impl.xml
  17. 8
      nbproject/genfiles.properties
  18. 2
      nbproject/private/private.properties
  19. 7
      nbproject/private/private.xml
  20. 95
      nbproject/project.properties
  21. 15
      nbproject/project.xml
  22. 55
      src/repasopoocoches/Abstracciones/Coche.java
  23. 19
      src/repasopoocoches/Interfaces/Coches.java
  24. 45
      src/repasopoocoches/Marcas/Ford.java
  25. 45
      src/repasopoocoches/Marcas/Peugeut.java
  26. 45
      src/repasopoocoches/Marcas/Renault.java
  27. 45
      src/repasopoocoches/Marcas/Toyota.java
  28. 57
      src/repasopoocoches/RepasoPOOCoches.java

@ -1,3 +1,50 @@
# RepasoPOOCoches
Ejercicio de repaso que hay en el raíz del contenido de la asignatura de Procesos y Serivicos.
> Este ejercicio fue hecho sin mirar el temario y entregado fuera de plazo por motivos agenos al ciclo, por lo que independientemente de resultados, agradecer al profesor a cargo de la asignatura por mirarlo igualmente pese a dichas condiciones, así por el apoyo ofrecido. También quiero que quede de aviso para otros posibles compañeros que quieran hacer uso de este contenido por posiblemente no ceñirse a lo requerido en la asignatura. Sea como sea, espero sea útil para aprender y reciclarse como lo fue para mi.
Este es un ejercicio de repaso que hay dentro de la asignatura de Programación de Servicios y Procesos. La idea es conseguir gestionar diferentes tipos de coches a partir de clases heredadas y repasar el ámbito de los atributos y elementos de clase y objeto.
A modo de estructuración del proyecto tenemos 3 directorios a modo de paquetes para:
- **Interfaces**: Aquí irán las interfaces asignadas al ejercicio.
- **Abstracciones**: Aquí irán las abstracciones (Clases abstractas) asignadas al ejercicio.
- **Marcas**: Paquete hecho a modo de modelos de cada una de las marcas que se vayan a trabajar aquí.
> El ejercicio en sí no me tenía mucha lógica funcional, así que lo fui adaptando para poder alcanzar un fin funcional en cuestión. Uno de los grandes problemas que encontré esla sobreescritura de los métodos de control del vehículo, que teóricamente han de ser iguales para todos y lo que varían en sí serían los parámetros que usen. Para poder hacer un "Override" de éstos, expuse una interfaz de la cual partan obligatoriamente dichos métodos. Para que los métodos sean distintos entre las distintas marcas, se establece un valor numérico personalizado según la marca.
La abstracción **Coche** implementa de forma heredada la interfaz **Coches** para que al definir cada marca, ésta tenga la obligación de crear dicho método. También tiene ciertos parámetros comunes a todos los coches, los cuales han de ser sobreescritos por cada Marca implementada.
> Para que todo esto tenga sentido, el constructor de cada marca operará en base al rendimiento del coche: un valor porcentual en base decimal, es decir, 1 sería el 100%, que determinará el rendimiento, velocidad máxima y capacidad del tanque de combustible, a mayores de la customización implementada en cada marca.
Finalmente, se implementaron las marcas:
- **Ford**
- **Peugeut**
- **Renault**
- **Toyota**
```mermaid
flowchart TD
I["Coches (Interfaz)"]
A["Coche (Abstracta)"]
F[Ford]
P[Peugeut]
R[Renault]
T[Toyota]
I --> A
A --> F
A --> P
A --> R
A --> T
```
La Interfaz **Coches** obligará a construir los métodos:
- **acelerar**
- **frenar**: Se entenderá como una aceleración negativa.
- **repostar**
En la clase principal **RepasoPOOCoches** se montarán todos los vehículos que se quieran en base al parámetro de configuración allí existente, que depende de los propios Coches existentes en Marcas como clases-objeto, en una tabla de datos la cual será migrada en el *main* a un ArrayList el cual luego ordenará mediante **sort** y un *Arrow Function* (Equivalente a crear un objeto *Comparator* y el Override de *compare*) donde se hará una comparativa mediante un valor numérico que determina si es mayor o menor que el objeto anterior, comparando, en este caso, mediante casteo a *Coche*, las potencias de todos los coches creados. Tras ésto, ejecutará cada uno de los métodos de la Interfaz e imprimirá, mediante el método *toString*, de forma automática, los datos del vehículo para determinar tanto su orden como el correcto funcionamiento de todo.

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="RepasoPOOCoches" default="default" basedir=".">
<description>Builds, tests, and runs the project RepasoPOOCoches.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="RepasoPOOCoches-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

@ -0,0 +1,4 @@
#Tue, 05 Mar 2024 01:15:20 +0100
/home/DAM2024/RepasoPOOCoches=

32
dist/README.TXT vendored

@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "RepasoPOOCoches.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

Binary file not shown.

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

@ -0,0 +1,8 @@
build.xml.data.CRC32=ffc29890
build.xml.script.CRC32=b6ac62aa
build.xml.stylesheet.CRC32=f85dc8f2@1.110.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=ffc29890
nbproject/build-impl.xml.script.CRC32=7be500db
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.110.0.48

@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=/home/kyman/snap/netbeans/93/build.properties

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
</open-files>
</project-private>

@ -0,0 +1,95 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/RepasoPOOCoches.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/RepasoPOOCoches
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=19
javac.target=19
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
# The jlink additional root modules to resolve
jlink.additionalmodules=
# The jlink additional command line parameters
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=RepasoPOOCoches
main.class=repasopoocoches.RepasoPOOCoches
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>RepasoPOOCoches</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

@ -0,0 +1,55 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package repasopoocoches.Abstracciones;
/**
*
* @author kyman
*/
public abstract class Coche implements repasopoocoches.Interfaces.Coches {
protected String marca = "Desconocido";
protected String modelo = "Desconocido";
public float potencia = 0;
protected float velocidad = 0;
protected float velocidad_maxima = 0;
protected float combustible = 0;
protected float capacidad_del_tanque = 0;
protected void ejecutar_aceleracion(float unidades){
float incremento = unidades * potencia;
if(incremento > 0){
if(velocidad < velocidad_maxima && (velocidad += incremento) > velocidad_maxima)
velocidad = velocidad_maxima;
}else if(velocidad != 0 && (velocidad -= incremento) < 0)
velocidad = 0;
}
protected float meter_combustible(float cantidad){
if(combustible < capacidad_del_tanque){
if((combustible += cantidad) > capacidad_del_tanque){
cantidad = combustible - capacidad_del_tanque;
combustible = capacidad_del_tanque;
}else
cantidad = 0;
}
return cantidad;
}
@Override
public String toString(){
return (
"Coche es el modelo '" + modelo + "' de la marca '" + marca + "' con " + potencia + " de caballos de potencia.\n" +
"Circula a una velocidad de " + velocidad + "km/h de " + velocidad_maxima + "km/h de velocidad máxima.\n" +
"Tiene " + combustible + "l de combustible de un máximo de " + capacidad_del_tanque + " litros."
);
}
}

@ -0,0 +1,19 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package repasopoocoches.Interfaces;
/**
*
* @author kyman
*/
public interface Coches {
public void acelerar();
public void frenar();
public void repostar();
}

@ -0,0 +1,45 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package repasopoocoches.Marcas;
/**
*
* @author kyman
*/
public class Ford extends repasopoocoches.Abstracciones.Coche {
protected String marca = "Ford";
public float potencia = 1.4f;
protected float velocidad_maxima = 270;
protected float capacidad_del_tanque = 60;
public Ford(String modelo, float rendimiento){
this.modelo = modelo;
super.marca = this.marca;
super.potencia = this.potencia * rendimiento;
super.velocidad_maxima = this.velocidad_maxima * rendimiento;
super.capacidad_del_tanque = this.capacidad_del_tanque * rendimiento;
}
@Override
public void acelerar() {
ejecutar_aceleracion(25);
}
@Override
public void frenar() {
ejecutar_aceleracion(-40);
}
@Override
public void repostar() {
meter_combustible(5);
}
}

@ -0,0 +1,45 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package repasopoocoches.Marcas;
/**
*
* @author kyman
*/
public class Peugeut extends repasopoocoches.Abstracciones.Coche {
protected String marca = "Peugeot";
public float potencia = .95f;
protected float velocidad_maxima = 220;
protected float capacidad_del_tanque = 50;
public Peugeut(String modelo, float rendimiento){
this.modelo = modelo;
super.marca = this.marca;
super.potencia = this.potencia * rendimiento;
super.velocidad_maxima = this.velocidad_maxima * rendimiento;
super.capacidad_del_tanque = this.capacidad_del_tanque * rendimiento;
}
@Override
public void acelerar() {
ejecutar_aceleracion(13);
}
@Override
public void frenar() {
ejecutar_aceleracion(-24);
}
@Override
public void repostar() {
meter_combustible(3);
}
}

@ -0,0 +1,45 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package repasopoocoches.Marcas;
/**
*
* @author kyman
*/
public class Renault extends repasopoocoches.Abstracciones.Coche {
protected String marca = "Reanult";
public float potencia = .8f;
protected float velocidad_maxima = 180;
protected float capacidad_del_tanque = 40;
public Renault(String modelo, float rendimiento){
this.modelo = modelo;
super.marca = this.marca;
super.potencia = this.potencia * rendimiento;
super.velocidad_maxima = this.velocidad_maxima * rendimiento;
super.capacidad_del_tanque = this.capacidad_del_tanque * rendimiento;
}
@Override
public void acelerar() {
ejecutar_aceleracion(10);
}
@Override
public void frenar() {
ejecutar_aceleracion(-20);
}
@Override
public void repostar() {
meter_combustible(3);
}
}

@ -0,0 +1,45 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package repasopoocoches.Marcas;
/**
*
* @author kyman
*/
public class Toyota extends repasopoocoches.Abstracciones.Coche {
protected String marca = "Toyota";
public float potencia = 1.2f;
protected float velocidad_maxima = 240;
protected float capacidad_del_tanque = 50;
public Toyota(String modelo, float rendimiento){
this.modelo = modelo;
super.marca = this.marca;
super.potencia = this.potencia * rendimiento;
super.velocidad_maxima = this.velocidad_maxima * rendimiento;
super.capacidad_del_tanque = this.capacidad_del_tanque * rendimiento;
}
@Override
public void acelerar() {
ejecutar_aceleracion(17);
}
@Override
public void frenar() {
ejecutar_aceleracion(-31);
}
@Override
public void repostar() {
meter_combustible(6);
}
}

@ -0,0 +1,57 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package repasopoocoches;
import java.util.ArrayList;
import java.util.Arrays;
import repasopoocoches.Abstracciones.Coche;
import repasopoocoches.Marcas.Ford;
import repasopoocoches.Marcas.Peugeut;
import repasopoocoches.Marcas.Renault;
import repasopoocoches.Marcas.Toyota;
/**
*
* @author kyman
*/
public class RepasoPOOCoches {
// Configuracion.
private static final Coche[] coches = {
new Ford("Mustang", 1.3f),
new Renault("Sedan", .8f),
new Renault("Clio", 2.5f),
new Toyota("Corola", 1.2f),
new Peugeut("207", 2.5f)
};
// Configuracion.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList<Coche> coches = new ArrayList<>(Arrays.asList(RepasoPOOCoches.coches));
coches.sort((Object coche_a, Object coche_b) -> (int)(
((Coche)coche_a).potencia * Math.pow(10, 8) - ((Coche)coche_b).potencia * Math.pow(10, 8)
));
for(int i = 0, l = coches.size(); i < l; i ++){
Coche coche = coches.get(i);
coche.acelerar();
coche.frenar();
coche.repostar();
System.out.println("\n" + coche + "\n");
}
}
}
Loading…
Cancel
Save