Question: I need to write a Java program that matches the following structure: Here is my code thus far, but Im having some issues with override

I need to write a Java program that matches the following structure:

I need to write a Java program that matches the following structure:Here is my code thus far, but Im having some issues with override for the interface and what the print function should be:

// First Interface

package myProgram;

public interface I_twoD { float computeArea(); float computePerimeter(); }

// Second Interface

package myProgram;

public interface I_threeD { float computeVolume(); }

// Shape.java

package myProgram;

import java.awt.Color;

public abstract class Shape { protected Color mColor; protected String mName; // Constructor public Shape(Color mColor, String mName) { this.mColor = mColor; this.mName = mName; } // Getter for name public String getName() { return mName; } // Getter for color public Color getColor() { return mColor; } // Setter for name public void setName(String mName) { this.mName = mName; } // Setter for color public void setColor(Color mColor) { this.mColor = mColor; } // Still confused on printf() }

// Circle.java

package myProgram;

import java.awt.Color;

public class Circle extends Shape implements I_twoD { // Local variable private final float mRadius; // Constructor public Circle(Color mColor, String mName, float mRadius) { super(mColor, mName); this.mRadius = mRadius; }

// Not sure if this is correct @Override public float computeArea() { return (float) (this.mRadius * this.mRadius * Math.PI); } // Not sure if this is correct @Override public float computePerimeter() { return (float) (this.mRadius * Math.PI * 2); } }

// Square.java

package myProgram;

import java.awt.Color;

public class Square extends Shape implements I_twoD { // Local variable protected float mSide; // Constructor public Square(Color mColor, String mName, float mSide) { super(mColor, mName); this.mSide = mSide; } // Interface I_twoD.java @Override public float computeArea() { return (this.mSide * this.mSide); } @Override public float computePerimeter() { return (float)(this.mSide * 4); } }

// Cube.java

package myProgram;

import java.awt.Color;

public class Cube extends Square implements I_threeD { // Constructor public Cube (Color mColor, String mName, float mSide) { super(mColor, mName, mSide); this.mColor = mColor; this.mName = mName; this.mSide = mSide; }

@Override public float computeVolume() { return (this.mSide * this.mSide * this.mSide); } }

Shape + Color mColor + String mName > Shape(Color, String) +getName() String +getColor() Color + setName(String) + setColor(Color) + print() I twoD I threeD +computeArea() + computePerimeter() +compute Volume( Cube Square Circle + float mSide +float mRadius > > > Cube(Color, String, float) Square(Color, String, float) Circle(Color, String, float)

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 Databases Questions!