can i get a hand writing this? the code MUST use the information given in the gr
ID: 3720976 • Letter: C
Question
can i get a hand writing this? the code MUST use the information given in the graph on the 1st page.
(i already have 1 completed i just need 2a and 2b)
thanks!
1. (09 pts) Complete the definition of the method below. The method conducts a search for a given Rectangle object in a given array of Rectangles, counts the number of occurrences of the target and returns count. We assume that the Rectangle class has an equals() method. // The method ta // Rectangle for parameters, each entry of the array is compared to 77 the target, the matches are counted and the count is returned kes an array of Rectangle objects and a target public int search (Rectanglel 1 boxes, Rectangle target) int counter //iterate through the parameter array for (int k=0; kExplanation / Answer
//2)Convert UML to class diagram,Cylinder class
//Cylinder.java
public class Cylinder
{
//declare variables
private double radius;
private double height;
//default constructor
public Cylinder()
{
radius=0;
height=0;
}
//parameter constructor
public Cylinder(double r,double h) {
radius=r;
height=h;
}
/*Set radius*/
public void setRadius(double r){
radius=r;
}
/*Set height*/
public void setHeight(double h){
height=h;
}
/*Get radius*/
public double getRadius(){
return radius;
}
/*Get height*/
public double getHeight(){
return height;
}
/*Calculates base area*/
public double baseArea(){
return Math.PI*radius*radius;
}
/*Calculate volume of cylinder and return volume*/
public double computeVolume(){
return baseArea()*height;
}
/*Override toString method*/
public String toString() {
return String.format("Cylinder has radius %3.2f and height %3.2f", radius,height);
}
}//end of the class , Cylinder
----------------------------------------------------------------------------
//2.b
//Test program for Cylinder class
//Test.java
public class Test {
public static void main(String[] args) {
//declare cylinder c1
Cylinder c1=null;
//instantiate c1 with 15.0 and 33.45 for radius and height
c1=new Cylinder(15.0, 33.45);
//display the state of c1 by using the toString method
System.out.println(c1.toString());
//change height of cylinder 222.5
c1.setHeight(222.5);
//calling computeVolume method
System.out.println("Volume is "+c1.computeVolume());
//Create an instance of Cylinder ,c2
//Assign the c1 to object,c2
Cylinder c2=c1;
//call equals method on c2 and c1
if(c2.equals(c1))
System.out.println("SAME");
else
System.out.println("DIFFERENT");
} //end of main method
}//end of the class, Test
----------------------------------------------------------------------------
Sample Output:
Cylinder has radius 15.00 and height 33.45
Volume is 157275.982220339
SAME
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.