Question

In: Computer Science

Java. You are creating a 'virtual pet' program. The pet object will have a number of...

Java.

You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of the pet class which will be a specific type of pet, and at least one instance of that class.

Attributes
An attribute is a characteristic of a pet. Each attribute is essentially a list of values. For example, a hunger attribute may have values from "famished" through "content" to "bloated." There should be some way to check the value of the attribute, as well as to increase and decrease the value. Note that you will be expected to create some sort of abstract data type (ADT) to represent the attribute. You are not yet building SPECIFIC attributes (like hunger or happiness) but a type that represents the common characteristics of all attributes. You might use an interface or an abstract class to generate your abstraction, but plan it first as an abstract data type.

Specific Attributes
Once you have created a generic attribute class, make some subclasses to represent the specific attributes you want your pets to have. If you designed the ADT well, creating specific subclasses should be quite easy. The main method of the specific classes should test the main functionality of the class.

Making your abstract pet
Now create a pet class that uses the attributes you have generated. This class is also abstract, as it represents just a type of pet. It will include attributes as data members, and it may also have other characteristics. You may also add methods that indicate actions the user can take with the pet, including things like feed and play (which may affect attributes) and perhaps other activities like rename (which might change another data member of the pet) and sleep (which might indicate the passage of time.)

Build a specific pet class
Finally you should be able to build a specific type of pet (like a lizard or a unicorn) that inherits from the pet class. This should begin (of course) with characteristics derived from the abstract pet, but you could then add new attributes or behaviors specific to your type of pet.

The main method of this pet class should instantiate an instance of the pet and indicate all the things it can do.

Create an interface for interacting with the pet.
Build some type of tool for interacting with the pet. At minimum this should allow the user to create a pet, interact with it in the ways you have defined, save its current status for future play (using object serialization) and load a previously saved pet.

Solutions

Expert Solution

Hi,

Sample java classes below:

Overall structure of the code:

////////////////


public abstract class Pet {
   private String hunger;
   private String happiness;
   private String name;
  
  
  
   /**
   * @param hunger
   * @param happiness
   * @param name
   */
   public Pet(String name) {
       super();
       this.hunger ="";
       this.happiness ="";
       this.name = name;
   }
  
  
   /**
   * @return the name
   */
   public String getName() {
       return name;
   }
   /**
   * @param name the name to set
   */
   public void setName(String name) {
       this.name = name;
   }
   /**
   * @return the hunger
   */
   public String getHunger() {
       return hunger;
   }
   /**
   * @param hunger the hunger to set
   */
   public void setHunger(String hunger) {
       this.hunger = hunger;
   }
   /**
   * @return the happiness
   */
   public String getHappiness() {
       return happiness;
   }
   /**
   * @param happiness the happiness to set
   */
   public void setHappiness(String happiness) {
       this.happiness = happiness;
   }

}


/////////////////


public class Dog extends Pet implements Interact {

   private int age;
  

   /**
   * @param hunger
   * @param happiness
   * @param name
   * @param age
   */
   public Dog(String name, int age) {
       super(name);
       this.age = age;
   }

   /**
   * @return the age
   */
   public int getAge() {
       return age;
   }

   /**
   * @param age the age to set
   */
   public void setAge(int age) {
       this.age = age;
   }

   @Override
   public void feed() {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void play() {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void sleep() {
       // TODO Auto-generated method stub
      
   }

}


/////////////////////////

/**
*
*/

public interface Interact {
   public void feed() ;

   public void play() ;
  
   public void sleep() ;
}


///////////////////////

import java.util.Scanner;

public class PetMain {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner input=new Scanner(System.in);
       int choice;
       Dog dog=null;
       String petName="";
       int petAge=0;
       System.out.println("Interact with Pet..");
       System.out.println("1.Create Pet..");
       System.out.println("2.Feed Pet..");
       System.out.println("3.Play with Pet..");
       System.out.println("4.Make Pet Sleep..");
       choice=input.nextInt();
      
       switch(choice) {
       case 1:
           System.out.println("Enter Pet name..");
           petName=input.next();
           System.out.println("Enter Pet age..");
           petAge=input.nextInt();
           dog=new Dog(petName,petAge);
           break;
       case 2:
           dog.feed();
           break;
       case 3:
           dog.play();
           break;
       case 4:
           dog.sleep();
           break;
       }
   }

}

/////////////////////////////////////////

Kindly, provide some implementation to the methods.

Let me know if you need more help on this.
Hope this helps.


Related Solutions

Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
You have written a JAVA program that creates Shoe object with three instance variables. You will...
You have written a JAVA program that creates Shoe object with three instance variables. You will need to use the exception you created to go along with it. So far you have been using my driver classes. Now it is time for you to create your own driver class that will implement an ArrayList of Shoe objects. This assignment uses the Shoe.java and ShoeException.java to create the driver ShoeStore.Java You will display a menu as follows: Add shoes Print all...
Write a java program using the information given Design a class named Pet, which should have...
Write a java program using the information given Design a class named Pet, which should have the following fields (i.e. instance variables):  name - The name field holds the name of a pet (a String type)  type - The type field holds the type of animal that a pet is (a String type). Example values are “Dog”, “Cat”, and “Bird”.  age - The age field holds the pet’s age (an int type) Include accessor methods (i.e. get...
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your...
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your own threaded program using the threadExtend.java code and the threadRunnable.java code. A.) Focus the threadExtend.java code DETAILS TO NOTE: - It creates 4 instances of the same thread. This means that the thread code is actually running 4 separate times - The thread accepts 2 parameters, an INTEGER from 1 to 4, as well as an ID - Note the parameters are hard coded...
This question is about the java Object-Oriend program and give the code as follow requirment: You...
This question is about the java Object-Oriend program and give the code as follow requirment: You are a software engineer who has to write the software for a car transmission. The transmission has five gears numbered from 1 to 5 to move forward, one neutral gear position numbered 0 where the car does not move, and one reverse gear numbered -1 to move backward. The transmission has a clutch, and the driver of the car can only change gear if...
Java Program General Scenario: You are creating an interactive application that gets input from the keyboard...
Java Program General Scenario: You are creating an interactive application that gets input from the keyboard and keeps track of a grocery store that a businessman runs. In order to develop this application, you will be using 2 interfaces, 1 abstract class, and 1 concrete class. You should use the interfaces and the abstract class to create the concrete class. Your application should have overridden toString() at appropriate places so that you could display the object state, i.e., the string...
A company that makes pet food is interested in creating dry and canned pet food. The...
A company that makes pet food is interested in creating dry and canned pet food. The company is also interested in what cats and dogs prefer their pet food to be (dry or canned). At the 5% significance level can you conclude that type of pet is independent of pet food choice? Canned Dry Total Dog 25 25 50 Cat 20 30 50 Total 45 55 100 Reject the null hypothesis, type of pet is independent of pet food choice...
Describe how you would develop object-oriented features of Java for the Quiz program developed in the...
Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners.
Describe how you would develop object-oriented features of Java for the Quiz program developed in the...
Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners. Your Discussion should be at least 250 words in length, but not more than 750 words. Once you’ve completed your initial post, be sure to respond to the posts of at least 3 of your classmates.
using java For this assignment, you will write a program that guesses a number chosen by...
using java For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to choose a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT