Desarrollo ejercicio
Publicado por Deivy Santiago (1 intervención) el 13/05/2019 14:19:45
Ayuda en el desarrollo de este ejercicio


Valora esta pregunta


-1
public class Orden {
private String granjero;
private String tipo;
private Double hectarias;
private Double descuento;
private Double total;
/**
* @return the granjero
*/
public String getGranjero() {
return granjero;
}
/**
* @param granjero the granjero to set
*/
public void setGranjero(String granjero) {
this.granjero = granjero;
}
/**
* @return the hectarias
*/
public Double getHectarias() {
return hectarias;
}
/**
* @param hectarias the hectarias to set
*/
public void setHectarias(Double hectarias) {
this.hectarias = hectarias;
}
/**
* @return the total
*/
public Double getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(Double total) {
this.total = total;
}
/**
* @return the descuento
*/
public Double getDescuento() {
return descuento;
}
/**
* @param descuento the descuento to set
*/
public void setDescuento(Double descuento) {
this.descuento = descuento;
}
/**
* @return the tipo
*/
public String getTipo() {
return tipo;
}
/**
* @param tipo the tipo to set
*/
public void setTipo(String tipo) {
this.tipo = tipo;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public class Fumigar {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static String leer(String message) {
String s;
try {
System.out.print(message);
s = br.readLine();
} catch (IOException ex) {
System.out.println("Hubo un error de lectura, vuelva a intentar");
s = null;
}
if (s == null) {
s = leer(message);
}
return s;
}
public static Double leerDouble(String message) {
Double d;
try {
d = Double.parseDouble(leer(message));
} catch (NumberFormatException ex) {
System.out.println("Valor incorrecto vuelva a intentar");
d = null;
}
if (d == null) {
d = leerDouble(message);
}
return d;
}
public static Integer leerInteger(String message) {
Integer d;
try {
d = Integer.parseInt(leer(message));
} catch (NumberFormatException ex) {
System.out.println("Valor incorrecto vuelva a intentar");
d = null;
}
if (d == null) {
d = leerInteger(message);
}
return d;
}
public static void main(String[] args) {
System.out.println("Fumigar...");
List<Orden> ordenes = new ArrayList();
do {
System.out.println("Introduzca los datos de la nueva orden");
Orden o = new Orden();
o.setGranjero(leer("Nombre del granjero: "));
o.setHectarias(leerDouble("Hectareas: "));
String tipo = "";
double total = 0.0;
double descuento = 0.0;
System.out.println("Selecione el tipo");
while (tipo.isEmpty()) {
switch (leerInteger("Introduzca 1 para Fumigacion contra malas hierbas"
+ "\nIntroduzca 2 para Fumigacion contra moscas y mosquitos"
+ "\nIntroduzca 3 para Fumigacion contra gusanos"
+ "\nIntroduzca 4 para Fumigacion contra todo lo anterior: ")) {
case 1:
total = o.getHectarias() * 50;
tipo = "Fumigacion contra malas hierbas";
break;
case 2:
total = o.getHectarias() * 70;
tipo = "Fumigacion contra moscas y mosquitos";
break;
case 3:
total = o.getHectarias() * 80;
tipo = "Fumigacion contra gusanos";
break;
case 4:
total = o.getHectarias() * 150;
tipo = "Fumigacion contra todo lo anterior";
break;
default:
tipo = "";
System.out.println("Opción incorrecta, vuelva a intentar");
break;
}
}
o.setTipo(tipo);
if (o.getHectarias() > 100.0) {
descuento += total * 0.05;
}
/**
* Si la cuenta total sobrepasa los $10,000 se hace acreedor de un
* 10% de descuento sobre la cantidad que sobrepase los $10,000
*/
if (total > 10000.0) {
descuento += (total - 10000) * 0.10;
}
o.setTotal(total);
o.setDescuento(descuento);
ordenes.add(o);
System.out.println("Orden añadida...");
} while (leer("Introduzca 1 para gregar mas ordenes: ").equals("1"));
//Limpiamos la consola
for (int i = 0; i < 15; i++) {
System.out.println();
}
/**
* Ahora visualizamos las ordenes
*/
double total = 0.0;
DecimalFormat df = new DecimalFormat("#,###.##");
for (int i = 0; i < ordenes.size(); i++) {
System.out.println(
"Granjero: " + ordenes.get(i).getGranjero()
+ "\nTipo: " + ordenes.get(i).getTipo()
+ "\nHectareas: " + df.format(ordenes.get(i).getHectarias())
+ "\nSubtotal: " + df.format(ordenes.get(i).getTotal())
+ "\nDescuento: " + df.format(ordenes.get(i).getDescuento())
+ "\nTotal: " + df.format(ordenes.get(i).getTotal() - ordenes.get(i).getDescuento())
+ "\n"
);
total += ordenes.get(i).getTotal() - ordenes.get(i).getDescuento();
}
System.out.println("Cantidad de ordenes: " + ordenes.size()
+ "\nTotal: " + df.format(total)
);
}
}