zoukankan      html  css  js  c++  java
  • 第四周总结

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

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

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

    (3) 提供计算面积的getArea()方法和计算周长的getLength()方法
    源代码:
    public class Rectangle {
    private double width;
    private double height;
    private String color;

    public double getWidth() {
        return width;
    }
    public void setWidth(double width) {
        this.width = width;
    }
    public double getHeight() {
        return height;
    }
    public void setHeight(double height) {
        this.height = height;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public Rectangle(double width,double height,String color) {
        this.setColor(color);
        this.setHeight(height);
        this.setWidth(width);
    }
    
    public double getArea() {
        return width * height;
    }![](https://img2018.cnblogs.com/blog/1608323/201909/1608323-20190920194955511-1140735610.png)
    

    2.银行的账户记录Account有账户的唯一性标识(11个长度的字符和数字的组合),用户的姓名,开户日期,账户密码(六位的数字,可以用0开头),当前的余额。银行规定新开一个账户时,银行方面提供一个标识符、账户初始密码123456,客户提供姓名,开户时客户可以直接存入一笔初始账户金额,不提供时初始余额为0。定义该类,并要求该类提供如下方法:存款、取款、变更密码、可以分别查询账户的标识、姓名、开户日期、当前余额等信息。
    源代码:
    import java.util.Date;
    import java.util.Scanner;
    public class Bank{
    private String id;
    private String name;
    private Date createTime;
    private String mima;
    private int balance;
    public amount(Sring id,String name,int balance){
    }
    super();
    this.id=id;
    this.name=name;
    this.balance=balance;
    this.createTime=new Date();
    this.mima=123456;
    }
    public void deposit(int amount){
    this.balance+=amount;
    }
    public void withdraw(int amount){
    this.balance-=amount;
    }
    public Date getCreateTime()
    {
    return createTime;
    }
    public void setCreateTime(Date createTime){
    this.createTime=createTime;
    }
    public void changemima(){
    Scanner sc=new Scanner(System.in);
    System.out.println(请输入新的密码:);
    String mima=sc.nextString();
    this.mima=new mima;
    }
    public static void main(String[] args){
    Bank a=new Bank(1234567890,luxi,1000);
    a.deposit(100);
    a.withdraw(150);
    a.changemima();
    a.createTime();
    System.out.println(账户账户:+a.etld()):
    System.out.println(账户姓名:+a.getName());
    System.out.println(账户日期:+a.getCreateTime());
    System.out.println(账户余额:+a.getAmount()):
    }
    }
    总结:总的来说 东西越来越深奥了 我越来越迷糊了,对String类对象和this关键字的理解还有待加强,emmmm 还需努力啊

  • 相关阅读:
    syslog(),closelog()与openlog()--日志操作函数 (1)
    C语言之strrchr函数
    HTTP 报文
    Apache Hive 建表操作的简单描述
    Apache Hive 简介及安装
    Hadoop之MapReduce(二)序列化,排序及分区
    Hadoop之MapReduce(一)简介及简单案例
    Hadoop之HDFS(三)HDFS的JAVA API操作
    Hadoop之HDFS(二)HDFS基本原理
    Hadoop之HDFS(一)HDFS入门及基本Shell命令操作
  • 原文地址:https://www.cnblogs.com/lijiawei18/p/11559474.html
Copyright © 2011-2022 走看看