Sign in
Log inSign up

Getting an error here and not sure why.. Help??

William Egan's photo
William Egan
·Jan 2, 2018
public void setModel(String model) {_model = model;} // private variable has _ other is supplied make
public void setMake (String make) {_make = make; }
public void setYear (int year)   //{_year = year; } 

// year can't be less than 1900 or more than 2015
{
    while(year < 1900 || year > 2015)
    {
        System.out.println("Please enter valid year");
        year = scan.nextInt();

    }
    _year = year;

This code works, but if I allow {_year = year} to run in my

'year' setter it won't recognise the variable 'year' in my while loop..

Can somebody explain to me in simple terms why this is the case?