Question
I need these specifications add to this java code import java.util.Scanner; abstract class Shape { abstract double getPerimeter(); abstract String getDimensions(); } class Rectangle extends
I need these specifications add to this java code
import java.util.Scanner;
abstract class Shape { abstract double getPerimeter();
abstract String getDimensions(); }
class Rectangle extends Shape { double rectangleHeight; double rectangleWidth;
public Rectangle(double rectangleHeight, double rectangleWidth) { this.rectangleHeight = rectangleHeight; this.rectangleWidth = rectangleWidth; }
@Override double getPerimeter() { return 2 * (rectangleHeight + rectangleWidth); }
@Override String getDimensions() { return rectangleHeight + " x " + rectangleWidth; } }
class Triangle extends Shape { double side1; double side2; double side3; public Triangle(double side1, double side2, double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; } @Override double getPerimeter() { return side1 + side2 + side3; } @Override String getDimensions() { return "perimeter " + (side1 + side2 + side3); } }
class Square extends Shape { double squareHeight;
public Square(double squareHeight) { this.squareHeight = squareHeight; }
@Override double getPerimeter() { return 4 * squareHeight; }
@Override String getDimensions() { return "height " + squareHeight; } }
class Circle extends Shape { double diameter;
public Circle(double diameter) { this.diameter = diameter; }
@Override double getPerimeter() { return Math.PI * diameter; }
@Override String getDimensions() { return "diameter " + diameter; } }
class Line extends Shape { double length; public Line(double length) { this.length = length; } @Override double getPerimeter() { return length; } @Override String getDimensions() { return "line length, " + length; } }
public class NeonTubingCalculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Welcome to Nick's Neon Tubing Calculator");
double totalLength = 0; double rectangleLength = 0; double squareLength = 0; double circleLength = 0; double triangleLength = 0; double lineLength = 0;
while (true) { System.out.print(" Enter the shape type (R, S, C, T, L, Q): "); String shapeType = scanner.nextLine();
if (shapeType.equalsIgnoreCase("Q")) { break; }
Shape shape; String dimensions;
switch (shapeType.toUpperCase()) { case "R": System.out.print("Enter Height and Width of Rectangle: "); double rectangleHeight = scanner.nextDouble(); double rectangleWidth = scanner.nextDouble(); scanner.nextLine(); // consume the newline character
shape = new Rectangle(rectangleHeight, rectangleWidth); dimensions = "rectangle, " + shape.getDimensions(); rectangleLength += shape.getPerimeter(); break;
case "S": System.out.println("Enter Height of Square: "); double squareHeight = scanner.nextDouble(); scanner.nextLine();
shape = new Square(squareHeight); dimensions = "square, " + shape.getDimensions(); squareLength += shape.getPerimeter(); break;
case "C": System.out.print("Enter Diameter of Circle: "); double diameter = scanner.nextDouble(); scanner.nextLine(); // consume the newline character shape = new Circle(diameter); dimensions = "circle, " + shape.getDimensions(); circleLength += shape.getPerimeter(); break; case "T": System.out.println("Enter Three side lengths: "); double side1 = scanner.nextDouble(); double side2 = scanner.nextDouble(); double side3 = scanner.nextDouble(); scanner.nextLine(); shape = new Triangle(side1, side2, side3); dimensions = "triangle, " + shape.getDimensions(); triangleLength += shape.getPerimeter(); break; case "L": System.out.println("Enter the Length of the Line: "); double length = scanner.nextDouble(); scanner.nextLine(); shape = new Line(length); dimensions = "line, " + shape.getDimensions(); lineLength += shape.getPerimeter(); break; default: System.out.println("Invalid shape type"); continue; }
double fullPerimeter = Math.round(rectangleLength) + Math.round(squareLength) + Math.round(circleLength) + Math.round(triangleLength) + Math.round(lineLength); totalLength += fullPerimeter;
System.out.printf("The perimeter of a %s is %.1f ", dimensions, shape.getPerimeter()); }
System.out.println(" Shapes Needed ");
// print out the list of shapes and perimeters System.out.printf(rectangleLength + "- rectangle, "); System.out.printf(circleLength + " - circle, diameter "); System.out.printf(squareLength + " - square, "); System.out.printf(triangleLength + " - triangle, "); System.out.printf(lineLength + " - line, ");
System.out.println("---------------------------"); System.out.printf("Total Length: %.1f ", totalLength);
System.out.println("Thank You"); } }
Version 2.0 needs to meet all of the design specifications for v1.0 PLUS: - Units - all measurements are in cm and calculations/output should be to the mm (ie 1 decimal place) - Triangles - enter the lengths of the 3 sides - BRACKETS - for each object, determine the number of brackets necessary to support it: - 1 bracket per vertex or endpoint (for a line) - so a square needs at least 4. - No more than 20cm of material without a bracket. A 20cm square needs 4 , but a 25cm square needs 8 since each side needs an additional bracket. - A circle needs at least 2 support brackets - Count the number of items of each type (e.g. 3 rectangles, 1 square). During the Design \& Coding Phases: Apply Object Oriented design principles following the guidelines discussed in class. Use inheritance to create a hierarchy of shapes. At least one abstract class is required with methods get TubeLength() and getNumBrackets() ArrayList (or similar) is required Use instanceOf() in an appropriate fashion. (counting the shape types?) Make sure to separate the user interface (including all 1/0 ) from the shape classesStep 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