码迷,mamicode.com
首页 > 其他好文 > 详细

第四周总结

时间:2019-09-20 21:38:36      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:长度   etc   ble   class   string类   eth   super   string   努力   

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 还需努力啊

第四周总结

标签:长度   etc   ble   class   string类   eth   super   string   努力   

原文地址:https://www.cnblogs.com/lijiawei18/p/11559474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!