Question

In: Computer Science

In Euclidean geometry, a rhombus is a simple quadrilateral whose four sides all have the same...

In Euclidean geometry, a rhombus is a simple quadrilateral whose four sides all have the same length. If lengths of each of the sides are a and the distance between the parallel sides (known as height) is h, then the area of the rhombus is defined as a × h. Suppose that you already have a class named Rhombus that can hold a and h. The class has a method to compute the area as well. The class is as follows.

public class Rhombus {

private double a, h;

Rhombus nextRhombus;

Rhombus(){

h=1; a=h;

}

Rhombus(double aa, double hh){

a=aa; h=hh;

}

public double geta(){

return a;

}

public double geth(){

return h;

}

public double getArea(){

return a*h;

}

public boolean isSquare(){

return a==h;

}

}

Notice that Rhombus nextRhombus; in the Rhombus class can be used to construct a linked list.

(15 points) Now, you have another class named RhombusProcessor that has Rhombus objects in an array in the main method. Write a method named getSquares in the RhombusProcessor class to copy only the Rhombus objects that represent squares. The getSquares method must return these square shaped Rhombus objects using a linked list in the same oder they appear in the original list. Notice that you will only return the head of the linked list. The program is partially written; you just need to write the getSquares method in the space provided within the RhombusProcessor class. The expected header is public static Rhombus getSquares(Rhombus[] r).

public class RhombusProcessor {

public static Rhombus getSquares(Rhombus[] r){

Solutions

Expert Solution

Rhombus.java

public class Rhombus {

private double a, h;

Rhombus nextRhombus;

Rhombus(){

h=1; a=h;

}

Rhombus(double aa, double hh){

a=aa; h=hh;

}

public void setNextRhombus(Rhombus nextRhombus) {

this.nextRhombus = nextRhombus;

}

public double geta(){

return a;

}

public double geth(){

return h;

}

public double getArea(){

return a*h;

}

public boolean isSquare(){

return a==h;

}

}

Driver class

public class CdDriver {

public static void main(String a[]){

Rhombus rh=new Rhombus(5.3, 4.1);

System.out.println("Area of rhombus: "+rh.getArea());

System.out.println("Is it a square? "+rh.isSquare());

System.out.println("------------------------------------");

Rhombus rh1=new Rhombus(5.3, 5.3);

System.out.println("Area of rhombus: "+rh1.getArea());

System.out.println("Is it a square? "+rh1.isSquare());

//create linked list by attaching rh1 with rh

rh.setNextRhombus(rh1);

}

}


Related Solutions

All of the sides of a quadrilateral are congruent if it is a rhombus.
The following conditional statement is true.All of the sides of a quadrilateral are congruent if it is a rhombus.Which of the following statements must also be true?a) If not all of the sides of a quadrilateral are congruent, then it is not a rhombus.b) If a quadrilateral is not a rhombus, then all of its sides are not congruent.c) If a quadrilateral is a rhombus, then not all of its sides are congruent.d) If all of the sides of a...
Consider a rhombus that is not square (i.e., the four sides all have the same length, but the angles between sides is not 90°).
Consider a rhombus that is not square (i.e., the four sides all have the same length, but the angles between sides is not 90°). Describe all the symmetries of the rhombus. Write down the Cayley table for the group of symmetries,
Prove that the quadrilateral enclosed by the perpendicular bisectors of the sides of a rhombus is...
Prove that the quadrilateral enclosed by the perpendicular bisectors of the sides of a rhombus is a rhombus.
PYTHON: A rhombus is a parallelogram with four equal sides. It resembles the diamonds suit in...
PYTHON: A rhombus is a parallelogram with four equal sides. It resembles the diamonds suit in playing cards. Here are the properties of a rhombus: - opposite sides are parallel - all four sides have the same length - opposite angles are equal - sum of any 2 adjacent angles is 180 degrees (x + y = 180 degrees) Write a function called rhombus that uses turtle graphics to draw a rhombus. The function rhombus takes three parameters: 1. t,...
Four charges of magnitude +q are placed at the corners of a square whose sides have...
Four charges of magnitude +q are placed at the corners of a square whose sides have a length d. What is the magnitude of the total force exerted by the four charges on a charge Q located a distance b along a line perpendicular to the plane of the square and equidistant from the four charges? Ans: bqQ/πε 0 (b2 + d2 / 2) how to get this answer?
Consider four nonstandard dice, whose sides are labeled as follows (the 6 sides on each die...
Consider four nonstandard dice, whose sides are labeled as follows (the 6 sides on each die are equally likely). A: 4, 4, 4, 4, 0, 0 B: 3, 3, 3, 3, 3, 3 C: 6, 6, 2, 2, 2, 2 D: 5, 5, 5, 1, 1, 1 These four dice are each rolled once. Let A be the result for die A, B be the result for die B, etc. (a) Find P(A > B), P(B > C), P(C >D),...
Prove the following for Euclidean Geometry. Provide general dynamic illustrations in GeoGebra. You will have to...
Prove the following for Euclidean Geometry. Provide general dynamic illustrations in GeoGebra. You will have to break down your illustrations and your proofs into 3 cases. Case 1: Both sides of the angle are tangent to the circle. Case 2: Exactly one side of the angle is tangent to the circle. Case 3: Neither side of the angle is tangent to the circle. Proposition 129. If an angle intercepts two arcs of a circle, then the measure of the angle...
In our simple models, the multipliers are the same for all spending and the same for...
In our simple models, the multipliers are the same for all spending and the same for all taxes. How do real world multipliers differ? How did they impact fiscal policy in the Obama American Recovery and Reinvestment Act of 2008? What does that tell us about fiscal policy in 2020?
1 Why does FedEx palletize their freight shipments? a. To provide access to all four sides...
1 Why does FedEx palletize their freight shipments? a. To provide access to all four sides b. Pallets are available and economical c. Freight customers own the equipment needed to handle pallets d. To comply with regulations e. Airlines require pallets f. Freight customers prefer palletization 2 Which statement best describes FedEx's Custom Critical service? a. These shipments must travel by air b. FedEx treats all shipments as critical c. Customers must pre-register to use this service d. The shipment...
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it...
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it follows that an isosceles triangle has three sides. Argument a is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument B There is a large crack in Philadelphia's Liberty Bell. From this, we can conclude that there was a defect in the bell's craftsmanship. Argument B is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument C Paleontologists now agree that the Tyrannosaurus Rex was actually a peaceful, plant-eating dinosaur. Therefore, it is probably...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT