I need help to complete my assignment on Object Oriented Design and Programming.

I've done it halfway and i need to complete it for the final class.

I've attached my work and the questions.

please help  

Get Help With a similar task to - I need help to complete my assignment on Object Oriented Design and Programming.

Login to view and/or buy answers.. or post an answer
Additional Instructions:

1 SCIT School of Computing and Information Technology Faculty of Engineering & Information Sciences CSIT121 Object Oriented Design and Programming Assignment 2 File name: YourName _A2.java Objectives: Practice java programming with inheritance and polymorphism. Task (6 marks) 2 Implement the Shape hierarchy as shown in the above diagram - Basically each two dimensional shape has an area method computes and returns the area of the two-dimensional shape. - Each three dimensional shape other than the area (also known as surface area) method we also have a volume method; computes and returns, respectively, the surface area and the volume of the three-dimensional shape. - Try to surf the internet to look for some formulas, for example, to compute the areas, the surface areas and the volumes … I did that too  A more detailed UML diagram is shown as follow: (Note that the #’s before the instance variables and the methods’ names mean “protected”) 3 Wow … so difficult to see; no worry, I will break it down bit by bit and explain what you have to do … Let us explore the above UML diagram at the highest hierarchy; you can see that Shape is an interface class. Two abstract classes TwoD and ThreeD implement the Shape interface; TwoD also implements Recolorable interface and ThreeD also implements Resizable interface and we also have an enumeration data type to describe some of the colors: 4 Four possible shapes for TwoD: one value, for example the radius, is a circle shape; two values, for example the length and the width, is a rectangle; three values for example the three sides of a triangle (provided it can be formed), five values for trapezoid (one additional value was the height, as we need that to compute the area). In this class, you can see that we have four constructors to describe the four shapes, a copy constructor, some accessor and mutator methods and a toString method. Each 2D shape also has a color and the color can be changed (recolor method) during runtime. You can see we also define an enumeration type to specify the color of the shapes. The following UML diagram shows the four concrete subclasses of TwoD: 5 Some methods just override the super class methods (same implementations) Information defined in each of the subclasses should be obvious in definitions. Now, let us look at the ThreeD class: Three possible shapes for ThreeD: Just one value can determine the shapes of a sphere, a cube and or a tetrahedron. In this class, we only also have constructors, copy constructor, accessor methods, mutator methods and a toString method. For a 3D object, we can compute and return the volume too. Therefore we have one abstract method in this abstract class ThreeD. ThreeD class also implements Resizable interface class. In this Resizable interface, other than the method resize, to reduce the size by certain percentage. Let us now look at the UML diagram for the three subclasses of ThreeD class: 6 Look for the surface area and volume formulas somewhere in internet to compute and to return their values, also don’t forget the two private methods I have just mentioned  Note that all 3D objects need to resize by a certain percentage. Let us now explore the main class, i.e. main method is defined in this class All shapes (2D or 3D) should be randomly generated and store them in an ArrayList of Shape’s. You can see a few private class methods are defined in this class: - a method generates and returns a positive integer, not too large - a method generates and returns a positive real number, not too large - a method generates and returns a color. - a method generates and returns a TwoD shape - a method generates and returns a ThreeD shape - a method to display the objects stored in the ArrayList. Note that in the display method, you display the details of each shape object, i.e. the toString method for each of the classes only display a “brief” object info, display of area / volume / resizable/ recolor should be done in this method. Convenient to your design, minor updates to methods or additional methods are allowed. 7 In the main method, you repeatedly generate an integer k (0 or 1 or 2). If k is 1 you construct a 2D object; if k is 2, you construct a 3D object and k is 0, you end the task. The following shows one of the possible displays: Three objects were generated and stored in an array list and you displayed the list. You can see Shape 2 and Shape 3 were 2D objects, their colors are changed during runtime (you must make sure that the color is really changed to a different color); Shape 1, a cube, its sizes, area, volume were reduced by 24.2 % (this percentage was randomly generated). Note that the list may be empty … IMPORTANT Put all your classes in a file called YourName_A2.java and make sure that this file can be compiled and can be executed. Upload ONLY this file to Moodle. ALL ZIP FILE SUBMISSION WILL BE REJECTED. No re-submission will be allowed after grading. 8 In the above file, remember to put down your name and also the following declaration (some similar contents): // Tell me if it is your own work, and whether you // have passed your program to your friends etc etc etc // and willing to accept whatever penalty given to you. - Wrong file name -0.5 mark - No declaration, no name etc -0.5 mark - Failing to demo -1 mark - Programs indentations and alignment of statements -0.5 mark - Late penalty: -0.1 mark per hour.

import java.util.ArrayList; import java.util.Random; enum ShapeColor {Blue,Yellow,Red,Green,White} interface Shape { double area(); } interface Recolorable { public void recolor(ShapeColor sc); } interface Resizable { public void resize(double percentage); } abstract class TwoD implements Shape { protected ShapeColor sc; protected int a; protected int b; protected int c; protected int d; public TwoD() { } public TwoD(ShapeColor sc,int a) { this.sc=sc; this.a=a; } public TwoD(ShapeColor sc,int a,int b) { this.sc=sc; this.a=a; this.b=b; } public TwoD(ShapeColor sc, int a, int b, int c) { this.sc=sc; this.a=a; this.b=b; this.c=c; } public TwoD(ShapeColor sc, int a, int b, int c, int d) { this.sc=sc; this.a=a; this.b=b; this.c=c; this.d=d; } public TwoD(TwoD td) { this (td.getShapeColor(),td.getA(),td.getB(),td.getC(),td.getD()); } public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } public int getD() { return d; } public ShapeColor getShapeColor() { return sc; } public void set(ShapeColor sc, int a, int b, int c, int d) { this.sc=sc; this.a=a; this.b=b; this.c=c; this.d=d; } public void recolor(ShapeColor sc) { this.sc=sc; } @Override public String toString() { return String.format(" "); } } class Circle extends TwoD { public Circle() { super(); } public Circle(ShapeColor sc, int radius) { super (sc,radius); } public Circle(Circle c) { super(c); } @Override public double area() { return Math.PI*getRadius()*getRadius(); } public int getRadius() { return a; } public void set (ShapeColor sc, int radius) { super.set(sc, radius,0,0,0); } @Override public String toString() { return String.format ("Circle (2D(%s,%d))",super.getShapeColor(),getA()); } } class Rectangle extends TwoD { public Rectangle() { } public Rectangle(ShapeColor sc,int length,int width) { super (sc, length, width); } public Rectangle(Rectangle r) { super (r); } @Override public double area() { return getLength()*getWidth(); } public int getLength() { return a; } public int getWidth() { return b; } public void set(ShapeColor sc, int length,int width) { super.set(sc,length,width,0,0); } @Override public String toString() { return String.format ("Rectangle (2D(%s,%d,%d))",super.getShapeColor(),getLength(),getWidth()); } } class Triangle extends TwoD { public Triangle() { } public Triangle(ShapeColor sc, int a, int b, int c) { super (sc,a,b,c); } public Triangle (Triangle t) { super (t); } @Override public double area() { double s = (a+b+c)/2; return Math.sqrt(s* (s-a)*(s-b)*(s-c)); } public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } public void set(ShapeColor sc,int a, int b, int c) { super.set(sc,a,b,c,0); } public String toString() { return String.format ("Triangle (2D(%s,%d,%d,%d))",super.getShapeColor(),getA(),getB(),getC()); } } class Trapezoid extends TwoD { private int h; public Trapezoid() { } public Trapezoid(ShapeColor sc, int a, int b, int c, int d, int h) { super (sc,a,b,c,d); this.h=h; } public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } public int getD() { return d; } public int getHeight() { return h; } @Override public double area() { double t = (a*h); double sq = b*h; double area = t+sq; return area; } public void set(ShapeColor sc, int a, int b, int c, int d) { super.set(sc,a,b,c,d); } @Override public String toString() { return String.format ("Triangle (2D(%s,%d,%d,%d))",super.getShapeColor(),getA(),getB(),getC()); } } abstract class ThreeD implements Shape,Resizable { protected ShapeColor sc; protected double a; public ThreeD() { } public ThreeD(ShapeColor sc, double a) { this.sc=sc; this.a=a; } public ThreeD(ThreeD td) { this(td.sc,td.getA()); } public double getA() { return a; } public void set (ShapeColor sc,double a) { this.sc=sc; this.a=a; } public void resize(double percentage) { this.a=a; } public double volume() { return Math.PI*a*a*a; } public String toString() { return String.format(" "); } } class Sphere extends ThreeD { public Sphere() { } public Sphere (ShapeColor sc, int a) { super (sc,a); } public Sphere(Sphere s) { super (s); } public double area() { return 4*Math.PI*a*a; } public double volume() { return Math.PI*a*a*a*(4/3); } public double getA() { return a; } public void set(ShapeColor sc, double a) { super.set(sc, a); } public String toString() { return String.format("Sphere (3D (%s, %.3f))%nSurface area = %.3f%nVolume = %.3f", super.sc,getA(),area(),volume()); } } class Cube extends ThreeD { public Cube() { } public Cube (ShapeColor sc,int a) { super (sc,a); } public Cube(Cube c) { super (c); } public double area() { return 6*(a*a); } public double volume() { return a*a*a; } public double getA() { return a; } public void set(ShapeColor sc, double a) { super.set(sc, a); } public String toString() { return String.format("Cube (3D (%s, %.3f))%nSurface area = %.3f%nVolume = %.3f", super.sc,getA(),area(),volume()); } } class Tetrahedron extends ThreeD { public Tetrahedron() { } public Tetrahedron (ShapeColor sc,double a) { super (sc,a); } public Tetrahedron(Tetrahedron t) { super (t); } public double area() { return Math.sqrt(3)*(a*a); } public double volume() { return (a*a*a)/6*Math.sqrt(2); } public double getA() { return a; } public void set(ShapeColor sc, double a) { super.set(sc, a); } public String toString() { return String.format("Tetrahedron (3D (%s, %.3f))%nSurface area = %.3f%nVolume = %.3f", super.sc,getA(),area(),volume()); } } class A2_S2_2020 { public static Random rand = new Random(); public static ArrayList<Shape>alist = new ArrayList<>(); private static int getInt() { int number = rand.nextInt((10)+1); return number; } private static double getDouble() { double number = rand.nextInt((10)+1); return number; } private static ShapeColor getColor() { int x = rand.nextInt(ShapeColor.values().length); return ShapeColor.values()[x]; } private static boolean isTriangle(int a,int b, int c) { if(a + b > c && b + c > a && a + c > b) { return true; } else { return false; } } private static TwoD getTwoD() { } }

Related Questions

Similar orders to I need help to complete my assignment on Object Oriented Design and Programming.
17
Views
0
Answers
Nested imbalanced design of expriment using Box-Adjusted wald-type test
I need to provide statistical analysis of a nested design non-balanced design of experiment. I am hoping to have the implementation in either R, SPSS, or both. I will need the answers to be provided as shown in the attached file (Project.docx), and also wo...
32
Views
0
Answers
CMPT 200 Coding Homework
Write a class called Fraction that can store a rational number (reminder: those numbers that can be expressed in the form a/b, where a and b are integers are rational numbers). For example, a variable with a value of ½ would be created using oneHalf ...
15
Views
0
Answers
Artificial Inteligence System Technique
This is a Master Degree course and I have attached example questions, there are 5 questions and only 3 need to be answered. We will get the actual questions on the day of the exam and they need to be completed within 2 hours, which means the expert has to ...
18
Views
0
Answers
Simulating Networks
Here are the details of first assignment for Computer Networks class. This is a pretty basic assignment with very little work but you will have to do initial setup for virtual box on your machine. Here are the details on how to do the setup: Download virt...