Está en la página 1de 5

package com.mycompany.

facturacion;

/**
* 20181031623
* FRANKLIN JAVIER VALERIANO AVILES
*/
import java.util.Date;
import java.util.Random;
import java.util.Scanner;

public class ProyectoII {


static Scanner sc = new Scanner(System.in);
static int [] cantidad = new int[100];
static int [] cod = new int [100];
static String [] descrip = new String [100];
static double [] precio = new double [100];
static boolean[] gravado = new boolean[100];
static boolean aggProducto = true;
static double[] total = new double[100];
static double
subTotal=0,descu=0,totalG=0,totalEx=0,isv=0,totalPagar=0,valorDescu=0,totalNeto=0,i
mporteG=0,importeEx=0;
public static void main(String[] args) {
Informacion();
IngresarDatos();
Salida(cantidad,cod,descrip,precio,gravado,total);
calculoDeTotales();
Totales();
}

private static void Informacion()


{
Date FechaActual = new Date();
Random random = new Random();

int numAleatorio = random.nextInt(90000) + 10000;


System.out.println("--------------------------DE TODO UN
POCO------------------------");
System.out.println("--------------------------Res. Norte
Fresco----------------------");
System.out.println("--------------RTN:08012000058031---------------");
System.out.println("--------------TEL:94823645---------------------");
System.out.println("--------------detodounpoco8@yahoo.com----------");
System.out.println("--------------www.detodounpoco.com-------------");
System.out.println("CAI:1FF8TCR-ZZC902-2F533T-6FF1EZ-11DV5P-G6
");
System.out.println( "No Factura:" + numAleatorio +"
");
System.out.println( "Fecha:"+ FechaActual +"
");
System.out.println("USUARIO: FRANK
");
System.out.println("CLIENTE: CONSUMIDOR ");
}

private static void IngresarDatos()


{
Random random = new Random();
for (int i = 0; i < 100; i++)
{
while(aggProducto){
//Ingresar cantidad del producto
System.out.println("Ingrese la cantidad del producto: ");
int cant = sc.nextInt();
//validando que cantidad sea mayor a cero
boolean repetir;
do{
repetir=false;
if (cant <=0){
repetir=true;
System.out.print("\n *¡Error!*, La cantidad debe ser mayor a 0,
Ingrese una opcion valida:");
cant = sc.nextInt();
}
}while(repetir==true);
//asigando el valor ingresado al arreglo cantidad
cantidad[i] = cant;
sc.nextLine();

int numeroAleatorio = random.nextInt(90000) + 10000;


cod[i] = numeroAleatorio;
//sc.nextLine();
//validando que la descripcion no se repita
boolean descripcionRepetida;
do {
descripcionRepetida = false;
System.out.println("Ingrese la descripcion del producto: ");
descrip[i] = sc.nextLine();
//ciclo para comparar la descripcion ingresada con cada una de
las anteriores
for (int j = 0; j < i; j++) {
if (descrip[i].equals(descrip[j])) {
descripcionRepetida = true;
System.out.println("La descripcion ingresada ya existe,
por favor ingrese una nueva.");
break;
}
}
} while (descripcionRepetida);
//ingresando precio del producto
System.out.println("Ingrese el precio del producto: ");
double pre = sc.nextDouble();
//validando que el precio sea mayor a cero
do{
repetir=false;
if (pre <=0){
repetir=true;
System.out.print("\n *¡Error!*, La cantidad debe ser mayor a 0,
Ingrese una opcion valida:");
pre = sc.nextDouble();
}
}while(repetir==true);
//asigando el precio al arreglo
precio[i] = pre;
sc.nextLine();
System.out.println("El producto es Gravado?: ");
System.out.println("Seleccione 1.Gravado 2.No Gravado ");
int grv = sc.nextInt();
sc.nextLine();
switch(validarEntrada(grv,1,2))
{
case 1 -> {
gravado[i] = true;
totalG += total[i];
}
case 2 -> {
gravado[i]= false;
totalEx += total[i];
}
}
total[i]= precio[i] * cantidad[i];
subTotal += total[i];

calcularDescuento(subTotal);

if(gravado[i]==true)
{
totalG += total[i];
}

System.out.println("¿Desea agregar otro producto? (S/N)");


String respuesta = sc.nextLine();

if(respuesta.equalsIgnoreCase("n")) {
aggProducto = false;
}
i++;

break;
}

private static void calculoDeTotales()


{
totalEx = subTotal - totalG;
valorDescu = subTotal * calcularDescuento(subTotal);
totalNeto = subTotal - valorDescu;
importeG = totalG*(1-descu);
importeEx = totalEx*(1-descu);
isv = importeG * 0.15;
totalPagar = totalNeto + isv;
}

private static void Totales()


{
System.out.println("......................................................");

System.out.println("SubTotal..............................................L."+
subTotal);

System.out.println("Descuento.............................................L."+
valorDescu);
System.out.println("Importe
Gravado.......................................L."+ importeG);
System.out.println("Importe
Exento........................................L."+ importeEx);

System.out.println("Isv...................................................L."+
isv);
System.out.println("Total a
Pagar.........................................L."+ totalPagar);
}

private static double calcularDescuento(double subTotal)


{
if(subTotal < 10000)
{
descu = 0;
}
else
{
if(subTotal >= 10000 && subTotal < 20000)
{
descu = 0.05;
}
else
{
if(subTotal >= 20000 && subTotal < 40000)
{
descu = 0.10;
}
else
{
if(subTotal >= 40000)
{
descu = 0.20;
}
}
}
}
return descu;
}

private static void


Salida(int[]cantidad,int[]codigo,String[]descripcion,double[]precio,boolean[]gravad
o,double total[])
{

System.out.println("...............................................................
..................");
System.out.println("No\tCantidad\t\tCodigo\tDescripcion\tPrecioUnitario\
tGrabadoExento\tTotalUnitario");
for (int i = 0; i < cantidad[i]; i++) {
System.out.printf("%d%12s%18s%12s%16.2f%20s%16.2f\n", i+1, cantidad[i],
codigo[i], descripcion[i], precio[i], gravado[i] ? "Gravado" : "Exento", total[i]);
}
}

private static int validarEntrada(int parametro, int inicio, int fin){


boolean repetir;
do{
repetir=false;
if(parametro<inicio || parametro>fin){
repetir=true;
System.out.print("\n *¡Error!*, Ingrese una opcion valida:");
parametro = sc.nextInt();
}
}while(repetir==true);
return parametro;
}
}

También podría gustarte