Question: Using the attached Eclipse Project, InterfaceAndPolymorphismAssignment.zip Download InterfaceAndPolymorphismAssignment.zip, add four more shape classes, Pyramid 4 a 4 - sided pyramid, Pyramid 3 a 3 -

Using the attached Eclipse Project, InterfaceAndPolymorphismAssignment.zip Download InterfaceAndPolymorphismAssignment.zip, add four more shape classes, Pyramid4 a 4-sided pyramid, Pyramid3 a 3-sided pyramid, Square, and Cube. You may add more shapes than these if you would like.
Each new shape class will implement the ShapesInterface.
You will then need to update the ShapeGenerator class to properly generate new objects of these classes.
Note that the TestDriver class never creates variables of the shape classes. It is using variables of the ShapesInteface class to access the methods of the shape objects.
Once you have made the necessary changes export your Eclipse project to a zip file and submit it to this page.
/**
*
*/
import interfacePackage.ShapesInterface;
import objectsPackage.Cone;
import objectsPackage.Triangle;
import java.util.Scanner;
/**
* @author Larry Shannon
*
*/
public class ShapeGenerator
{
private static Scanner keyboard = new Scanner(System.in);
public static ShapesInterface getShape()
{
int numberOfShapes =2; //Change this value to the number of current shapes as you add new shapes.
int randomValue =(int)(Math.random()* numberOfShapes);
ShapesInterface newShape = null;
switch(randomValue)
{
case 0:
newShape = new Triangle();
break;
case 1:
newShape = new Cone();
break;
// case 2:
// newShape = new Pyramid4();
// break;
// case 3:
// newShape = new Pyramid3();
// break;
// case 4:
// newShape = new Square();
// break;
// case 5:
// newShape = new Cube();
// break;
}
return newShape;
}
public static ShapesInterface selectShape()
{
ShapesInterface newShape = null;
boolean shapeNotSelected = true;
int menuValue =0;
double height =0.0;
double base =0.0;
double radius =0.0;
do
{
shapeNotSelected = false;
System.out.println("Select from the following shapes:");
System.out.println("1) Triangle");
System.out.println("2) Cone");
if(!keyboard.hasNextInt())
{
keyboard.nextLine();
menuValue =0;
}
else
{
menuValue = keyboard.nextInt();
keyboard.nextLine();
}
switch(menuValue)
{
case 1:
System.out.println("You selected a Triangle.");
System.out.println("Please enter the length of the base.");
while(!keyboard.hasNextDouble())
{
keyboard.nextLine();
System.out.println("Invalid entry.");;
System.out.println("Please enter the length of the base.");
}
base = keyboard.nextDouble();
System.out.println("Please enter the height of the triangle.");
while(!keyboard.hasNextDouble())
{
keyboard.nextLine();
System.out.println("Invalid entry.");;
System.out.println("Please enter the height of the triangle.");
}
height = keyboard.nextDouble();
keyboard.nextLine();
newShape = new Triangle(height, base);
break;
case 2:
System.out.println("You selected a cone.");
System.out.println("Please enter the radius of the base.");
while(!keyboard.hasNextDouble())
{
keyboard.nextLine();
System.out.println("Invalid entry.");;
System.out.println("Please enter the radius of the base.");
}
radius = keyboard.nextDouble();
System.out.println("Please enter the height of the cone.");
while(!keyboard.hasNextDouble())
{
keyboard.nextLine();
System.out.println("Invalid entry.");;
System.out.println("Please enter the height of the cone.");
}
height = keyboard.nextDouble();
keyboard.nextLine();
newShape = new Cone(height, radius);
break;
// case 3:
// newShape = new Pyramid4();
// break;
// case 4:
// newShape = new Pyramid3();
// break;
// case 5:
// newShape = new Square();
// break;
// case 6:
// newShape = new Cube();
// break;
default:
shapeNotSelected = true;
}
}while(shapeNotSelected);
return newShape;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!