Virtual Pet Game Development Assignment
Introduction
The Virtual Pet Game is an application which created through which people are able to take care of an artificial animal. Encapsulation, inheritance, polymorphism and abstraction as some of the basic principles of object oriented programming are incorporated in this project to make the gaming environment more appealing, as well as making the structure of the project organized. Users can take pet on lease, take care of their health and plays with them by feeding, playing or providing rest. Every pet has certain parameters like hunger, happiness, health, energy which are always in the process of changing depending on the users’ actions.
The project step were segmented into the three general tasks as described below; Task 1 is to model the system before implementing and this will require the developers to draw the UML Class and Object diagrams. The second task involves creating base classes in Java primarily relating to the core operations concerning pets. In Task 3, the game is expanded with such features as interactions with users, pet’s actions, and pet’s health, using ArrayList to mimic the database. The game also includes a sick state with mechanic due to which the health of the pets becomes low and they need some treatment. It means if the Pet of the user reaches the zero value, the Pet data is deleted from the list.
Task 1: UML Class and Object Diagrams
Since the Virtual Pet Game is going to be a complex design, there is a need to adopt a clear structure to facilitate the implementation process. The next step towards the development of the system is the creation of the necessary diagrams using Unified Modeling Language (UML). This will issue a great understanding of how all the components works with the other in the program. The first task involves modelling UML Class and Object Diagram that explains the features in the game appropriately (Nagineni, 2021). These can be used as frameworks for implementation of the system in Java so as to facilitate organized and manageable code.
In the Virtual Pet Game, there will be a number of avatars which users will be able to create and tend for. Each pet overlaps features such as hunger, happiness level, health and energy that is in form of tokens shift according to instances that occur between the user. The animals vary in behaviors, and despite the fact that they are pets that may include dogs, cats, and fish they are not entirely similar. Hence the use of object-oriented principles like inheritance, polymorphism, encapsulation and abstraction are directly relevant in the design of this system.
Class Diagram for the Virtual Pet Game
The UML Class Diagram gives a conceptual perspective of the different classes in the system and their communications. It involves features, behaviors, and relations of the distinct entities what are presented in the provided CSV table. Based on the analysis of the above description, the main classes in system are: Pet, Dog, Cat, Fish, User and VirtualPetGame.

Figure 1: Class Diagram
(Source: Self-designed using draw.io)
The Pet class is an abstract class that serves as the blueprint for all the pets that you will find on the site. These are known attributes which are hunger, happiness, health, and energy. The class also includes the methods that control the interaction with the user like feeding, playing and resting. Because every pet that is to be created is bound to exhibit some specific behaviors, there is the abstract method referred to as uniqueBehavior().
From this class, there are three subclasses namely Dog, Cat and Fish, which also have the method uniqueBehavior(). Every subclass of the pet class presents its own implementation of this method to represent certain pet behaviors (Krismadinata et al., 2023). For instance, a Dog moves its tail to show joy, a Cat makes a low sound and a Fish glides through water smoothly.
The User class is the model that describes the player or a person who can take care of up to three pets. It uses an ArrayList to keep a list of pets indicating the capability to dynamically store the Pet class objects. Functions like addPet() allow the management of pets for each user by efficiently adding a new pet to the list of pets, removeDeadPets() to delete the pets that are no longer existing hence helpful in managing the pets of each specific client.
The VirtualPetGame is the initial class of the application and the one that controls the others. It has the list of pets and users of the game and offers choices for users so that they can engage in the game (Brown et al., 2022). This is basically a menu driven system that will enable the users to be able to perform other activities like creating of a user, adoptions of the pets or may be playing with the pets.
Object Diagram for a Scenario
UML Class Diagram is more general and affects the whole system whereas Object Diagram represents the instance taken at a certain time when the program runs. This is evident on how objects are made and even their interactions occur in a real worldly game environment.

Figure 2: Object Diagram
(Source: Self-designed using draw.io)
For instance, consider publishing References wherein a user Alice has adopted a Dog Buddy and a Cats Whiskers; an Object diagram can illustrate this relation. Based on the diagram, it can be seen that the two pet objects related to Alice are Buddy and Whiskers with attributes hunger, happiness, health, and energy. The state of each pet evolves as they feel the effects of the interaction coming from Alice.
Applying Object-Oriented Principles in Design
The Virtual Pet Game is developed with the principles of Object-Oriented Programming (OOP) due to the needs for scalability, maintainability, and code reuse.
Encapsulation is used to hide or shield all new pet attributes by declaring them as either private or protected in order to be accessed through set and get only. This acts as a barrier to the alteration of pet attributes by any other entities other than the class itself, a measure that protects the data recently set.
The application of inheritance is done by using the Pet class which is a parent class to the subclasses of Dog, Cat, and Fish. This means that the code will not be repetitive since most of the attributes and behaviors are defined in one place while the specific behaviors are just inherited in subclasses.
Polymorphism is achieved in overriding especially in the uniqueBehavior() method. Each pet subclass has its own implementation of this method, which offers dynamic responsiveness when it is executed.
In the Pet class, a method uniqueBehavior() is declared abstract, implying that the Pet class cannot have an implementation but the subclass must provide an implementation of the method. This makes it mandatory that all the pet types should state their particular behavior fully without having to alter the base class.
Task 2: Implementing the Virtual Pet Game in Java
Following the design of the Virtual Pet Game using UML Class and Object Diagrams, the next step is to code the system in Java. The game is programmed in such a manner, using entities such as inheritance, polymorphism, encapsulation, as well as abstraction to make the source code understandable and manageable (Dev.java, 2024). This phase emphasizes the implementation of classes given in Task 1 where the major focus is to ensure that the classes are coded and they interconnect optimally.
The main aspect of the Virtual Pet Game is that one can adopt more than one pets and take care of them by feeding, playing with, and putting them to rest, and check their health and condition. It is then possible to implement a menu driven approach to let the users be able to easily execute these actions. The game also allows pets to have different actions depending on the type of pet and also has a method of treating an ill pet.
Defining the Pet Class and its Subclasses
The Pet class is the base class for Pet type in the game where all the game’s specified pet types descend from it. These include attributes such as hunger, happiness, health, and energy, which make up the pet’s status. The class contains methods to feed, play, and rest with it; the functionality of this class is to make the user interact with pets.

Figure 3: Pet Class (Initial Stage)
(Source: Self-coded using java)
Because various types of pets may have different behaviors as per requirements, an abstract method named uniqueBehavior() has been included in the Pet class. This way, there will be no overlapping of features associated with a particular pet type (Christopher and Waworuntu, 2021). There is also the isSick() and isDead() which will be used in the function of checking on the pet’s state of health. If the health reaches certain level, the pet becomes sick, and if the health is diminished to zero then the pet will be excluded by the user’s list.
Figure 4: Subclasses of Pet Class (Initial Stage)
(Source: Self-coded using java)
The classes Dog, Cat and Fish are sub classes of Pet class in which they override the abstract method uniqueBehavior(). A Dog barks happily and wags its tail, a Cat is purring quietly, and a Fish swims in a non-violent manner. These classes mean that each kind of a pet acts in a typical manner to imply their types.
Handling Sick Pets with an Interface
In order to make the game more realistic, a new interface called SickPet is developed. The class includes the treatSickPet() method whereby a pet gets well when treated. It could be implemented only by some of the subclasses, namely Dogs and Cats, because these types of pets need some extra attention when they get sick. However, the program does not contain the SickPet operation because in real life fish cannot recover easily from sickness.
Figure 5: Sick or dead pet handling
(Source: Self-coded using java)
As a result, the specific subclasses, the Dog and the Cat, were able to extend the ‘SickPet’ interface and refine the treatSickPet() method. When a sick dog or a cat is treated, they improve in their health making the pet regain health and can be active again in playing with the user (Eclipse.org, 2025). This makes use of interface here as it enable broad separation of loose coupling hence enabling the inclusion of new type of pets with distinct treatment mechanism in future.
User Class and Pet Management
The User class refers to the players who own and nurture pets. A user is an object and as we already said, it is characterized by a single name and a List of pets, implemented through an ArrayList. There can only be three pets per user to avoid adoption of a large number of pets in a single time.
Figure 6: Add pet to user
(Source: Self-coded using java)
The addPet() method enables the user to choose and bring in a pet from a list of pets available for adoption. A user cannot adopt more than three pets, but if for instance, a user has three pets then the user has to give out one before he is allowed to adopt any other pet. The removeDeadPets () method is used to prevent the existence of dead pets, which is necessary for a natural game flow when the pet’s health is equal to zero.
Figure 7: Display pets
(Source: Self-coded using java)
The displayPets() function is a way for a user to check the status of the pets: hunger, happiness, health, and energy levels for each of them. It therefore assists the user in determining how to behave in around his or her pets.
Implementing the Virtual Pet Game Class
The VirtualPetGame class is the main class of the game that processes the inputs from the user and oversees the game flow. It keeps two lists of available pets and the users, thus chalking out the way in which the game has to function (GeeksforGeeks, 2023). The initial method of the game is initializeGame () which creates a set of dogs, cats and fish which users will adopt.
Figure 8: Game Initiation
(Source: Self-coded using java)
There is also the adoption of a menu in order to enable the users to engage in the activities practiced in the game. Individuals are able to register an account, nurture their pets and perform certain activities on the pets. Depending on the selected action, the game alters some of the attributes of the selected pet. This is useful in situations where hunger, happiness, or energy reaches a dangerous level and the game advises the user what they have to do.
Figure 9: User Management
(Source: Self-coded using java)
The manageUser() method enables a user to choose a pet of his or her choice then perform what he or she wants to do with the particular pet. They can feed the pet, play with it, nap with it or tend to it, and in case the pet is ill, they can tend to it, if the kind of pet allows tending to it.
Figure 10: Game output
(Source: Self-coded using java)
Task 3: Enhancing the Virtual Pet Game with Improved Functionality
In the third task, further development of the Virtual Pet Game is done with more enhancements on pet management, user engagement and overall creativity of the game. The goal is to make the game environment more lifelike and obliged to pay necessary attention to the cute pets. New features are added such as an improved flow of pet attributes, new user interface, and advancement in the SickPet interface. Such changes make the game more interesting because pets are bound to act differently and therefore, demand attention.
There are three major improvement categories that belong to this phase. Part A deals with improving of the pet class hierarchy in order to achieve better object-oriented approach. Part B improves the usability of the system for pet management and creates better opportunities in adopting new pets and their further care (GeeksforGeeks, 2017). Part C enhances gameplay functionality by following: The game possesses a structured and hierarchical menu To help the player to know the status of his/her pet, the system provides automated status updates Some user interfaces prompt the player depending on the action that they are undertaking. These additions increase marketed gimmicks, but at the same time, the main intent of the creating game is kept in a way that does not cause it to become impossible to play or achievable all at once.
Part A: Refining the Pet Class Hierarchy
Pet class has changes to make dynamic attribute initialization possible. The new idea is that instead of having specific set of static numbers for hunger, happiness, health, and energy each pet has individual values at his or her creation. This gives a diversification among pets, which brings out the element of surprise and hence increases the interest when playing the game.
The uniqueBehavior() method stays permanently empty in the Pet class and child classes are expected to override it with concrete implementations. Furthermore, there is modification of the SickPet interface so that the pet that falls sick is handled in an organized manner (Galindo et al., 2023). Dogs and cats meet the interface to treat and become healthy and the fish do not implement the interface because they do not receive treatment as do the dogs and cats. This differentiation makes pet care more tactical, in addition to forcing the players to be attentive while taking care of the pet.
Part B: Improving User and Pet Management
The class of the User is advanced to offer a systematic way of handling the pets. Individuals can choose to adopt up to three pets and there is a message that appears when the limit of pets has been reached by the user. The displayPets() has been changed to present an interface of pets in an elaborated form by states rather than figures. For example, the glossary includes such qualities as “Full,” “Hungry,” and “Exhausted” which helps players determine the state of their dogs.
Figure 11: Display Pets with status
(Source: Self-coded using java)
Next is a new system for updating the pet’s status automatically. As time passes, hunger appears, energy depletes, and happiness varies, which reminds people about active pet care. In the other method, removeDeadPets(), the pets which have hit zero health are eliminated from the list of pets in the application, belonging to that particular user (Gresta et al., 2023). This feature created in the game keeps the players busy with the pets hence the need to always interact with them.
Figure 12: Removal of dead pets
(Source: Self-coded using java)
Social relations between people and animals that were previously limited to feeding them or playing with them. Pets also have chance to recharge energy and if need be be treated if they fall sick. This contributes to the realism in the game, and by extension, the fun and entertainment of the players avoid doing repetitious things just to satisfy the pets.
Part C: Enhancing Gameplay Mechanics and Interactions
In order to improve the gameplay experience, a new class called VirtualPetGame is introduced here to replace the existing one. It also subscribes to a new menu system for the acquisition of pets, their management and even for checking their status . A detailed user selection process allows a player to either carry on with a game or create a new user hence avoiding the creation of multiple users.
Figure 13: Main Class of the game
(Source: Self-coded using java)
It also brings improvement to the process of pet adoption. Pets are now classified according to species so that particular species of pets of choice can be adopted instead of picking random kinds of pets. In order to make sure that each of the pets is distinctive once a pet is adopted, it is relocated from the available pets list.
It is possible add minigames related to resting and sickness treatment, which brings new dimensions to the gameplay. Some get bored and sleepy which leads to taking their rest while those that suffer from an illness need to be treated if the species is one that is allowed to be cured (Eck, 2021). This makes the system much more interesting and fair for the players to implement their plans for interaction.
Figure 14: Game output
(Source: Self-coded using java)
To increase the level of challenge in the game, the concept of background update is incorporated into the game. It is also important to clarify that over time, the pets’ characteristics evolve—hunger, energy levels, and happiness, for instance. Pet neglect results in pet illness or even death, thus it is better than encouraging occasional interactions with the pets.
Conclusion
As a result of the Virtual Pet Game, the tasks that the project comprises developed greatly in the three tasks set. Task 1 completed laid the ground work where only the framework of pets, users and their relationship was created. Task 2 contributed to making the game more advanced by developing on the pet class hierarchy and adding significant game elements such as feeding, playing and resting of the pet thereby improving the required skills relating to pet care. In the last task, the pet attributes became more dynamic with new upgrades, while the flexibility of user management increased as well as numerous additional pet functionalities such as curing an illness, resting.
The principles of object-oriented design have been used to maintain encapsulation and extensibility as the main aspects during the development of the game. Inheritance worked effectively to set up various behaviors to different types of pets and interfacing was simple in the best way possible.
Finding Java, UML diagrams, or OOP concepts challenging? Our assignment help online create well-structured, fully functional programming solutions aligned with university grading standards—so you can submit confidently and score higher.
Reference List
Brown, N.C., Weill-Tessier, P., Sekula, M., Costache, A.L. and Kölling, M., 2022. Novice use of the Java programming language. ACM Transactions on Computing Education, 23(1), pp.1-24.
Christopher, L. and Waworuntu, A., 2021. Java programming language learning application based on octalysis gamification framework. IJNMT (International Journal of New Media Technology), 8(1), pp.65-69.
Dev.java, 2024. Building a Java Application in the Eclipse IDE - Dev.java. [online] Available at: https://dev.java/learn/eclipse/ [Accessed on: 7 Mar. 2025].
Eclipse.org, 2025. Help - Eclipse Platform. [online] Available at: https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2FgettingStarted%2Fqs-3.htm [Accessed on: 7 Mar. 2025].
Galindo, C., Pérez, S. and Silva, J., 2023. Program slicing of Java programs. Journal of Logical and Algebraic Methods in Programming, 130, p.100826.
GeeksforGeeks, 2017. Classes and Objects in Java. [online] GeeksforGeeks. Available at: https://www.geeksforgeeks.org/classes-objects-java/ [Accessed on: 7 Mar. 2025].
GeeksforGeeks, 2023. Java OOP(Object Oriented Programming) Concepts. [online] GeeksforGeeks. Available at: https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-in-java/ [Accessed on: 7 Mar. 2025].
Gresta, R., Durelli, V. and Cirilo, E., 2023. Naming practices in object-oriented programming: An empirical study. Journal of Software Engineering Research and Development, 11(1), pp.5-1.
J Eck, D., 2021. Introduction to programming using Java. Hobart and William Smith Colleges.
Krismadinata, E., Boudia, C., Jama, J. and Saputra, A.Y., 2023. Effect of Collaborative Programming on Students Achievement Learning Object-Oriented Programming Course. Int. J. Inf. Educ. Technol, 13(5), pp.792-800.
Nagineni, R.B., 2021. A Research on Object Oriented Programming and Its Concepts. Andhra Pradesh, India: International Journal of Advanced Trends in Computer Science and Engineering.
Singh, N., Chouhan, S.S. and Verma, K., 2021, October. Object oriented programming: Concepts, limitations and application trends. In 2021 5th International Conference on Information Systems and Computer Networks (ISCON) (pp. 1-4). IEEE.
tpointtech.com, 2025. Java OOPs Concepts - Tpoint Tech. [online] Available at: https://www.tpointtech.com/java-oops-concepts [Accessed on: 7 Mar. 2025].
Tutorialspoint.com, 2025. Eclipse - Create Java Project. [online] Available at: https://www.tutorialspoint.com/eclipse/eclipse_create_java_project.htm [Accessed on: 7 Mar. 2025].
W3schools.com, 2025. W3Schools.com. [online] Available at: https://www.w3schools.com/java/java_oop.asp [Accessed on: 7 Mar. 2025].
Winkelmann, H., Troost, L. and Kuchen, H., 2022, April. Constraint-logic object-oriented programming for test case generation. In Proceedings of the 37th ACM/SIGAPP Symposium on Applied Computing (pp. 1499-1508).
