java chapter 9 practice set

 package com.company;


class Cylinder{
private int radius;
private int height;

public Cylinder(int radius, int height) {
this.radius = radius;
this.height = height;
}

public int getRadius() {
return radius;
}

public void setRadius(int radius) {
this.radius = radius;
}//constructor

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}
public double surfaceArea(){
return 2* Math.PI* radius * radius + 2*Math.PI*radius*height;
}
public double volume(){
return Math.PI * radius * radius * height;
}


}

class Rectangle {
private int length;
private int breadth;

public Rectangle() {//problem 4
this.length = 4;
this.breadth = 5;
}

public Rectangle(int length, int breadth) {
this.length = length;
this.breadth = breadth;
}

public int getLength() {
return length;
}

public int getBreadth() {
return breadth;
}


/*
class Circle {
private int radius;

public void setRadius(int radius) {
this.radius = radius;
}

public int getRadius() {
return radius;
}

}



public double volume() {
int radius;
double d = 4.0 / 3.0;
System.out.println(d);
return d * Math.PI *radius*radius*radius;
}
*/


public static class cwh_chapter9_practice_set {


public static void main(String[] args) {

// Problem 1----------------
Cylinder myCylinder = new Cylinder(9, 12);
System.out.println(myCylinder.getHeight());
myCylinder.setHeight(12);
System.out.println(myCylinder.getRadius());
myCylinder.setRadius(9);


// Problem 2---------------------
System.out.println(myCylinder.surfaceArea());
System.out.println(myCylinder.volume());


// Problem 3,4
Rectangle r = new Rectangle(12, 56);
System.out.println(r.getLength());
System.out.println(r.getBreadth());


}
}
}


Comments

Popular posts from this blog

java chapter11 practice question on abstruct class and interfaces

java practice set 8

new stored procidure with interval and frequery code