CIS 265 Homework 1 Due Feb 1, 2022 at 11:59pm Description This assignment is based on problem P-2.34 in the text, but many of the details have been modi- fied. You will write several classes that...

1 answer below »
java assignment about calculatipng area of trangle recangle etc


CIS 265 Homework 1 Due Feb 1, 2022 at 11:59pm Description This assignment is based on problem P-2.34 in the text, but many of the details have been modi- fied. You will write several classes that implement a given interface, as well as several specialized methods for each class. You may find some of the below methods to be easier to implement than others; I encourage you to work on them in any order you see fit and test as you go. The harder problems might become more clear after spending some time working on other parts. Requirements The interface ComputableShape is given below. It specifies methods to compute the area and perimeter of a shape. You will code the following classes, each of which implements ComputableShape in addition to its own particular requirements: • Triangle – The constructor should take the triangle’s three side lengths. – There should be a method isValid() that returns true if the three side lengths corre- spond to a valid triangle, and false otherwise. – There should be a method isIsoceles() that returns true if the triangle is isoceles, and false otherwise. – There should be a method isRight() that returns true if the triangle is a right triangle, and false otherwise. – The methods getArea() and getPerimeter() should first check if the triangle is valid. If it is, the methods compute the area or perimeter, respectively. However, for invalid triangles, the methods should return a negative value. • Rectangle – The constructor should take the rectangle’s height and width. – There should be methods getLargeSide() and getSmallSide() that return the length of the larger and smaller side, respectively. – There should be a method fitsInside(Rectangle) that returns true if this rectangle can be entirely contained within the other Rectangle, and false otherwise. • RegularPolygon – The constructor should take the number of sides of the polygon as well as the length of a side (because this class only represents regular polygons, all the sides will have the same length). – There should be a method getNumberOfSides() that returns the number of sides. – There should be a method getInteriorAngle() that returns, in degrees, the measure of the interior angle of this polygon. Note that you will still turn in ComputableShape.java despite the fact that you do not need to make any changes to it. Template Code ComputableShape.java: 1 public interface ComputableShape { 2 public double getArea (); 3 public double getPerimeter (); 4 } Triangle.java: 1 public class Triangle implements ComputableShape { 2 private double [] sideLengths; 3 4 public Triangle(double side1 , double side2 , double side3) { 5 // constructor code goes here 6 } 7 8 // implement the rest of your code here 9 } Rectangle.java: 1 public class Rectangle implements ComputableShape { 2 private double width , height; 3 4 public Rectangle(double width , double height) { 5 // constructor code goes here 6 } 7 8 // implement the rest of your code here 9 } RegularPolygon.java: 1 public class RegularPolygon implements ComputableShape { 2 private double sideLength; 3 private int numSides; 4 5 public RegularPolygon(double side , int n) { 6 // constructor code goes here 7 } 8 9 // implement the rest of your code here 10 } 2 of 4 Testing You can use the following code to test your program. Note that this may not exhaustively test all requirements; you are still responsible for making sure your code works as intended in all cases. 1 public class Test { 2 3 public static void main(String [] args) { 4 ComputableShape [] shapes = {new Triangle (3.0, 4.0, 5.0), 5 new Rectangle (2.0, 5.0), 6 new RegularPolygon (5.0, 8)}; 7 8 for (int i = 0; i < 3; i++) { 9 system.out.println("area of shape " + (i+1) + " is " + 10 shapes[i]. getarea ()); 11 system.out.println("perimeter of shape " + (i+1) + " is " + 12 shapes[i]. getperimeter ()); 13 } 14 15 triangle t = (triangle) shapes [0]; 16 system.out.println("\nthe triangle is" + 17 (t.isvalid () ? " " : " not ") + "valid."); 18 system.out.println("the triangle is" + 19 (t.isisoceles () ? " " : " not ") + "isoceles."); 20 system.out.println("the triangle is" + 21 (t.isright () ? " " : " not ") + "right."); 22 23 rectangle r = (rectangle) shapes [1]; 24 rectangle r2 = new rectangle (3,6); 25 rectangle r3 = new rectangle (3,4); 26 system.out.println("\nthe rectangle ’s large side has length " + 27 r.getlargeside ()); 28 system.out.println("the rectangle ’s small side has length " + 29 r.getsmallside ()); 30 system.out.println("the rectangle does" + 31 (r.fitsinside(r2) ? " " : " not ") + 32 "fit in the second rectangle."); 33 system.out.println("the rectangle does" + 34 (r.fitsinside(r3) ? " " : " not ") + 35 "fit in the third rectangle."); 36 37 regularpolygon p = (regularpolygon) shapes [2]; 38 system.out.println("\nthe polygon has " + 39 p.getnumberofsides () + " sides."); 40 system.out.println("the polygon ’s interior angles are " + 41 p.getinteriorangle () + " degrees each."); 42 } 43 } grading criteria your program must compile and run with my test program(s) to receive credit. the assignment is worth 100 points total, broken down as follows: • computableshape.java: 10 points • triangle.java: 40 points • rectangle.java: 25 points 3 of 4 • regularpolygon.java: 25 points example point deductions: • compiler warning: 3 points • minor error (any issue that does not impact core functionality): 5 points • extraneous code unrelated to assignment: 10 points • major error (e.g runtime exception, infinite loop): 15 points submission create a zip file with all of your code for the assignment and submit it on blackboard. be sure to include an appropriate header with your name, csu id, etc (see syllabus) in each file you submit. note that you do not need to submit a class with a main method; i will supply that myself for grading purposes. 4 of 4 3;="" i++)="" {="" 9="" system.out.println("area="" of="" shape="" "="" +="" (i+1)="" +="" "="" is="" "="" +="" 10="" shapes[i].="" getarea="" ());="" 11="" system.out.println("perimeter="" of="" shape="" "="" +="" (i+1)="" +="" "="" is="" "="" +="" 12="" shapes[i].="" getperimeter="" ());="" 13="" }="" 14="" 15="" triangle="" t="(Triangle)" shapes="" [0];="" 16="" system.out.println("\nthe="" triangle="" is"="" +="" 17="" (t.isvalid="" ()="" "="" "="" :="" "="" not="" ")="" +="" "valid.");="" 18="" system.out.println("the="" triangle="" is"="" +="" 19="" (t.isisoceles="" ()="" "="" "="" :="" "="" not="" ")="" +="" "isoceles.");="" 20="" system.out.println("the="" triangle="" is"="" +="" 21="" (t.isright="" ()="" "="" "="" :="" "="" not="" ")="" +="" "right.");="" 22="" 23="" rectangle="" r="(Rectangle)" shapes="" [1];="" 24="" rectangle="" r2="new" rectangle="" (3,6);="" 25="" rectangle="" r3="new" rectangle="" (3,4);="" 26="" system.out.println("\nthe="" rectangle="" ’s="" large="" side="" has="" length="" "="" +="" 27="" r.getlargeside="" ());="" 28="" system.out.println("the="" rectangle="" ’s="" small="" side="" has="" length="" "="" +="" 29="" r.getsmallside="" ());="" 30="" system.out.println("the="" rectangle="" does"="" +="" 31="" (r.fitsinside(r2)="" "="" "="" :="" "="" not="" ")="" +="" 32="" "fit="" in="" the="" second="" rectangle.");="" 33="" system.out.println("the="" rectangle="" does"="" +="" 34="" (r.fitsinside(r3)="" "="" "="" :="" "="" not="" ")="" +="" 35="" "fit="" in="" the="" third="" rectangle.");="" 36="" 37="" regularpolygon="" p="(RegularPolygon)" shapes="" [2];="" 38="" system.out.println("\nthe="" polygon="" has="" "="" +="" 39="" p.getnumberofsides="" ()="" +="" "="" sides.");="" 40="" system.out.println("the="" polygon="" ’s="" interior="" angles="" are="" "="" +="" 41="" p.getinteriorangle="" ()="" +="" "="" degrees="" each.");="" 42="" }="" 43="" }="" grading="" criteria="" your="" program="" must="" compile="" and="" run="" with="" my="" test="" program(s)="" to="" receive="" credit.="" the="" assignment="" is="" worth="" 100="" points="" total,="" broken="" down="" as="" follows:="" •="" computableshape.java:="" 10="" points="" •="" triangle.java:="" 40="" points="" •="" rectangle.java:="" 25="" points="" 3="" of="" 4="" •="" regularpolygon.java:="" 25="" points="" example="" point="" deductions:="" •="" compiler="" warning:="" 3="" points="" •="" minor="" error="" (any="" issue="" that="" does="" not="" impact="" core="" functionality):="" 5="" points="" •="" extraneous="" code="" unrelated="" to="" assignment:="" 10="" points="" •="" major="" error="" (e.g="" runtime="" exception,="" infinite="" loop):="" 15="" points="" submission="" create="" a="" zip="" file="" with="" all="" of="" your="" code="" for="" the="" assignment="" and="" submit="" it="" on="" blackboard.="" be="" sure="" to="" include="" an="" appropriate="" header="" with="" your="" name,="" csu="" id,="" etc="" (see="" syllabus)="" in="" each="" file="" you="" submit.="" note="" that="" you="" do="" not="" need="" to="" submit="" a="" class="" with="" a="" main="" method;="" i="" will="" supply="" that="" myself="" for="" grading="" purposes.="" 4="" of="">
Answered 1 days AfterJan 29, 2022

Answer To: CIS 265 Homework 1 Due Feb 1, 2022 at 11:59pm Description This assignment is based on problem P-2.34...

Arun Shankar answered on Jan 31 2022
121 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here