Question
*JAVA ONLY* In my attached java file, I completed the code but need help with the syntax errors? // Create an interface named shape public
*JAVA ONLY*
In my attached java file, I completed the code but need help with the syntax errors?
// Create an interface named "shape"
public interface Shape extends Comparable
{
// Declare the methods
// This abstract method is implemented at the concrete level.
public double calculateArea();
public Shape copyShape();
}
/*********** File Name: AbstractShape.java ***********/
// Create an abstract class named "AbstractShape"
public abstract class AbstractShape implements Shape
{
// Declare a string variable named "name"
private String name;
// Create a parameter constructor
public AbstractShape(String name)
{
this.name = name;
}
// Create a default constructor
public AbstractShape()
{
name = "";
}
// Create a Accessor for the variable named "name"
public String getName()
{
return name;
}
// Create a "toString()" method
public String toString()
{
return "Shape[name=" + name + ",area=" + calculateArea() + "]";
}
}
/*********** File Name: Circle.java ***********/
// Create a class named "Circle"
public class Circle extends AbstractShape
{
// Declare varaibles
public double myRadius;
private static int myID;
// Create a default constructor
public Circle()
{
myRadius = 0.00;
myID = 0;
}
// Create a parameter constructor
public Circle(double myRadius)
{
myID = 0;
}
// Create a method named "setRadius()" to store the radius
public void setRadius(final double theRadius) {
myRadius = theRadius;
myID++;
}
// Create a method named "calculateArea()" to calculate the radius
@Override
public double calculateArea()
{
return Math.PI * myRadius * myRadius;
}
// Create a method named "copyShape()" to copy the objects
@Override
public final Shape copyShape()
{
Circle newC = new Circle();
newC.myRadius = myRadius;
return newC;
}
// Create method named "compareTo()" to compare two shape objects.
@Override
public int compareTo(Shape o)
{
// TODO Auto-generated method stub
return new Double(this.calculateArea()).compareTo(new Double(o.calculateArea()));
}
// Create a method named "toString()" to return the output
public String toString()
{
return "Circle" + myID + "[Radius:" + myRadius + "] Area:" + String.format("%.02f", calculateArea());
}
}
/************ File Name: Rectangle.java **********/
// Create a class named "Rectangle"
public class Rectangle extends AbstractShape
{
// Declare variables
double myLength, myWidth;
private static int myID;
// Create a default constructor.
public Rectangle()
{
myLength = 0.00;
myWidth = 0.00;
myID = 0;
}
// Create a parameter constructor.
public Rectangle(final double theLength, final double theWidth)
{
myLength = theLength;
myWidth = theWidth;
myID = myID + 1;
}
// Create a method named "setLength()" to store the length
public void setLength(final double theLength)
{
myLength = theLength;
}
// Create a method named "setWidth()" to store the width
public void setWidth(final double theWidth)
{
myWidth = theWidth;
}
// Create a method named "calculateArea()" to calculate the area of the rectangle.
@Override
public double calculateArea()
{
return myWidth*myLength;
}
// Create a method named "copyShape()" to copy the shape
@Override
public final Shape copyShape()
{
Rectangle newR = new Rectangle();
newR.myLength = myLength;
newR.myWidth = myWidth;
return newR;
}
// Create a method named "compareTo()" to compare shapes
@Override
public int compareTo(Shape o)
{
return new Double(this.calculateArea()).compareTo(new Double(o.calculateArea()));
}
// Create a method named "toString()" to return the output as per the instructions.
public String toString()
{
return "Rectangle" + myID + "[Length: " + myLength + ", Width: " + myWidth + "] Area:" + String.format("%.02f", calculateArea());
}
}
/*********** File Name: Triangle.java *********/
// Create a class named "Triangle"
public class Triangle extends AbstractShape
{
// Declare the variables
double mySideA, mySideB, mySideC;
private static int myID;
// Create a default constructor.
public Triangle()
{
mySideA = 0.00;
mySideB = 0.00;
mySideC = 0.00;
myID = 0;
}
// Create a parameter constructor.
public Triangle(final double theSideA, final double theSideB, final double theSideC)
{
mySideA = theSideA;
mySideB = theSideB;
mySideC = theSideC;
myID = myID + 1;
}
// Create a method named "setSideA()" to store the first side of the triangle
public void setSideA(final double theSideA)
{
mySideA = theSideA;
}
// Create a method named "setSideB()" to store the second side of the triangle
public void setSideB(final double theSideB)
{
mySideB = theSideB;
}
// Create a method named "setSideC()" to store the third side of the triangle
public void setSideC(final double theSideC)
{
mySideC = theSideC;
}
// Create a method named "calculateArea" to calculate the area of the triangle.
@Override
public double calculateArea()
{
double side4 = (mySideA + mySideB + mySideC) / 2;
return Math.sqrt(side4 * (side4 - mySideA) * (side4 - mySideB) * (side4 - mySideC));
}
// Create a method named "copyShape" to copy the triangle shape
@Override
public final Shape copyShape()
{
Triangle newT = new Triangle();
newT.mySideA = mySideA;
newT.mySideB = mySideB;
newT.mySideC = mySideC;
return newT;
}
// Create a method named "compareTo()" to compare the two triangle shapes
@Override
public int compareTo(Shape o)
{
return new Double(this.calculateArea()).compareTo(new Double(o.calculateArea()));
}
// Create a method named "toString()" to return the output.
public String toString()
{
return "Traingle" + myID + "[SideA: " + mySideA + ",SideB: " + mySideB + ",SideC:" + mySideC + "] Area: " + String.format("%.02f", calculateArea());
}
}
/*********** File Name: Assignment7.java **********/
// Create a class named "Assignment7"
public class Assignment7
{
// Create a "main" method
public static void main(String[] args)
{
// Declare a variable
String input = "in7.txt";
try (BufferedWriter bw = new BufferedWriter(new FileWriter("out7.txt")))
{
// Create a linked list
LinkedList myList = new LinkedList();
// Create a list named "copyList" and assign the return array list
// which getting data from the method getOriginalList()
List copyList = getOriginalList(input, myList);
List newList = new ArrayList();
for (Shape element : myList)
{
Shape s = element.copyShape();
s.toString();
newList.add(s);
}
//System.out.println(" Original List[unsorted]:");
bw.write("Original List[unsorted]:");
for (Shape element : myList)
{
Shape s = element.copyShape();
//System.out.println(s.toString());
bw.write(" " + s.toString());
}
Collections.sort(copyList);
//System.out.println(" Copied List[sorted]:");
bw.write(" Copied List[sorted]:");
for (Shape element : copyList)
{
Shape s = element.copyShape();
//System.out.println(s.toString());
bw.write(" " + s.toString());
}
//System.out.println(" Original List[unsorted]:");
bw.write(" Original List[unsorted]:");
for (Shape element : newList)
{
Shape s = element.copyShape();
//System.out.println(s.toString());
bw.write(" " + s.toString());
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
// Create a method named "getOriginalList()" which takes a string and a linked list of shape objects
public static ArrayList getOriginalList(String input, LinkedList myList)
{
// Create an array list to store the resulted objects.
ArrayList arrayList = new ArrayList();
// Create an object for a class named "Circle"
Circle circleObj = new Circle();
// Create an object for a class named "Rectangle"
Rectangle rectangleObj;
// Create an object for a class named "Triangle"
Triangle triangleObj;
// Create a try block to handle the run time exceptions
// Open a file using the classes named "BufferedReader" and "FileReader"
try (BufferedReader br = new BufferedReader(new FileReader(input)))
{
String sCurrentLine;
boolean notDigit = false;
String[]pLine;
// Create a "while" loop to every line in the input file
while ((sCurrentLine = br.readLine()) != null)
{
// Split the each number and store in the array named "pLIne"
pLine = sCurrentLine.split(" ");
notDigit = false;
String[]values = sCurrentLine.split(" ");
// Create a "for" loop to check the words are numbers or not.
for (int i = 0; i
{
if (notDigit == true)
{
break;
}
try
{
double checkDatatype = Double.parseDouble(values[i]);
}
catch (Exception ex)
{
notDigit = true;
break;
}
}
if (notDigit == false)
{
if (pLine.length == 1)
{
double radius = Double.parseDouble(values[0]);
circleObj.setRadius(radius);
myList.add(circleObj);
}
if (values.length == 2)
{
double length = Double.parseDouble(values[0]);
double bredth = Double.parseDouble(values[1]);
rectangleObj = new Rectangle(length, bredth);
myList.add(rectangleObj);
}
if (values.length == 3)
{
double sideA = Double.parseDouble(values[0]);
double sideB = Double.parseDouble(values[1]);
double sideC = Double.parseDouble(values[2]);
triangleObj = new Triangle(sideA, sideB, sideC);
myList.add(triangleObj);
}
}
}
// Create a "for" loop to store the "myList" data in the array list
for (Shape element : myList)
{
Shape s = element.copyShape();
arrayList.add(s);
}
br.close();
}
catch (IOException e)
{
e.printStackTrace();
System.out.println("File not found. Please check the input file in7.txt");
}
// Return the array list from the method.
return arrayList;
}}
Files to be submitted: . A class diagram - created either by Violet UML editor or ArgoUML or StarUML Java Source code o Shape o Rectangle, RectangleDriver, o Triangle, TriangleDriver, o Circle, CircleDriver, o InvalidTriangleException o Helper class, o and a driver Supporting file o A text file containing data that can be used to form shapes. Write a program to model a generic shape and a list of specific shapes such as a rectangle, a triangle, and a circle. Test each class with its own driver. Create a helper class with helper methods th classes. It is required to meet all the requirements that are included below. at the driver program will use for testing all Shape Triangle Rectangle CircleStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started