首页 > 其他 > 详细

第四周课程总结&实验报告二

时间:2019-09-19 19:27:22      阅读:75      评论:0      收藏:0      [点我收藏+]

实验报告

1.写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。要求该类具有:

(1) 使用构造函数完成各属性的初始赋值

(2) 使用get…()和set…()的形式完成属性的访问及修改

(3) 提供计算面积的getArea()方法和计算周长的getLength()方法

class Rectangle {
    private double width,height;
    private  String color;
    public Rectangle(double width,double height,String color){
        this.setWidth(width);
        this.setHeight(height);
        this.setColor(color);
    }
    public void tell(){
        System.out.println("宽:"+width+"  "+"高:"+height+"  "+"颜色:"+color);
    }
    public double getWidth(){
        return width;
    }
    public double getHeight(){
        return height;
    }
    public String getColor(){
        return color;
    }
    public void setWidth(double width){
        this.width=width;
    }
    public void setHeight(double height){
        this.height=height;
    }
    public void setColor(String color) {
        this.color=color;
    }
    public void getArea(){
        System.out.println("面积为:"+(width*height));
    }
    public void getLength(){
        System.out.println("周长为:"+(width+height)*2);
    }

}
public class Test{
     public static void main(String[] args){
         Rectangle per=new Rectangle(30,60,"yellow");
         per.tell();
         per.getArea();
         per.getLength();
     }
}

技术分享图片

2.银行的账户记录Account有账户的唯一性标识(11个长度的字符和数字的组合),用户的姓名,开户日期,账户密码(六位的数字,可以用0开头),当前的余额。银行规定新开一个账户时,银行方面提供一个标识符、账户初始密码123456,客户提供姓名,开户时客户可以直接存入一笔初始账户金额,不提供时初始余额为0。定义该类,并要求该类提供如下方法:存款、取款、变更密码、可以分别查询账户的标识、姓名、开户日期、当前余额等信息。

第四周课程总结&实验报告二

原文:https://www.cnblogs.com/chenxiaolong-cxl/p/11551738.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!