• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

variables not found with OOP

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.html
  • cat.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 functionality
  • As 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
    reply
      Bookmark Topic Watch Topic
    • New Topic