How to perform this exercise with arrangements in JAVA

1

I have managed to advance a little, I have put the instructions of income but the instructions of calculation I can not do them :( Help please

/*
“El náufrago satisfecho” ofrece hamburguesas sencillas (S), dobles (D) y 
triples (T),
las cuales tienen un costo de $2.0, $3.5 y $4.8 respectivamente. 
La empresa acepta tarjetas de crédito con un cargo de 5 % sobre la compra. 
Lea datos de los N clientes, el tipo de hamburguesa y cantidad, 
la forma de pago (contado, tarjeta_crédito). 
Cada cliente adquiere una hamburguesa, las cuales pueden ser de diferente tipo, 
realice un programa para determinar cuánto deben pagar cada uno, si hay N 
clientes. 
También calcule cuantos clientes compraron hamburguesas: sencillas, dobles y 
triples.
Finalmente, presente el valor recaudado por la venta de las hamburguesas a los N 
clientes.
*/

package hamburguesa;
import java.util.Scanner;

public class Hamburguesa {

public static void main(String[] args) {
    int longitud,compra2=0;
    String formadepago;
    Scanner entrada=new Scanner(System.in);
    do{
        System.out.println("¿Cuantos clientes desean comprar hamburguesa?: ");
        longitud=entrada.nextInt();
    }while(longitud==0);

    String clientes[]=new String[longitud];
    String rfc[]=new String[longitud];
    String tipohamburguesa[]=new String[longitud];
    for(int i=0; i<clientes.length; i++){
        System.out.println("Ingrese el nombre del cliente "+(i+1)+":");
        clientes[i]=entrada.next();
        System.out.println("Ingrese el ruc o cedula para su factura: ");
        rfc[i]=entrada.next();
        System.out.println("¿Desea pagar en Efectivo o con Tarjeta?");
        System.out.println("1.Presione E para pagar en efectivo");
        System.out.println("2. Presione T para pagar con Tarjeta");
        formadepago=entrada.next();
        do{
            System.out.println("Ingrese el tipo de Hamburguesa: ");
            System.out.println("1. Hamburguesa Sencilla--> Digite S");
            System.out.println("2. Hamburguesa Doble-----> Digite D");
            System.out.println("3. Hamburguesa Triple----> Digite T");
            tipohamburguesa[i]=entrada.next();
            switch (tipohamburguesa[i]){
                case "s":
                case "S":
                    tipohamburguesa[i] = "Sencilla";
                break;
                case "d":
                case "D":
                    tipohamburguesa[i] = "Doble";
                break;
                case "t":
                case "T":
                    tipohamburguesa[i] = "Triple";
                break;
            }
            System.out.println("¿Desea otra hamburguesa?");
            System.out.println("Presione 1 para aceptar...");
            System.out.println("Presione 2 para cancelar y facturar...");
            compra2=entrada.nextInt();
        }while(compra2==1);
    }

    for(int i=0; i<clientes.length; i++){
        System.out.println("Nombre Cliente: "+clientes[i]);
        System.out.println("Cédula: "+rfc[i]);
        System.out.println("Hamburguesa: "+tipohamburguesa[i]);
    }
  }
} 
    
asked by AndréRod542 04.11.2018 в 05:24
source

2 answers

6

I comment, you have a lot of code that is in your program, I recommend that you limit yourself to what the problem asks you. All of the customer data is commented to you because it is not necessary for the calculation.

The calculation is simple, what you needed was to instantiate cost variables for each type of hamburger and at the time of making each payment calculate the sum of the burgers purchased.

Another thing, as there are only 3 types of burgers I found it was more viable to save the amount of hamburgers purchased of each type, one in each variable. This is a matter of taste.

import java.util.Scanner;

public class Hamburguesa {

    public static void main(String[] args) {
        //int longitud,compra2=0; //el nombre de tus variables debe dar mas informacion sobre lo que hace
        int cantidadClientes;
        boolean continuarCompra=true;
        // falta el valor de cada hamburguesa
        final double s = 2;     //simple
        final double d = 3.5;   //doble
        final double t = 4.8;   //triple
        // lo que haria yo es crear un atributo de cantidad para cada tipo de hamburguesa.
        int cantS = 0 ,cantD = 0 ,cantT = 0;
        double gananciaTotal = 0;  // lo recaudado al final del dia
        double costePersonal = 0;      // el costo de lo comprado por persona
        String formadepago;
        Scanner entrada=new Scanner(System.in);
        do{
            System.out.println("¿Cuantos clientes desean comprar hamburguesa?: ");
            cantidadClientes=entrada.nextInt();
        }while(cantidadClientes==0);

        //String clientes[]=new String[cantidadClientes];
        //String rfc[]=new String[cantidadClientes];
        //String tipohamburguesa[]=new String[cantidadClientes];//un cliente puede comprar mas de una hamburguesa por lo que este atributo no te sirve

        for(int i=0; i<cantidadClientes; i++){
            //System.out.println("Ingrese el nombre del cliente "+(i+1)+":");//esto no te lo pide el problema
            //clientes[i]=entrada.next();
            //System.out.println("Ingrese el ruc o cedula para su factura: ");
            //rfc[i]=entrada.next();
            System.out.println("¿Desea pagar en Efectivo o con Tarjeta?");
            System.out.println("1.Presione E para pagar en efectivo");
            System.out.println("2. Presione T para pagar con Tarjeta");
            formadepago=entrada.next();
            do{ // falta validar esto
                System.out.println("Ingrese el tipo de Hamburguesa: ");
                System.out.println("1. Hamburguesa Sencilla--> Digite S");
                System.out.println("2. Hamburguesa Doble-----> Digite D");
                System.out.println("3. Hamburguesa Triple----> Digite T");
                //tipohamburguesa[i]=;entrada.next()
                switch (entrada.next()){
                    case "s":
                    case "S":
                        //tipohamburguesa[i] = "Sencilla";
                        cantS++;
                        costePersonal += s;
                        break;
                    case "d":
                    case "D":
                        //tipohamburguesa[i] = "Doble";
                        cantD++;
                        costePersonal += d;
                        break;
                    case "t":
                    case "T":
                        //tipohamburguesa[i] = "Triple";
                        cantT++;
                        costePersonal += t;
                        break;
                    default:

                        break;
                }
                System.out.println("¿Desea otra hamburguesa?");
                System.out.println("Presione 1 para aceptar...");
                System.out.println("Presione 2 para cancelar y facturar...");
                if(entrada.nextInt()!=1) continuarCompra=false;
            }while(continuarCompra==true);
            //facturamos cliente por cliente
            System.out.println("Su compra tiene un coste de :"+costePersonal);//decimos al ciente cuanto salio su compra
            if(formadepago.equals("T")||formadepago.equals("t")){
                gananciaTotal += costePersonal * 0.95;  // si se con tarjeta se gana un 95%
            }else{
                gananciaTotal += costePersonal;
            }
            costePersonal = 0; //volvemos a instanciar el coste personal para cada cliente;
            System.out.println("-------------------------------------------------------------------------");
        }
        System.out.println("Ganado al final del dia: " + gananciaTotal);

        //for(int i=0; i<cantidadClientes; i++){
            //System.out.println("Nombre Cliente: "+clientes[i]);
            //System.out.println("Cédula: "+rfc[i]);
            //System.out.println("Hamburguesa: "+tipohamburguesa[i]);
        //}
    }
}
    
answered by 05.11.2018 в 06:08
-1

Look, I leave a small base, since you have to save the data first then print them, just keep adding what you need, and if not leave your comment.

public class Hamburguesa {

    public static void main(String[] args) {
        int longitud;
        Scanner entrada=new Scanner(System.in);
        do{
            System.out.println("¿Cuantos clientes desean comprar hamburguesa?: ");
            longitud=entrada.nextInt();
        }while(longitud==0);

        String clientes[]=new String[longitud];
        String RFC[]=new String[longitud];
        String tipohamburguesa[]=new String[longitud];
        for(int i=0; i<clientes.length; i++){
            System.out.println("Ingrese el nombre del cliente "+(i+1)+":");
            clientes[i]=entrada.next();
            System.out.println("Ingrese el ruc o cedula para su factura: ");
            RFC[i]=entrada.next();
            System.out.println("Ingrese el tipo de Hamburguesa: ");
            System.out.println("1. Hamburguesa Sencilla--> Digite S");
            System.out.println("2. Hamburguesa Doble-----> Digite D");
            System.out.println("3. Hamburguesa Triple----> Digite T");
            tipohamburguesa[i]=entrada.next();
            /*if (tipohamburguesa=="S"){

            }*/
            switch (tipohamburguesa[i]){
                case "s":
                case "S":
                    tipohamburguesa[i] = "Sencilla";
                break;
                case "d":
                case "D":
                    tipohamburguesa[i] = "Doble";
                break;
                case "t":
                case "T":
                    tipohamburguesa[i] = "Triple";
                break;
            }
        }
        for(int i=0; i<clientes.length; i++){
            System.out.println("El cliente "+clientes[i]+" con RFC: "+RFC[i]+" adquirio una hamburguesa "+tipohamburguesa[i]);
        }
      }
    } 
    
answered by 04.11.2018 в 05:56