+1 (315) 557-6473 

Program To Create Shape Manager and Area Calculator Using Java Programming Language Assignment Solutions.


Instructions

Objective
Write a java assignment program to create a shape manager and area calculator.

Requirements and Specifications

Objective
The purpose of this assignment is to practice enums, exceptions, and unit testing. You will implement and modify a few classes that solve a programming task, and then you will write a small tester to test your code. No tester will be provided for this assignment.
Overview
  1. Analyze the ShapeManager class and the interface it uses, AreaCalculator.
  2.  Analyze the Shape class hierarchy, used to represent a limited set of shapes.
  3.  Analyze the enum named MeasuringUnit, used to represent the shape sides’ unit of measurement (FEET, or METER).
  4. Implement the exception classes ShapeException, MeasuringUnitException and
  5. AreaCalculatorException, which shall be used to signal improper values and impossible actions relating to classes.

  6. Write a class named E3Tester that performs unit testing for the classes.
  7. Prepare the assignment for submission and submit it through Blackboard
Source Code
SHAPE MANAGER
import java.util.Arrays;
public class ShapeManager implements AreaCalculator {
 public static final MeasuringUnit defaultUnit = MeasuringUnit.METERS;
 public Shape[] shapes;
 public ShapeManager (Object[][] values) {
  initShapes(values.length);
  values2Shapes(values);
 }
 public void initShapes(int length){
  this.shapes = new Shape[length];
 }
 public void setShapes(Shape[] shapes){
  if(shapes == null){
   throw new IllegalArgumentException();
  }
  this.shapes = shapes;
 }
 public Shape[] getShapes(){
  if(this.shapes == null){
   throw new IllegalStateException();
  }
  return this.shapes;
 }
 public void values2Shapes(Object[][] values){
  for(int i = 0; i < values.length; i++){
   Object[] value = values[i];
   switch(value.length){
    case 2:
    shapes[i] = new Square((MeasuringUnit)value[0], (int)value[1]);
    break;
    case 3:
    shapes[i] = new Rectangle((MeasuringUnit)value[0], (int)value[1], (int)value[2]);
    default:
   }
  }
 }
 // the default measuring unit is determined by defaultUnit
 public long convertArea(long area, MeasuringUnit ms){
  return 0l;
 }
 // the default measuring unit is determined by defaultUnit, use this.getShapes() for sum of the areas
 public long getTotalArea(){
  // this is not complete, it is a hint.
  long result = 0;
  for(Shape shape: this.getShapes()){
   result+=shape.getArea();
  }
  return result;
 }
 // the default measuring unit is determined by defaultUnit, use this.getShapes() for sum of the areas
 public long getTotalArea (MeasuringUnit ms){
  return 0l;
 }
}
SQUARE
public class Square extends Shape{
 public int side;
 public Square (MeasuringUnit unit, int side) {
  super(unit, side);
  this.side = side;
 }
 public void setSide(Integer side){
  this.side = side;
 }
 public int getArea(){
  return this.side * this.getSide();
 }
 public String toString(){
  return "Square: {_side: " + side + ", side: " + super.getSide()+"}";
 }
}
AREA CALCULATOR
public interface AreaCalculator{
 // returns the parameter area from the implementer's default measuring unit to the one given by the unit parameter
 public long convertArea(long area, MeasuringUnit ms)throws CheckedRuntimeException;
 // returns the sum of the areas determined by the implementer from the implementer's default measuring unit to the one given by the unit parameter.
 public long getTotalArea (MeasuringUnit ms) throws CheckedRuntimeException;
 // returns the sum of the areas determined by the implementer using the implementer's default measuring unit
 public long getTotalArea () throws CheckedRuntimeException;
}