Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part a: Write a class called Geniegotchi with: 1. Private data elds: name (of St

ID: 3763461 • Letter: P

Question

Part a: Write a class called Geniegotchi with:
1. Private data elds: name (of String type, initialized to Bob"), endurance (of int
type, initialized to 4) and happiness (of int type, initialized to 3);
2. Public methods:
void setName(String newName) : renames Genie with newName, prints
newName con rmation to screen;
void genieInfo() : prints to screen the Genie's current name, current en-
durance level and current happiness level;
int getEndurance() : returns current endurance;
int getHappiness() : returns current happiness;
void feed() : this method increases current endurance by 1 if endurance is
less than 10, otherwise it prints a No, thanks..." message to the screen;
void play() : if happiness is less than 10, then this method increases current
happiness by 1 and decreases current endurance by 2, otherwise it prints a
No, thanks..." message to the screen;
void askFortune() :
if happiness is greater than 6 and endurance is greater than 5 (that is, if your
Genie is happy and healthy enough to predict your fortune...), then:
{ using Math.random(), pick a random number ran between 1 and 100
(inclusive);
{ display to the screen the fortune from line number ran in the fortunes.txt
le;
1
if happiness is greater than 6 but endurance is at most 5, then:
{ display message to screen regarding low endurance;
if endurance greater than 5 but happiness is at most 6, then:
{ display message to screen regarding low happiness;
if both endurance and happiness are at most 5 and 6 respectively, then:
{ display message telling user to feed and play with the Geniegotchi.
Regardless of branch, this method should reduce both endurance and hap-
piness by 1.
Part b: Write a class called GeniegotchiDemo containing two static methods:
1. public static void printMenu() :
Prints a welcoming message and the menu.
0 - Quit
1 - Rename your Geniegotchi
2 - Get current stats on Geniegotchi
3 - Feed your Geniegotchi
4 - Play with your Geniegotchi
5 - Ask your fortune!
6 - Print Menu
(keep options and functionality the same, but feel free to customize these strings)
2. public static void main(String[] args) :
instantiates a Geniegotchi object;
prints the menu;
repeatedly asks for user to enter menu option and performs appropriate ac-
tions given user input until user selects 0;
Other than the game stopping when user selects 0 (which should print a nice good
bye message), the game should also stop if the Geniegotchi runs out of happiness or
endurance (the user is messaged that the Geniegotchi has run away either hungry or
unhappy).
Part c: In a text le called genie.txt, answer the following questions:

Propose a new method for the Geniegotchi class. Provide its signature and de-
scribe what it does (what it takes, what it returns, etc). You do not have to
implement it.
2
Notes:
Please keep the given class names, variable names, method names and array of
String literals (fortunes) exactly as given. For other strings/variables you may
have creative license or use your judgment.
Please display the messages printed to the screen nicely, that is with appropriate
spacing and new lines.
Please stick to the description of the assignment. If you want to make a cooler
version of the game with a GUI or something else, you can do that after submitting
the version described here.

I have alaready finished part a and part b.

I have no idea about part c.

Explanation / Answer

Part-A

Geniegotchi.java

import java.io.BufferedReader;
import java.io.EOFException;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;


public class Geniegotchi
{
   private String name="Geniegotchi";
   private int endurance =4;
   private int happiness =3;
   public void setName(String newName)
   {
       this.name=newName;
       System.out.println("New name"+this.name);
   }
   public void genieInfo()
   {
       System.out.println("Genie