I calculate Java water consumption using Eclipse IDE

Asked

Viewed 636 times

4

I’m having a hard time writing this exercise in the Java Language, using the Eclipse IDE:

The director of a state school in the city of São Paulo is terrified by the absurd consumption of water that has been occurring monthly. In order to gather information that leads her to make cost containment decisions, she hired you to develop a program that performs the reading of water consumption in the month, in m3, and inform the value of the account. Data: consider that each m3 is worth R$ 2.00; in addition, R$ 20.00 of sewage and 15% of taxes are added.

I’m not getting the program to perform the calculations. In my case I must first calculate the tax, then "throw" it in the formula to calculate the value of water consumption.

MY DOG

import java.io.IOException;
import java.util.Scanner;

public class Agua {

    public static void main(String[] args) throws IOException  {

        int consumo;
        int valore;
        int imposto;

                System.out.println("Informar o valor do consumo");

                Scanner Leio = new Scanner(System.in);
                consumo = Leio.nextInt();

                imposto = (2 * consumo + 20) * 15/100;
                System.out.println("O imposto é ");


                System.out.println("Informe o valor do imposto");
                valore = (2 * consumo + 20) + imposto;

                System.out.println("O Valor é de: R$ ");
                Leio.close();

            }

}

I’m having difficulties in this exercise, because after I type the consumption value does not occur anything!

Below follows the formulas by Visualg where the cacules occur smoothly (crazy teacher wants Portugol/Visualg and Java)!

VISUALG

My second image is the screen in Eclipse after I inform the value of "consumption"

JAVA

  • 1

    In case nothing appears on the screen, why you are not printing the variables. Your System.out.println is just printing the text. Try to put in the text System.out.println("O imposto é " + imposto); and System.out.println(O valor é de R$: " + valore);

2 answers

4

You are not printing the tax and consumption values. What you do is print only the text:

System.out.println("O imposto é ");
...
System.out.println("O Valor é de: R$ ");

See that in your Visualg code you print the actual value:

Escreva(Valor)

The only adjustment you need to make is to add the variable’s value print, the same way you did in Visualg:

System.out.println("O imposto é ");
System.out.println(imposto);
...
System.out.println("O Valor é de: R$ ");
System.out.println(valore);

So the values you calculated will appear on the console.

1


Look the java is much more malleable than portugol, you can do this, if you do not understand anything you can ask me. OK?

public class Agua {

    public static void main(String[] args) throws IOException {
        System.out.println("Informar o valor do consumo");
        Scanner Leio = new Scanner(System.in);
        int consumo = Leio.nextInt();
        int imposto = (2 * consumo + 20) * 15 / 100;
        System.out.println("O imposto é " + imposto);
        System.out.println("Informe o valor do imposto");
        int valore = (2 * consumo + 20) + imposto;
        System.out.println("O Valor é de: R$ " + valore);
    }
}

Browser other questions tagged

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