标签:客户 setw amp idt 红色 set 掌握 颜色 hang
(1) 使用构造函数完成各属性的初始赋值
(2) 使用get…()和set…()的形式完成属性的访问及修改
(3) 提供计算面积的getArea()方法和计算周长的getLength()方法
public class Rectangle { private double height; private double width; private String color; public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } 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 void getArea(){ double area=0; area=this.height*this.width; System.out.println("矩形的面积为"+area); } public String toString(){ String recStr="矩形的高度:"+this.getHeight()+"宽度:"+this.getWidth() +"颜色:"+this.getColor(); return recStr; } /** * 测试函数 * @param args */ public static void main(String[] args) { Rectangle rec=new Rectangle(3, 4, "红色"); rec.getArea(); System.out.println(rec.toString()); } }
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关键字,main方法等。这些内容还是好理解的,掌握的还不错。这周的实验还是有一点难度的,首先代码行数比较多,然后也比较复杂,算法上想了很久。
标签:客户 setw amp idt 红色 set 掌握 颜色 hang
原文地址:https://www.cnblogs.com/zcl666/p/11548199.html