| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 405 人关注过本帖
标题:新手 帮忙看看错在哪里。
只看楼主 加入收藏
yl100124
Rank: 1
等 级:新手上路
帖 子:5
专家分:3
注 册:2012-12-25
结帖率:0
收藏
 问题点数:0 回复次数:1 
新手 帮忙看看错在哪里。
import java.util.*;
interface Shape{
    public double getArea();
    public double getVolume();
    public String getName();
}
class Point implements Shape{
    private int x;
    private int y;
    public Point(){
        x=0;
        y=0;
    }
    public Point(int x,int y){
        this.x=x;
        this.y=y;
    }
    public int getX(){
    return x;
    }
    public double getArea(){
    return 0.0;
    }
    public double getVolume(){
    return 0;
    }
    public String getName(){
    return "Point";
    }
}

class Circle{
    private double r;
    private Point center;
    public Circle(){
        center=new Point();
        r=0.0;
        }
    public Circle(int x,int y,double r){
        center=new Point(x,y);
        this.r=r;
}
    public void setRadius(double r){
        this.r = r;        
    }
   
    public double getRadius(){
        return r;
    }
   
    public double getArea(){
        return Math.PI*getRadius()*getRadius();
    }
   
    public double getCircumference(){
        return 2*Math.PI*getRadius();
    }
   
    public String getName(){
        return "Circle";
    }
   
    public String toString(){
        String s = center.toString();
        s+=",半径:"+r+",";
        return s;
    }
}

class Cylinder extends Circle{
    double h;
    public Cylinder(){
        super();
        h=0.0;
}
    public Cylinder(int x,int y,double r,double h){
        super(x,y,r);
        this.h = h;
    }
    public double getHeight(){
        return h;
    }
    public void setHeight(double h){
        this.h = h;
    }
   
    public double getArea(){
        return 2*Math.PI*getRadius()*getRadius() + 2*Math.PI*getRadius()*getHeight();
    }
   
    public double getVolume(){
        return Math.PI*getRadius()*getRadius()*getHeight();
    }
   
    public String getName(){
        return "Cylinder";
    }
   
    public String toString(){
        String s = super.toString();
        s+="高:"+getHeight()+",";
        return s;
    }
}

public class Sun22{
  public static void main(String args[]){
    Scanner input = new Scanner(System.in);
    int a,b;
    double c,d;
     while(true){
     System.out.println("输入圆柱体的底心坐标[x,y], 以及它的半径和高(坐标必须是正整数,其它必须为正数)");
     a=input.nextInt();
     b=input.nextInt();
     c=input.nextDouble();
     d=input.nextDouble();   
    Cylinder c2=new Cylinder(a,b,c,d);
    System.out.print(c2.toString());
    System.out.printf("体积:%.0f,表面积:%.0f",c2.getVolume(),c2.getArea());
    System.out.printf("\n输入911退出:");
    String s=input.next();
    if(("911")==0)
    break;
}
   System.out.println("Have a nice day!");
 }
}
搜索更多相关主题的帖子: public private interface double return 
2014-03-22 17:01
zjcl817
Rank: 4
来 自:残狼部落
等 级:业余侠客
威 望:2
帖 子:68
专家分:206
注 册:2013-11-11
收藏
得分:0 
去掉public class Sun22这行的    public就行了!
2014-03-30 16:48
快速回复:新手 帮忙看看错在哪里。
数据加载中...
 
   



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

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