Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35983

Java error variable symbol not find

Hi all I have a problem into my program Java, I have already import io input in the mother project and isnt that the problem. The error is:

C:\Users\test\Desktop\Prodotto.java:26: cannot find symbol
symbol : variable input
location: class Prodotto
line=input.readLine();
^

And this is the program. How can I solve that?

public class Prodotto
{
String descrizione;
double prezzoVendita;
int giacenza;
String line;


Prodotto(){}

void Valore()
{
    System.out.print("Valore di magazzino = ");
    System.out.println(giacenza*prezzoVendita);
}

void Carico()
{
    int carico=0;
    String line;
    do
    {
        try
        {
            System.out.println("Di quanto è aumentata la giacenza?");
            line=input.readLine();
            carico=Integer.parseInt(line);
        }
        catch (Exception e)
        {
            System.out.println("il carico deve essere maggiore di 0");  
        }

        if(carico<=0)
        {

        }
        else
        {
            giacenza=giacenza+carico;   
        }
    }
    while(carico<=0);
}

void Scarico()
{
    int scarico=0;
    String line;
    do
    {
        try
        {
            System.out.println("Di quanto è diminuita la giacenza?");
            line=input.readLine();
            scarico=Integer.parseInt(line);
}
catch (Exception e)
{
System.out.println("la giacenza non può essere minore di 0");
}

if(scarico<=0)
{

}
else
{
giacenza=giacenza-scarico;
}
}
while(giacenza<=0);
}

void Visualizza()
{
System.out.println("Descizione prodotto = "+ descrizione);
System.out.println("Prezzo di vendita = "+ prezzoVendita);
System.out.println("giacenza = "+ giacenza);
}
}

Upvotes: 0

Views: 115

Answers (2)

user2163298
user2163298

Reputation: 655

import the scanner class with with the following:

import java.util.Scanner;

Then create an instance of the Scanner class with the following:

Scanner input = new Scanner(System.in);

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1504122

The compiler is absolutely right (as I'd expect it to be) - you never declare a variable called input. Think about why you expected it to work, what you expected the variable type to be, where you expected it to be initialized etc.

Given that you're using it from two different methods, you may well want it to be an instance variable... and perhaps you wanted it to be a Scanner? It's important to think about this though - to work out why you expected it to work. If you've just been copying code from other places, reflect on how important it is to really understand code before including it in your own program.

Additionally, it would be a good idea to follow Java naming conventions, and to indent your code for readability.

Upvotes: 4

Related Questions