# java

julia
java
1 Answer(s)      7 years ago
Posted in : UML
Every cylinder has a base and height, where the base is a circle. Design the class cylinder that can captures the properties of a cylinder and perform the usual operations on a cylinder. Derive this class from the class circle designed in programming exercise 4.some of the operations that can be performed on a cylinder are as follows: calculate and print the volume, surface area,set the height, set the radiusof the base, and set the center of the base.

April 30, 2010 at 1:08 PM

Hi Friend,

Try the following code:

class Circle{
private double r;
public Circle(){}
public Circle(double r){
this.r=r;
}
public void setR(double r){
this.r=r;
}
public double getR(){
return r;
}
}
public class Cylinder extends Circle{
private double r;
private double h;
public Cylinder(){}
public Cylinder( double r,double h){
super(r);
this.r=r;
this.h=h;
}
public void setH(double h){
this.h=h;
}
public double getH(){
return h;
}
public double volume(){
return Math.PI*r*r*h;
}
public double surfaceArea(){
double s=r+h;
return 2*Math.PI*r*s;
}
public static void main(String args[]){
Cylinder c = new Cylinder(3,5);
System.out.println(c.volume());
System.out.println(c.surfaceArea());
c.setR(5);
c.setH(10);
System.out.println(c.getR());
System.out.println(c.getH());
}
}

Thanks

Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  is java purely object oriented language
java
java  write a java program using filenotfoundexception
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  how use java method
java
java  what are JAVA applications development tools
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  why multiple inheritance is not possible in java