Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do parts a and b in java language. Where it asks please use the input file fortunes.txt. It's not important what is in the

Please do parts a and b in java language. Where it asks please use the input file fortunes.txt. It's not important what is in the file but please use file input and outputs as needed.

image text in transcribed

image text in transcribed

Geniegotchi! Part a: Write a class called Geniegotchi with: 1. Private data fields: 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 new Name, prints newName confirmation to screen; void genieInfo(): prints to screen the Genie's current name, current endurance 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 file; 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 happiness 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 actions 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Are emotional appeals ethical? Why or why not? [LO-4]

Answered: 1 week ago