| Author |
variables not found with OOP
|
Ben Hultin
Ranch Hand
Joined: Aug 17, 2009
Posts: 135
|
|
I am trying out my hand at OOP and I have run into a problem regarding variables not found between two files (the driver and the driven class).
driver class
driven class
The errors I am getting refer to the lines of code in the driver class at the bottom
HultinBenWeek6Prog.java:117: cannot find symbol
symbol : variable name
location: class HultinBenWeek6Prog
myCat1.set(name, age, weight);
^
HultinBenWeek6Prog.java:117: cannot find symbol
symbol : variable age
location: class HultinBenWeek6Prog
myCat1.set(name, age, weight);
^
HultinBenWeek6Prog.java:117: cannot find symbol
symbol : variable weight
location: class HultinBenWeek6Prog
myCat1.set(name, age, weight);
^
HultinBenWeek6Prog.java:118: cannot find symbol
symbol : variable breed
location: class HultinBenWeek6Prog
myCat1.setBreed(breed);
^
HultinBenWeek6Prog.java:119: cannot find symbol
symbol : variable declawed
location: class HultinBenWeek6Prog
myCat1.setDeclawed(declawed);
^
HultinBenWeek6Prog.java:120: cannot find symbol
symbol : variable name
location: class HultinBenWeek6Prog
myCat1.setName(name);
^
HultinBenWeek6Prog.java:121: cannot find symbol
symbol : variable age
location: class HultinBenWeek6Prog
myCat1.setAge(age);
^
HultinBenWeek6Prog.java:122: cannot find symbol
symbol : variable weight
location: class HultinBenWeek6Prog
myCat1.setWeight(weight);
^
8 errors
|
 |
Rok Ć telcer
Ranch Hand
Joined: Nov 03, 2009
Posts: 101
|
|
Hi,
Before starting with OOP in any language, you should master the basis or language fundamentals per se first.
Hm ... where should I start.
OK, following has to be corrected:
class name should always start with an uppercase ... naming convention.
Check the following ling: http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.htmlcat.input method stores all results in local vars (not class member vars).
Meaning that all results will be lost after the method completes (local scope)No need for Scanner class in HultinBenWeek6Prog ... has no functionalityAs I already mentioned before, change the input method.
For example:
String name = input.next();
change with
setName( input.next() );
This how, you'll store the results in member vars ... meaning they will be available as long as the object lives (or particular member is not changed/modified)WRONG:
# myCat1.set(name, age, weight);
# myCat1.setBreed(breed);
# myCat1.setDeclawed(declawed);
# myCat1.setName(name);
# myCat1.setAge(age);
# myCat1.setWeight(weight);
vars like name, age, weight, etc. are declared in class Cat not in HultinBenWeek6Prog ... beside this, they are private (java access modifier) --> encapsulation ... well, except declawed.
Remove the all above lines. Or you can leave them in order to demonstrate the member modification ...
I think, this is all.
Regards,
Rok
|
SCJP, SCWCD
|
 |
 |
|
|
subject: variables not found with OOP
|
|
|