Godking_6
2021-11-19 14:43
采纳率: 85.7%
浏览 37
已结题

JAVA,面向对象的类的问题

img

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • ヾ凉秋 2021-11-19 14:54
    最佳回答
    public class Test {
        public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            Rectangle haha = new Rectangle();
            haha.setWeight(in.nextDouble());
            haha.setHeight(in.nextDouble());
            haha.getArea();
            haha.getPperimeter();
        }
    }
    
    
    
    public class Rectangle {
        double weight=1;
        double height=1;
        public double getWeight() {
            return weight;
        }
        public void setWeight(double weight) {
            this.weight = weight;
        }
        public double getHeight() {
            return height;
        }
         public void setHeight(double height) {
            this.height = height;
        }
        public void getArea(){
            System.out.println(getHeight()*getWeight());
        }
        public void getPperimeter(){
            System.out.println((getHeight()+getWeight())*2);
        }
    }
    
    
    
    评论
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题