• 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

Inheritance program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does:
if(Type='d'){
System.out.println("Please enter the Furlength");
String FurLength = Keyboard.readString();
System.out.println("Please enter the Size of the dog");
String Size = Keyboard.readString();
pets [petCount] = new Dog(Name, Sex, Age, FurLength, Size);
}
else if(Type='c'){
System.out.println("Please enter the FurColor of the Cat");
String FurColor = Keyboard.readString();
System.out.println("Please enter the EyeColor of the Cat");
String EyeColor = Keyboard.readString();
pets [petCount] = new Cat(Name, Sex, Age, FurColor, EyeColor);
}
else if(Type='b'){
System.out.println("Please enter the FeatherColor");
String FeatherColor = Keyboard.readString();
System.out.println("Please enter the BeekColor of the Bird");
String BeekColor = Keyboard.readString();
pets [petCount] = new Bird(Name, Sex, Age, FeatherColor, BeekColor);
}
else{
System.out.println("You have entered the wrong option!");
}
not work. The error I get says:
found:java.lang.String
required:boolean
if(Type='d')
but I tried if(Type=='d')
and it still wont work. Can anyone help me find out whats wrong.
Thanks
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see a declaration for the variable "Type"; what is it?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like Type is a String. To compare strings you need to use the equals() method.
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if(Type='d') is an assignment, so like you figured, you need a boolean statement - if(Type == 'd') is a boolean statement.
Try
if("d".equals(Type)){
...
}
Try changing, recompiling, and testing again.

You said you changed = to == .

You got an error that says (Type='d') when you program uses (Type == 'd') -which is probably not what you want if Type is a String
means that you're running the wrong program or forgot to compile.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also note that 'd' is a char, while "d" is a String. These are not at all the same thing!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic