0

I am writing a program that stretches over 3 different java files

  1. pencil.java
  2. pencilbox.java
  3. schoolbad.java

I have defined a couple of variables using setter and getter commands in Pencil, that are appropriately being pulled and used in Pencilbox. How ever for some reason it is not able to locate one variable, the getBrand variable.

Pencil:

public String getbrand()
{
return brand; 
}
public void setBrand(String brand){
this.brand=brand;
}

PencilBox:

public String toString(){
return type1.getColor() + " " + type1.getBrand + "$" + (type1.getPrice()*qty1) + "\n" 
+ type2.getColor() + " " + type2.getBrand + "$" + (type2.getPrice()*qty2) + "\n$" + grandTotal();
}

But I keep getting these two errors:

symbol: variable getBrand location: variable type1 of type Pencil

and this:

symbol: variable getBrand location: variable type2 of type Pencil

Why is the public variable not accessible in the second program? getColor and getPrice worked with no problem. Can someone please explain?

0

3 Answers 3

3

You're missing brackets and should be lower case b e.g. try type1.getbrand() etc

Sign up to request clarification or add additional context in comments.

Comments

0

getBrand() is a method ,so you have to call it with paranthesis ()

type1.getBrand()

Comments

0

Correct with this and try

type1.getBrand() 

1 Comment

Alternatively (preferably), correct the capitalization of the method declaration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.