Quote (carteblanche @ Apr 23 2016 08:10pm)
know what would be helpful? posting the compile error and highlighting which lines of code is causing it. nobody here is gonna compile your code, so the onus is on you to give as much info as you can.
as for my suggest of comparing = and == you can look at this link:
http://www.javacoffeebreak.com/faq/faq0022.htmlok thanks, and sorry for being rude.
error i get:
Code
Animal2.java:24: error: cannot find symbol
dog.omnivore = true;
^
symbol: variable omnivore
location: variable dog of type Animal2
Animal2.java:25: error: cannot find symbol
tiger.carnivore = true;
^
symbol: variable carnivore
location: variable tiger of type Animal2
Animal2.java:26: error: cannot find symbol
skunk.herbavore = true;
^
symbol: variable herbavore
location: variable skunk of type Animal2
Animal2.java:28: error: cannot find symbol
System.out.println("Dog is a " + dog.check());
^
symbol: method check()
location: variable dog of type Animal2
Animal2.java:29: error: cannot find symbol
System.out.println("tiger is a " + tiger.check());
^
symbol: method check()
location: variable tiger of type Animal2
Animal2.java:30: error: cannot find symbol
System.out.println("Skunk is a " + skunk.check());
^
symbol: method check()
location: variable skunk of type Animal2
http://pastebin.com/W28JGSpMAlso my updated code:
Code
class Animal {
boolean omnivore;
boolean carnivore;
boolean herbavore;
void check() {
if(omnivore == true) System.out.println("is an omnivore");
if(carnivore == true) System.out.println("is an carnivore");
if(herbavore == true) System.out.println("is an herbavore");
}
}
class Animal2 {
public static void main(String args[]) {
Animal2 dog = new Animal2();
Animal2 tiger = new Animal2();
Animal2 skunk = new Animal2();
dog.omnivore = true;
tiger.carnivore = true;
skunk.herbavore = true;
System.out.println("Dog is a " + dog.check());
System.out.println("tiger is a " + tiger.check());
System.out.println("Skunk is a " + skunk.check());
}
}
http://pastebin.com/ZeESQHMeThis post was edited by ferf on Apr 23 2016 08:02pm