Question

In: Computer Science

(YOU don't need to write the client class I already have it, just need this) You...

(YOU don't need to write the client class I already have it, just need this)

You are provided with Main.java that is a client for this program.

You will create THREE files-- GameCharacter.java, ShieldMaiden.java, and Dragon.java

First: You must Create an interface called GameCharacter WITH JUST PROTOTYPES, NO IMPLEMENTATIONS

A GameCharacter has a few functions associated with it

1) takeHit: decreases the character's health. It should return an int representing damage taken (hit points)

2) heal: increases the character's health. Should return an int representing amount healed (i.e. hit points)

3) getHealth: returns the total current health the character has (i.e. hit points)

4) isAlive: determines if the character is dead. Should return true if the character is dead, and false if not.

Second: Then create two classes. One should be named Dragon, and the other should be named ShieldMaiden (i.e. warrior) that IMPLEMENT Game Character. Give them each private variables for health. The constructor should take in an initial amount to set health to.

Third: Implement the interface functions for these two classes (Dragon and ShieldMaiden). To make the game more interesting, the dragon's takeHit should hurt the dragon a random number from 10 to 20 inclusive and the ShieldMaiden's takeHit should hurt the shieldMaiden a random number from 15 to 25 inclusive. Furthermore, the dragon's heal should only heal the dragon a random number from 1 to 10 inclusive but the ShieldMaiden's heal should heal the ShieldMaiden a random number from 8 to 20 inclusive. A character is dead when they get negative health.

Solutions

Expert Solution

package java1;
import java.util.*;
import java.util.Random;

interface GameCharacter{
public int takeHit();
public int heal();
public int getHealth(int health);
public boolean isAlive();
}


class ShieldMaiden implements GameCharacter{
public static void main(String[] args){
private int healthShieldMaiden;
Random rand = new Random();
public int getHealth(int health){
healthShieldMaiden=health;
return healthShieldMaiden;
}
public int takeHit(){
int n = rand.nextInt(20+1) + 10;
healthShieldMaiden=healthShieldMaiden-n;
return healthShieldMaiden;
}
public int heal(){
int n=rand.nextInt(21)+8;
healthShieldMaiden=healthShieldMaiden+n;
return healthShieldMaiden;
}
public boolean isAlive(){
if(healthShieldMaiden<0){
return true;
}
else{
return false;
}
}

}
}

public class Dragon implements GameCharacter{
public static void main(String[] args){
private int dragonHealth;
Random rand = new Random();

public int getHealth(int health){
dragonHealth=health;
return dragonHealth;
}
public int takeHit(){
Random rand = new Random();
int n = rand.nextInt(25+1) + 15;
dragonHealth=dragonHealth-n;
return dragonHealth;
}
public int heal(){
int n=rand.nextInt(11)+1;
dragonHealth=dragonHealth+n;
return dragonHealth;
}
public boolean isAlive(){
if(dragonHealth<0){
return true;
}
else{
return false;
}}}

}

ShieldMaiden class output::

0-->for getHealth

THIS STATEMENT BASED UPON COMPILER // int n = rand.nextInt(20+1) + 10;
NEGATIVE VALUE...> FOR      takeHit()

heal ...> -VE

isAlive..> false

Dragonclass output::

0-->for getHealth

NEGATIVE VALUE...> FOR      takeHit()
heal ...> -VE

isAlive..> false


Related Solutions

JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to...
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to use all methods, also switch statements. Write a Temperature class. The class will have three conversion methods: toCelsius(), toKelvin() and toFahrenheit(). These methods will return a Temperature in those three scales equal to the this temperature. Note that the value of this is not changed in these conversions. In addition to these three conversion methods the class will have methods add(Temperature), subtract(Temperature), multiply(Temperature), and...
I need a full answer ...not a part.. please and you don't have to explain just...
I need a full answer ...not a part.. please and you don't have to explain just give me a answer plesase.. question 1 . Match the following, each choice is used once. 1. Levering System a. long or irregular bones b. synovial joint c. how things move d. muscle power e .object to be moved 2. Pivot (Fulcrum) a. long or irregular bones b. synovial joint c. how things move d. muscle power e .object to be moved 3. Effort...
Minerals question i have named all 16 minerals already i just need the function Major or...
Minerals question i have named all 16 minerals already i just need the function Major or trace ,Food Source,Name of deficiency or symptoms of deficiency,and toxicity and yes or No answer. There will be a total of 16 minerals (7 major & 9 trace) Minerals Name – both name and number if given Function Major or trace if minerals 4 food sources Name of deficiency or symptoms of deficiency Toxicity Yes or no 1.Calcium 2.Magnesium 3.Potassium 4.Sodium 5.Sulfer 6.Phosphorous 7.Chloride...
I NEED PART 2 COMPLETED I ALREADY COMPLETED 1A-D COURSE PROJECT 1 INSTRUCTIONS You have just...
I NEED PART 2 COMPLETED I ALREADY COMPLETED 1A-D COURSE PROJECT 1 INSTRUCTIONS You have just been contracted as a new management trainee by Earrings Unlimited, a distributor of earrings to various retail outlets across the country. In the past, the company has done very little in the way of budgeting and at certain times of the year has experienced a shortage of cash. Since you are well trained in budgeting, you have decided to prepare a master budget for...
I already answered the first three questions and put the answer down I just don't know...
I already answered the first three questions and put the answer down I just don't know how to answer the last question which asks to calculate K in the rate law? A clock reaction is run at 20 ºC with several different mixtures of iodide, sodium bromate and acid, to form iodine. Thiosulfate is used to react with the iodine formed initially. Starch indicator is added to form a blue color when all the thiosulfate has been used up and...
I have this question in my nursing class I just need someone to answer it for...
I have this question in my nursing class I just need someone to answer it for me Reflect on an occasion where you experienced ineffective leadership (doesn't have to be in the hospital/healthcare). What behaviors did they display? What factors may have influenced their leadership style?
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't...
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't need the number entries. I attached the balance sheet in case you need it for reference Problem - Your required tasks are as follows: On the designated worksheet, prepare in journal entry form the adjusting journal entries for the following items. Letter entries to correspond to the below information and present them in alphabetical order. (Round all numbers to the nearest dollar) On June...
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't...
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't need the numbers. I attached the balance sheet in case you need it for reference Problem - Your required tasks are as follows: On the designated worksheet, prepare in journal entry form the adjusting journal entries for the following items. Letter entries to correspond to the below information and present them in alphabetical order. (Round all numbers to the nearest dollar) a) On June...
I need to take the code i already have and change it to have at least...
I need to take the code i already have and change it to have at least one function in it. it has to include one function and one loop. I already have the loop but cant figure out how to add a function. I thought i could create a funciton to call to the totalCost but not sure how to do it. Help please. #include #include //main function int main(void) {    char userName [20];    char yesOrNo [10];   ...
Just need 2a and 2b answered. Already have number one. Just included in case you needed...
Just need 2a and 2b answered. Already have number one. Just included in case you needed it for part two. 1. On January 1, 2020, Hawkeye Air leased a new airplane for a term of 8 years. The expected life of the airplane is 20 years. There are no rights to purchase the asset at the end of the term, no bargain purchase option, and no residual value guarantee. The lease stipulates that Hawkeye Air makes annual payments of $550,000...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT