0

I'm trying to use encapsulation to assign values to variables via user entry, but my set methods aren't recognizing my variables. My code is as follows:

static class Sneakers{
    //Declare variables
    private String brand;   //can be changed by the user
    private double size;    //can be changed by the user
    
    //Constructor
    public Sneakers() {
        //set values
        brand = null;
        size = 0;
    }//end sneaker constructor
    
    //get methods
    public String getBrand() {
        return brand;
    }
    
    public double getSize() {
        return size;
    }
    
    //set methods
    public void setBrand(String brand) {
        this.brand = brand;
    }
    
    public void setSize(double size) {
        this.size = size;
    }
    
    //user input method
    public void Input() {
        System.out.println("Please enter the brand of your shoes. Ex: Nike ");
        Scanner sc = new Scanner(System.in);
        brand = sc.nextLine();
        System.out.println("Please enter the size of your shoes. Ex: 10.5 ");
        size = Double.valueOf(sc.nextLine());
        sc.close();
    }
}

//main method
public static void main(String[] args) {
    System.out.println("Thank you for donating your shoes to charity! Can you provide us with some extra information?");
    
    //declare an instance of the sneaker class
    Sneakers bBall = new Sneakers();
    bBall.Input();
    bBall.setBrand(brand);
    bBall.setSize(size);
    System.out.println("You are about to donate size " + bBall.getSize() + " " + bBall.getBrand() + " shoes.");
    System.out.println("We appreciate your donation! Come again soon!");
}

When I try to run this code it gives me an error at these two lines in my main method

bBall.setBrand(brand);

bBall.setSize(size);

I'm completely lost here. How can I fix this?

0 Answers0