Ejercicio de POO1 - Ventas

Descargar como txt, pdf o txt
Descargar como txt, pdf o txt
Está en la página 1de 3

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package poo1;

import java.util.Scanner;

/**
*
* @author Estudiantes
*/
public class ventas {
//atributos
private String fecha, producto;
private int cantidad;
private int precio;
private int cod = 0;

//constructor
public ventas(){

}
public ventas(String f, String p, int cant, int valor){
this.cod++;
this.fecha=f;
this.producto=p;
this.cantidad=cant;
this.precio=valor;
}

public String getProducto(){


return producto;
}
public int getNumeroFactura(){
return cod;
}
public String getFecha(){
return fecha;
}
public void ActualizarPrecio(int p){
this.precio=p;
}

public String ConsultarProducto(){


return " Fecha :" +this.fecha +
" Cantidad " +this.cantidad +
" Precio :" +this.precio +
" Total :" +this.cantidad*this.precio ;
}

public String ConsultarFecha(){


return " Codigo :" +this.cod +
" Producto :" +this.producto ;
}

public String mostrarVentas(){


return " Codigo : " +this.cod +
" Producto :" +this.producto+
" Cantidad :" +this.cantidad+
" Precio :" +this.precio+
" Valor de la factura :" +cantidad*precio;

public static void main(String[] args) {

ventas miventa=null;
ventas vector[] = new ventas[3];

String prod, fecha ;


int valor, cant, total=0, i=0, opc, num;
Scanner leer = new Scanner (System.in);
do{
System.out.println("1. Generar venta");
System.out.println("2. Modificar precio");
System.out.println("3. Consultar producto");
System.out.println("4. Consultar fecha");
System.out.println("5. Mostrar ventas");
System.out.println("6. Total ventas");
opc = leer.nextInt();
switch (opc){
case 1:
System.out.println("Fecha de emision");
fecha= leer.next();
System.out.println("Nombre del producto");
prod= leer.next();
System.out.println("Cantidad a comprar");
cant= leer.nextInt();
System.out.println("Precio unitario");
valor=leer.nextInt();

miventa = new ventas(fecha, prod, cant, valor);


vector[i]=miventa;
i++;
break;
case 2:
System.out.println("Ingrese el nùmero de la factura");
num = leer.nextInt();
for (int j=0; j<i; j++){
if (vector[j].getNumeroFactura()==num){
System.out.println("Precio unitario");
valor=leer.nextInt();
vector[j].ActualizarPrecio(valor);
}
}
break;
case 3:
System.out.println("Nombre del producto");
prod = leer.next();
for (int j=0; j<i; j++){
if (vector[j].getProducto().equals(prod)){
System.out.println(vector[j].ConsultarProducto());
}
}
break;
case 4:
System.out.println("Fecha de emisiòn");
fecha= leer.next();
for (int j=0; j<i; j++){
if (vector[j].getFecha().equals(fecha)){
System.out.println(vector[j].ConsultarFecha());
}
}

break;
case 5:
for (int j=0; j<i; j++){
System.out.println(vector[j].mostrarVentas());
break;
}
}
}while (opc != 7);

}
}

También podría gustarte