Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Every cylinder has a base and height, where the base is a circle. Design the class Cylinder that can capture the properties of a cylinder and perform the usual operations on a cylinder. Derive this class from the class Circle (done through Problem 3.2). Please do the following:

  1. Some of the operations that can be performed on a cylinder are as follows: calculate and print the volume, calculate and print the surface area, set the height, set the radius of the base, and set the center of the base.
  2. Write a test program to test your program.

Note: Java programming. Please also send the test program so I can run it in dr java and learn. Use given code and design the class cylinder that can capture the properties of a cylinder and perform the usual operations on a cylinder.

Point code:

// class Point

public class Point
{
protected double x, y; // coordinates of the Point

//Default constructor
public Point()
{
setPoint( 0, 0 );
}

//Constructor with parameters
public Point(double xValue, double yValue )
{
setPoint(xValue, yValue );
}

// set x and y coordinates of Point
public void setPoint(double xValue, double yValue )
{
x = xValue;
y = yValue;
}

// get x coordinate
public double getX()
{
return x;
}

// get y coordinate
public double getY()
{
return y;
}

// convert point into String representation
public String toString()
{
return "[" + String.format("%.2f", x)
+ ", " + String.format("%.2f", y) + "]";
}

//Method to compare two points
public boolean equals(Point otherPoint)
{
return(x == otherPoint.x &&
y == otherPoint.y);
}

//Method to compare two points
public void makeCopy(Point otherPoint)
{
x = otherPoint.x;
y = otherPoint.y;
}

public Point getCopy()
{
Point temp = new Point();

temp.x = x;
temp.y = y;

return temp;
}

// print method
public void printPoint()
{
System.out.print("[" + String.format("%.2f", x)
+ ", " + String.format("%.2f", y) + "]");
}

} // end class Point

 

Circle code:

public class Circle
{
    //declaring data members 
    protected double radius;
    protected Point center;
    
    //constructor
    public Circle()
    {
        radius=0;
        center=new Point();
    }
    
    //parameterized constructor
    public Circle(Point p, double radius)
    {
        center=p;
        this.radius=radius;
    }
    
    //getters and setters for radius 
    public double getRadius()
    {
        return radius;
    }
    
    public void setRadius(double radius)
    {
        this.radius=radius;
    }
    
    //getters and setters for center
    public void setCenter(Point p)
    {
        center=p;
    }
    
    public Point getPoint()
    {
        return center;
    }
    
    //finding area 
    public double getArea()
    {
        return 3.14*radius*radius;
    }
    
    //finding circumference
    public double getCircumference()
    {
        return 2*3.14*radius;
    }
}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY