dimanche 4 novembre 2018

How to use if statement to check if something is null and react accordingly

I am trying to make a program that receives 3 user inputs and can check whether one of them is null and can react accordingly.

This is my code, but I keep getting errors when running it. Not sure what I'm doing wrong. Please if anyone can advise me on what I'm doing wrong it would be greatly appreciated.

double hours, minutes, triples;

    hours = Double.parseDouble(txtHours.getText());
    minutes = Double.parseDouble(txtMinutes.getText());
    triples = Double.parseDouble(txtTriples.getText());


    //In the event that all fields are used
    double hours1, hours11, hours111, hoursTot, triples1, TotWage;
    hours1 = hours * 60;
    hours11 = hours1 + minutes;
    hours111 = hours11 / 60;
    triples1 = triples * 3;
    hoursTot = (hours111 * 9.55);
    TotWage = hoursTot + triples1;

    //In the event that only hours and minutes are used
    double hours2, hours22, hours222, TotWage2;
    hours2 = hours * 60;
    hours22 = hours2 + minutes;
    hours222 = hours22 / 60;
    TotWage2 = hours222 * 9.55;


    //In the event that only hours and triples are used
    double hours3, triples3, TotWage3;
    hours3 = hours * 9.55;
    triples3 = triples * 3;
    TotWage3 = hours3 + triples3;



    if (minutes == 0){

        txtTotal.setText("€"+TotWage3+" is the amount needed to be paid.");

    }

    else if (triples == 0){

        txtTotal.setText("€"+TotWage+" is the amount needed to be paid.");

    }

    else {
        txtTotal.setText("€"+TotWage2+" is the amount needed to be paid.");
    }

Aucun commentaire:

Enregistrer un commentaire