-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #881 from daniel-gf05/master
cambio3
- Loading branch information
Showing
4 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import java.util.Scanner; | ||
|
||
public class Propuesto11 { | ||
|
||
private double chocos = 0; | ||
private double papas = 0; | ||
private int clientes = 0; | ||
|
||
public Propuesto11(double chocos, double papas) { | ||
this.chocos = chocos; | ||
this.papas = papas; | ||
} | ||
|
||
public Propuesto11() { | ||
this.chocos = 0; | ||
this.papas = 0; | ||
} | ||
|
||
public double getChocos() { | ||
return chocos; | ||
} | ||
|
||
public void setChocos(double chocos) { | ||
this.chocos = chocos; | ||
} | ||
|
||
public double getPapas() { | ||
return papas; | ||
} | ||
|
||
public void setPapas(double papas) { | ||
this.papas = papas; | ||
} | ||
|
||
public int pedirClientes() { | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Introduce el número de clientes: "); | ||
this.clientes = sc.nextInt(); | ||
return clientes; | ||
} | ||
|
||
public void pedirProductos() { | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Introduce la cantidad de papas: "); | ||
this.papas = sc.nextDouble(); | ||
System.out.println("Introduce la cantidad de chocos: "); | ||
this.chocos = sc.nextDouble(); | ||
} | ||
|
||
public double personasAlimentar() { | ||
boolean a = true; | ||
do { | ||
if (papas >= 1 && chocos >= 0.5) { | ||
this.clientes += 3; | ||
this.papas -= 1; | ||
this.chocos -= 0.5; | ||
} else if (papas < 1 || chocos < 0.5) { | ||
a = false; | ||
} else { | ||
System.out.println("Error"); | ||
a = false; | ||
} | ||
} while (a == true); | ||
return this.clientes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package Tema2; | ||
|
||
public class coche { | ||
|
||
private int velocidad; | ||
//Constructor | ||
public coche() { | ||
velocidad = 0; | ||
} | ||
|
||
public coche(int velocidad){ | ||
super(); | ||
this.velocidad = velocidad; | ||
} | ||
|
||
public int getVelocidad() { | ||
return velocidad; | ||
} | ||
|
||
public void setVelocidad(int velocidad) { | ||
this.velocidad = velocidad; | ||
} | ||
//limite 120 | ||
public void acelera(int chop){ | ||
|
||
if (velocidad+chop>120) { | ||
velocidad = 120; | ||
} | ||
else{ | ||
velocidad+=chop; | ||
} | ||
} | ||
|
||
public void frena(int cant){ | ||
|
||
if (velocidad-cant<0) { | ||
velocidad=0; | ||
} | ||
else{ | ||
velocidad-=cant; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Coche [velocidad=" + velocidad + "]"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class test_propuesto11 { | ||
public static void main(String[] args) { | ||
Propuesto11 rest1 = new Propuesto11(); | ||
rest1.pedirClientes(); | ||
rest1.pedirProductos(); | ||
rest1.personasAlimentar(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package Tema2; | ||
|
||
import java.util.Scanner; | ||
|
||
public class coche_test { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
coche renault = new coche(); | ||
System.out.println("Introduce la velocidad del vehículo"); | ||
int vel = sc.nextInt(); | ||
System.out.println("Cuanto acelera el vehículo?"); | ||
int acelera = sc.nextInt(); | ||
System.out.println("Cuanto frena el vehículo?"); | ||
int frena = sc.nextInt(); | ||
renault.setVelocidad(vel); | ||
System.out.println(renault.toString()); | ||
renault.acelera(acelera); | ||
System.out.println(renault.toString()); | ||
renault.frena(frena); | ||
System.out.println(renault.toString()); | ||
|
||
coche merchi = new coche(); | ||
System.out.println("Introduce la velocidad de merchi: "); | ||
int vm = sc.nextInt(); | ||
merchi.setVelocidad(vm); | ||
System.out.println(merchi.toString()); | ||
int potito=merchi.getVelocidad(); | ||
System.out.println(potito); | ||
} | ||
} |