permaculture playing cards*
The moose likes Beginning Java and the fly likes Inheritance program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance program" Watch "Inheritance program" New topic
Author

Inheritance program

Diana Aldueza
Greenhorn

Joined: Oct 29, 2002
Posts: 1
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
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
I don't see a declaration for the variable "Type"; what is it?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Larry Jones
Greenhorn

Joined: Oct 22, 2002
Posts: 24
Looks like Type is a String. To compare strings you need to use the equals() method.
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
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.


comp.lang.javascript FAQ: http://jibbering.com/faq/
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Also note that 'd' is a char, while "d" is a String. These are not at all the same thing!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance program