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, Pyramid a sided pyramid, Pyramid a 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 ScannerSystemin;
public static ShapesInterface getShape
int numberOfShapes ; Change this value to the number of current shapes as you add new shapes.
int randomValue intMathrandom numberOfShapes;
ShapesInterface newShape null;
switchrandomValue
case :
newShape new Triangle;
break;
case :
newShape new Cone;
break;
case :
newShape new Pyramid;
break;
case :
newShape new Pyramid;
break;
case :
newShape new Square;
break;
case :
newShape new Cube;
break;
return newShape;
public static ShapesInterface selectShape
ShapesInterface newShape null;
boolean shapeNotSelected true;
int menuValue ;
double height ;
double base ;
double radius ;
do
shapeNotSelected false;
System.out.printlnSelect from the following shapes:";
System.out.println Triangle";
System.out.println Cone";
ifkeyboard.hasNextInt
keyboard.nextLine;
menuValue ;
else
menuValue keyboard.nextInt;
keyboard.nextLine;
switchmenuValue
case :
System.out.printlnYou selected a Triangle.";
System.out.printlnPlease enter the length of the base.";
whilekeyboard.hasNextDouble
keyboard.nextLine;
System.out.printlnInvalid entry.";;
System.out.printlnPlease enter the length of the base.";
base keyboard.nextDouble;
System.out.printlnPlease enter the height of the triangle.";
whilekeyboard.hasNextDouble
keyboard.nextLine;
System.out.printlnInvalid entry.";;
System.out.printlnPlease enter the height of the triangle.";
height keyboard.nextDouble;
keyboard.nextLine;
newShape new Triangleheight base;
break;
case :
System.out.printlnYou selected a cone.";
System.out.printlnPlease enter the radius of the base.";
whilekeyboard.hasNextDouble
keyboard.nextLine;
System.out.printlnInvalid entry.";;
System.out.printlnPlease enter the radius of the base.";
radius keyboard.nextDouble;
System.out.printlnPlease enter the height of the cone.";
whilekeyboard.hasNextDouble
keyboard.nextLine;
System.out.printlnInvalid entry.";;
System.out.printlnPlease enter the height of the cone.";
height keyboard.nextDouble;
keyboard.nextLine;
newShape new Coneheight radius;
break;
case :
newShape new Pyramid;
break;
case :
newShape new Pyramid;
break;
case :
newShape new Square;
break;
case :
newShape new Cube;
break;
default:
shapeNotSelected true;
whileshapeNotSelected;
return newShape;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
