Someone helps me with an exercise in java

0

the exercise is as follows:

Make a class of name Cashier that contains the private variables customerName, customerName, codigocliente and balance. In the same class declare a method that allows to pay a deposit of money to the balance and another method that allows to withdraw money, both methods will have a parameter.

Make another method that shows me the following information: Client Code: Name and Surname of the Client: The total balance in your account is: Make another class that proves the Cashier class by instantiating 2 objects, the data of the variables will NOT be captured from the keyboard but directly assigned. For an object, invoke the method to payBalance and for the other the method to withdraw. In the end invoke the method that I deploy all the information for each instance.

I have only developed up to the total balance of the account the other part that they ask me what class to prove the Cashier class by instantiating 2 objects, the data of the variables there already I stayed: (

import java.util.*;

class cajero
{ 
    String NombreCliente, ApellidoCliente, CodigoCliente;
    double SaldoCliente;


    private void CapturarDatosAbono(double abono)
    {
        Scanner datoscliente = new Scanner(System.in);
        System.out.println("Digite el monto a abonar a la cuenta: ");
        abono = datoscliente.nextDouble();
        SaldoCliente = SaldoCliente + abono;
    }


    private void CapturarDatosRetiro(double retiro)
    {
        Scanner datoscliente = new Scanner(System.in);
        System.out.println("Digite el monto a retirar de la cuenta: ");
        retiro = datoscliente.nextDouble();
        SaldoCliente = SaldoCliente - retiro;
    }


    public void capturardatosabono()
    {
        CapturarDatosAbono(SaldoCliente);
    }


    public void capturardatosretiro()
    {
        CapturarDatosRetiro(SaldoCliente);
    }


    public void mostrardatos()
    {
        System.out.println("Codigo del Cliente: "+CodigoCliente);
        System.out.println("Nombre Completo del cliente: "+NombreCliente+" "+ApellidoCliente);
        System.out.println("Saldo total de la cuenta: "+SaldoCliente);
    }
}

class cajeroinstanciado
{

}
    
asked by Johnny 10.11.2017 в 03:32
source

1 answer

0

According to the description of your problem, I think that what you could not solve was to do the test of the class without using the Scanner, here is a proposal using a Boolean to know if you are testing the instance, or you are really going to ask for the amount per Scanner:

//Tu clase no tenía constructor, recuerda que el constructor se utiliza normalmente para inicializar las variables
public Cajero(String nombre, String apellido, String codigo){
        NombreCliente = nombre;
        ApellidoCliente = apellido;
        CodigoCliente = codigo;
    }


    public void CapturarDatosAbono(double abono, boolean probando)
    {
//Si no se esta probando (bool probando = false) se utilizara el scanner
        if(!probando){
            Scanner datoscliente = new Scanner(System.in);
            System.out.println("Digite el monto a abonar a la cuenta: ");
            abono = datoscliente.nextDouble();
        }

        SaldoCliente = SaldoCliente + abono;
    }


    public void CapturarDatosRetiro(double retiro,boolean probando)
    {
        if(!probando){
            Scanner datoscliente = new Scanner(System.in);
            System.out.println("Digite el monto a retirar de la cuenta: ");
            retiro = datoscliente.nextDouble();
        }
        SaldoCliente = SaldoCliente - retiro;
    }

And in a main class, you can test your Cashier class in the following way:

static Cajero intancia1, intancia2;
    public static void main(String[] args) {
        // TODO code application logic here
        intancia1 = new Cajero("Karlo", "Lopez", "kalm1997");
        intancia2 = new Cajero("Richard", "Alas", "RAL2017");  
        metodoParaProbar(intancia1);
    }

    public static void metodoParaProbar(Cajero instanciaAProbar){
        System.out.println("Comienza la prueba: " + instanciaAProbar.NombreCliente);
        //Probamos los ingresos
        for(int i = 0; i<10;i++){
            //Ingreso aleatorio desde 0 hasta 100
            int ingresoAleatorio = (int) (Math.random() * 100);
            instanciaAProbar.CapturarDatosAbono(ingresoAleatorio, true);
        }

        for(int i = 0; i<10;i++){
            //Retiro aleatorio desde 0 hasta 30
            int retiroAleatorio = (int) (Math.random() * 30);
            instanciaAProbar.CapturarDatosRetiro(retiroAleatorio, true);
        }
        instanciaAProbar.mostrardatos();
        System.out.println("Termina la prueba");
    }
    
answered by 10.11.2017 / 04:57
source