User Tools

Site Tools


virtual_pet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
virtual_pet [2026/03/01 14:31] – [Try this GUI Runner] frchrisvirtual_pet [2026/03/01 15:02] (current) – [Part C] frchris
Line 126: Line 126:
 </file> </file>
 ===== Activity 4 ===== ===== Activity 4 =====
 +==== Part A: Food ====
 <file java Food.java> <file java Food.java>
 /** /**
Line 132: Line 132:
  * @author (your name)  * @author (your name)
  * @version (a version number or a date)  * @version (a version number or a date)
 + 
 + * A Food object is created with parameters that define the name of the food, 
 + * the increase in energy level, the increase in happiness level, 
 + * and the amount of weight gained if the food is consumed by a 
 + * VirtualPet object. 
 + 
 + * The Food class provides a constructor with the following header: 
 + * public Food(String name, int energyIncrease, int happinessIncrease, int weightGain). 
 + * The Food class also has accessor methods for all instance variables.
  */  */
 public class Food public class Food
Line 140: Line 149:
 } }
 </file> </file>
 +==== Part B: Game ====
 <file java Game.java> <file java Game.java>
 /** /**
Line 172: Line 181:
 } }
 </file> </file>
 +
  
  
Line 333: Line 343:
 } }
 </file> </file>
- ==== GUI Based Runner for Activity 4 ====+==== Part C Putting it all together ==== 
 + 
 +Now that we have a Game and Food class, let’s revise the VirtualPet class to include interactions with these classes.  
 +  - Write the class VirtualPet4. You may copy your code implementation of VirtualPet from Activity 3 but be sure to modify the class header and constructor to match the new class name.  
 + 
 +  - Modify the ''feed()'' method to take a ''Food'' parameter. The method should increase the ''energy'' level, ''happiness'' level, and ''weight'' of the virtual pet object based on the ''getEnergyRating()'', getHappinessRating(), and getWeightGain() accessor methods of the Food parameter. It is possible for the ''happiness level'' to decrease depending on the ''Food'' consumed.  
 + 
 +  - Modify the ''play()'' method to take a ''Game'' parameter and return a ''boolean'' value indicating whether the game was won. The method should decrease the weight based on the ''getWeightLoss()'' accessor method of the ''Game'' parameter. Remember, the weight can not go below the minimum ''weight'' value. The method should also increase the ''happiness'' level only if the ''Game parameter’s'' accessor method ''isWinner()'' returns ''true''. The method should decrease the happiness level if isWinner() returns false. The method should return the same value returned by ''isWinner()''. (Note: Be sure to call ''isWinner()'' only once in the method. Repeated calls may result in different return values.)  
 + 
 + === GUI Based Runner for Activity 4 ===
  
   - [[https://mathorama.com/apcs2/petHappy.gif|petHappy.gif]]   - [[https://mathorama.com/apcs2/petHappy.gif|petHappy.gif]]
Line 726: Line 745:
 ===== Activity 5 ===== ===== Activity 5 =====
  
-==== Try this GUI Runner ====+==== Adding Your Own Features ====
 Copy your code from ''Food.java'' and ''Game.java'' to your working project for Activity 5. Copy your code from ''VirtualPet4.java'' to a new file named ''VirtualPet5.java''. Be sure to modify your class header to match the name of your ''.java'' file.   Copy your code from ''Food.java'' and ''Game.java'' to your working project for Activity 5. Copy your code from ''VirtualPet4.java'' to a new file named ''VirtualPet5.java''. Be sure to modify your class header to match the name of your ''.java'' file.  
  
-Implement two new features in your VirtualPet5 class or Game class. Your new features should add instance variables and/or methods to your VirtualPet5 class. +Implement two new features in your ''VirtualPet5'' class or ''Game'' class. Your new features should add instance variables and/or methods to your ''VirtualPet5'' class. 
  
 The following are ideas for additional features, inspired by the original Tamagotchi:  The following are ideas for additional features, inspired by the original Tamagotchi: 
Line 736: Line 755:
   - Your virtual pet will randomly get sick and need to be given medicine.    - Your virtual pet will randomly get sick and need to be given medicine. 
   - Your virtual pet will notify the user if their energy level is 0, if their happiness level is 0, if they are sick, or if they used the bathroom and need to be cleaned.     - Your virtual pet will notify the user if their energy level is 0, if their happiness level is 0, if they are sick, or if they used the bathroom and need to be cleaned.  
-  - Create a more interactive game in the Game class for the VirtualPet to play. +  - Create a more interactive game in the Game class for the ''VirtualPet'' to play. 
virtual_pet.1772393484.txt.gz · Last modified: by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki