
class Point{
private int x, y;
//get / set
public Point(){
}
public Point(int x, int y){
thisx=x; thisy=y;
}
}
继承就是再extends Point、并添加相应的方法、属性
第3题,按照题目要求编写的Java程序如下
public class VolumeTest{
int volume(int a){
return aaa;
}
int volume(int a,int b,int c){
return abc;
}
double volume(double r,double h){
return MathPIrrh;
}
public static void main(String[] args){
VolumeTest vt=new VolumeTest();
Systemoutprintln("立方体体积为"+vtvolume(3));
Systemoutprintln("长方体体积为"+vtvolume(3,4,5));
Systemoutprintln("圆柱体体积为"+vtvolume(32,52));
}
}
package Area;
// 圆
public class circle {
// 半径
private double r;
public double getR() {
return r;
}
public void setR(double r) {
thisr = r;
}
// 面积计算
public double getArea(double r){
thisr=r;
return rr314;
}
}
package Area;
// 圆柱体
public class circularCylinder extends circle{
// 高度
private double h;
public double getH() {
return h;
}
public void setH(double h) {
thish = h;
}
// 体积
public void getValumn(double r,double h){
thish=h;
Systemoutprintln(thisgetArea(r)h);
}
}
package Area;
import javautilScanner;
// 主程序
public class testArea {
private static Scanner scanner = new Scanner(Systemin);
public static void main(String[] args) {
circle c = new circle();
circularCylinder cc = new circularCylinder();
Systemoutprintln("请输入圆的半径:");
// 手动设置圆半径
csetR(scannernextDouble());
Systemoutprintln("请输入圆柱体高度:");
// 设置圆柱体的高
ccsetH(scannernextDouble());
Systemoutprint("圆面积为:"+cgetArea(cgetR()));
Systemoutprint("相应的圆柱体体积为:");
ccgetValumn(cgetR(),ccgetH());
}
}
import javautilScanner;
public class TestCount {
//计算体积的方法 其中h代表高,r代表半径,m代表体积
public void tiji(double h,double r){
double m = r r MathPI h;
Systemoutprintln("体积="+m);
}
//计算表面积的方法
public void biaomiji(double h,double r){
double n = r r MathPI + 2 r h MathPI;
Systemoutprintln("表面积="+n);
}
public static void main(String[] args) {
TestCount test = new TestCount();
Systemoutprint("请输入物体半径:");
Scanner Scanner = new Scanner(Systemin);
double r=ScannernextDouble();
Systemoutprint("请输入物体高度:");
Scanner Scanner1 = new Scanner(Systemin);
double h=Scanner1nextDouble();
testtiji(h, r);//调用计算体积的方法
testbiaomiji(h, r);//调用计算表面积的方法
}
}
运行结果:
请输入物体半径:100
请输入物体高度:50
体积=15707963267948967
表面积=6283185307179587
完整的程序。望采纳。
//Cylinder类
public class Cylinder {
private static final double PI = 31415926;
private double height; //圆柱体的高
private double radius; //底面半径
public double getHeight() {
return height;
}
public void setHeight(double height) {
thisheight = height;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
thisradius = radius;
}
public Cylinder() {}
public Cylinder(double height, double radius) {
thisheight = height;
thisradius = radius;
}
public double getSideArea(){
return 2PIradiusheight;
}
public double getFullArea(){
return (getSideArea()+PIradiusradius2);
}
public double getVolume(){
return PIradiusradiusheight;
}
}
//TestCylinder类
public class TestCylinder {
public static void main(String[] args) {
Cylinder cylinder = new Cylinder(55, 35);
Systemoutprintln("圆柱体侧面积: "+cylindergetSideArea());
Systemoutprintln("圆柱体表面积: "+cylindergetFullArea());
Systemoutprintln("圆柱体体积: "+cylindergetVolume());
}
}
以上就是关于java.继承和派生:编写一个程序计算出圆的面积、圆柱体的表面积和体积。全部的内容,包括:java.继承和派生:编写一个程序计算出圆的面积、圆柱体的表面积和体积。、编写java程序、java编程求圆形和圆柱体的面积和体积等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)