Q BgQuestion:

      
Pupil
Karma Points: 97
Respect (94%):
posted by  Kyorochan on 11/21/2009 9:06:52 AM  |  status: Closed  |  Earned Karma: 97

Java: Classes and Objects

Course Textbook Chapter Problem Needs by
N/A N/A N/A N/A 11/21/2009 at 6:00:00 PM
Question Details:
A pet store sells dogs, cats, birds, and hamsters. Write a declaration for an enumeratered data type that can represent the types of pets the store sells.
Bonus Point Alert! Earn +7 additional karma points for helping this gold member.

AAnswers:

Answer Question Ask for clarification
Oracle
Karma Points: 24,207
posted by sam__GT(MND) on 11/21/2009 9:23:53 AM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
//Here is EnumTest.java, hope this will help you.

enum Day {
    dogs, cats, birds, hamsters
}

 class EnumTest {
Day day;
public EnumTest(Day day) {
this.day = day;
}
public void tellItLikeItIs() {
switch (day) {
case cats: System.out.println("catss are cute.");
    break;
case dogs: System.out.println("dogs are brave.");
    break;
    
case birds: System.out.println("Birds can fly.");
    break;
case hamsters:
System.out.println("hamsters are there ");
break;
default:
System.out.println("I don't know");
break;
}
}
public static void main(String[] args) {
EnumTest firstDay = new EnumTest(Day.cats);
firstDay.tellItLikeItIs();
EnumTest thirdDay = new EnumTest(Day.hamsters);
thirdDay.tellItLikeItIs();
EnumTest seventhDay = new EnumTest(Day.dogs);
seventhDay.tellItLikeItIs();
}
}






Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »