Java
TOPIC 10 – MATH FUNCTIONS

AP EXTRA

 

AP LESSON WORK

 

 

QUESTION 1

Write the program that will reproduce the following output.  Note that the min function only works on two values at once.  Also, the four marks below are entered by the user.

 

SAMPLE OUTPUT

 

What is your Period 1 mark?

76

 

What is your Period 2 mark?

81

 

What is your Period 3 mark?

59

 

What is your Period 4 mark?

78

 

Your worst mark is 59. 

 

QUESTION 2


We will look at a minor variation of the Weapon class from a previous lesson.  The class has only three datafields:

 

·         name

·         lowDamage

·         highDamage

The lowDamage and highDamage give the range of the damage that the weapon can make.  So if lowDamage is 7 and highDamage is 12, then the Weapon will do 7-12 damage.

 

ACTIONS

 

After creating the class above, write the code that represents the following actions.

 

1-Create a weapon called "Staff".  Its damage is 6-10.

 

2-Your character is in a battle and you need to calculate how much damage the Staff does.  In other words, you need to generate a random number between 6 and 10.  Test your program several times to makes sure the number fits.

 

3-Create another weapon called "Thor's Hammer".  Its damage is 210-250.

 

4-Thor is in a battle and swings his hammer 5 times at five different enemies. Write the statements required to generate the five different damage amounts.