Bad operand : does not accept accounts or comparisons!

Asked

Viewed 39 times

0

I’m inclined to solve the following problem: João Papo-de-Pescador, a good man, bought a microcomputer to control the daily income of his work. Every time he brings a weight of fish greater than that established by the regulation of fishing in the state of São Paulo (50 kilos) must pay a fine of R$ 4.00 per kilo surplus. John needs you to do a program that read the weight variable (weight of fish) and calculate the excess. Write in variable excess the amount of kilos beyond the limit and in the variable fine the amount of the fine that João must pay. Print the data of program with the appropriate messages.

But the compiler is not accepting my comparisons and sums, where I am missing?

package papodepescador;

import java.util.Scanner;


public class PapoDePescador {

    public static void main(String[] args) {

        peso.quanto();

    }
 class peso {
    private static void quanto(){
        System.out.println("Quantos quilos de peixes temos hoje João? ");
        Scanner sc = new Scanner(System.in);
        boolean quilo = sc.nextBoolean();
        if(quilo <= 50){
           System.out.println("A quantidade " + quilo+"Kg de peixes esta dentro do"
                    + " limite de peso do regulamento do estado de São Paulo. Muito bem João!");

        }
        else{
            System.out.println("Que pena João!\n Infelismente você esta com " + excesso(quilo) 
                    + "Kg acima do limite.\n E terá que pagar uma multa de R$" + multa.valor(quilo)+ ".");
        }
    }
    public static boolean excesso(boolean quilo){
         return quilo / 50.00;
        }

    }
 public class multa {


    public static boolean valor(boolean quilo){
          boolean aux;
          aux = 50.00 / quilo * 4.00;
          return aux;

        }
    }

}

bad operand errors occur on lines:

if(quilo <= 50){


return quilo / 50.00;

and the flip operands:

aux = 50.00 / quilo * 4.00;

1 answer

1


You are trying to carry out divisions and use the relational operator <= between a boolean (true or false) and a number in the variables quilo and aux.

Replace the type of boolean for int, float or double in the declarations of variables and the type of function return excesso and valor

int quilo = sc.nextInt(); 
// sc.nextFloat(); caso quilo for float
// sc.nextDouble(); caso quilo for double
public static int excesso(int quilo){
    return quilo / 50.00;
}
public static int valor(int quilo){
    int aux;
    aux = 50.00 / quilo * 4.00;
    int aux;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.