import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class Tienda {
public static void main(String[] args) throws IOException {
List<Venta> ventas = new ArrayList();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nombre;
double monto;
do {
System.out.print("\nNombre del cliente: ");
nombre = br.readLine();
System.out.print("Monto de la venta: ");
monto = Double.parseDouble(br.readLine());
ventas.add(new Venta(nombre, monto));
System.out.print("Introduce 1 para registrar una nueva venta: ");
} while (br.readLine().equals("1"));
double total = ventas.stream()
.mapToDouble(v -> v.getTotal())
.sum();
ventas.forEach(System.out::println);
System.out.println("El total de las ventas es: " + total);
}
}
class Venta {
private String cliente;
private double total;
private final String fecha;
public Venta(String cliente, double total) {
this.cliente = cliente;
this.total = total;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
fecha = sdf.format(Calendar.getInstance().getTime());
}
@Override
public String toString() {
return "\nfecha: " + fecha + "\ncliente: " + cliente + "\ntotal: " + total;
}
/**
* @return the cliente
*/
public String getCliente() {
return cliente;
}
/**
* @param cliente the cliente to set
*/
public void setCliente(String cliente) {
this.cliente = cliente;
}
/**
* @return the total
*/
public double getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(double total) {
this.total = total;
}
/**
* @return the fecha
*/
public String getFecha() {
return fecha;
}
}