Submit the source code .java files on Ecampus under the "Submit Homework" menu option.


1
. In a single file named shapes.java, write class definitions for a square based Pyramid and a Cone.  These classes should have a constructor to pass values for the class variables.

Pyramid class variables:  Width, Height
Pyramid class methods:  getVolume(),  getSurfaceArea()
Cone class variables:  Radius, Height
Cone class methods:  getVolume(),  getSurfaceArea()

Your main program should ask the user to enter values for each of the variables and output the volume and surface area of the pyramid and cone.  The code below will help you get started with the main program.

import java.util.*;
public class shapes
{
   public static void main(String[] args)
   {
      // ask user to enter values for pyramid Width and Height here

      // declare instance of the Pyramid class and send width and height as parameters

      Pyramid Luxor = new Pyramid(Width, Height);

      // output volume and surface area of pyramid
      System.out.println("Volume = " + Luxor.getVolume() + " cubic meters") ;
      System.out.println("Surface area = " + Luxor.getSurfaceArea() + " square meters");

      // do the same thing with the Cone class
   }
}

// Pyramid class goes here

// Cone class goes here



2
.  Write a class definition for an Enemy for your game.java

Enemy Class

Variables Description
int Xpos, Ypos X,Y location of the enemy.  The top left of the screen will be 1,1.
char Avatar The character that will be displayed on the screen representing the type of enemy.
String Type Enemy type such as "Orc" or "Troll".
int HP Hitpoints of the enemy.  The enemy is deceased when HP is 0.
int Attack Attack rating of the enemy: The higher the number, the more damage is does.
int Armor Armor rating of the enemy: The higher the armor, the less damage it takes.
Methods Description
Enemy(String theType) Constructor that takes 1 parameters - theType

Initialize your class variable to the parameter:
Type = theType;

Set Xpos and Ypos to random numbers from 0 to 9.

In the constructor, you will set these things based on the Type:  Avatar, HP, Attack, Armor.  For example:
if (Type.equals("Orc"))

   Avatar = 'O';  HP = 50;  Attack = 5;  Armor = 20;
}

Write a main program to demonstrate your Enemy class:

1.  Create an object of each of enemy (at least 3 different types).
2.  Create a 10x10 array of characters named World (same as in homework 2).
3.  Put the Avatar character of each of the 3 types of enemies into the World.
4.  Display World (same as in homework 2)

Example output below showing a dragon, orc, and troll in random locations.

. . . D . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . O . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . T . . .
. . . . . . . . . .

. . . . . . . . . .