| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 642 人关注过本帖
标题:实在是不会做了,求助各位,谢谢了
只看楼主 加入收藏
bizika526
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2007-10-20
收藏
 问题点数:0 回复次数:1 
实在是不会做了,求助各位,谢谢了
设计一个点类,他仅包含两个属性:横坐标和纵坐标.通过继承点类再设计一个圆类,他除了有一个圆心还有半径,还应该能计算周长和面积等,编写一个程序来测试所设计的类能否实现预定功能.
class Point{
private double h;//横坐标
private double z;//纵坐标
public Point(double h,double z){
this.h=h;
this.z=z;
}
public Point{
}
public double geth(){
return this.h;
}
public doubel seth(double h){
this.h=h;
}
public double getz(){
return this.z;
}
public double setz(double z){
this.z=z;
}

}
class Circle extends Point{
private double hc;//圆心的横坐标
private double zc;//圆心的纵坐标
private double radius;
private double perimeter;
private double area;
private double pi=3.14;
private double D;
public Circle(double hc,double zc){
this.hc=hc;
this.zc=zc;
}
public double sethc(double hc){
this.hc=hc;
}
public double gethc(){
return this.hc;
}
public double setzc(double zc){
this.zc=zc;
}
public double gethc(){
return this.zc;
}
D=((geth()-gethc())*(geth()-gethc()))+((getz()-getzc())*(getz()-getzc()));
public static void main(String[] args){
Point p=new Point(3,4);
Circle c=new Circle(0,0);
System.out.println("圆的面积为:"+(pi*D));

}
}
请帮忙修改
搜索更多相关主题的帖子: 设计 private public double 
2007-11-28 22:45
无缘今生
Rank: 2
等 级:新手上路
威 望:3
帖 子:523
专家分:7
注 册:2007-6-25
收藏
得分:0 
修改后的程序:
class Point{
private double h;//横坐标
private double z;//纵坐标
public Point(double h,double z){
this.h=h;
this.z=z;
}

public Point(){
}

public double geth(){
return this.h;
}
public void seth(double h){
this.h=h;
}
public double getz(){
return this.z;
}
public void setz(double z){
this.z=z;
}

}


class Circle extends Point{
private double hc;//圆心的横坐标
private double zc;//圆心的纵坐标
private double radius;
private double perimeter;
private double area;
static private double pi=3.14;
private double D;

public Circle(double hc,double zc){
this.hc=hc;
this.zc=zc;
}

public void sethc(double hc){
this.hc=hc;
}

public double gethc(){
return this.hc;
}

public void setzc(double zc){
this.zc=zc;
}

public double getzc(){
return this.zc;
}

public double getD(){
D=((geth()-gethc())*(geth()-gethc()))+((getz()-getzc())*(getz()-getzc()));
return D;
}

public static void main(String[] args){
Point p=new Point(3,4);
Circle c=new Circle(0,0);
System.out.println("圆的面积为:"+(pi*c.getD()));

}
}
顺便说一下:其中有好些低级错误。

时不再来!!!
2007-11-29 18:06
快速回复:实在是不会做了,求助各位,谢谢了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023642 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved