zoukankan      html  css  js  c++  java
  • 第四周课程总结&试验报告(二)

    第四周课程总结

    本周学习了String的多种常见方法,比如substring,indexOf等。
    在代码方法练习了get方法和set方法。

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

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

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

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

    package two;
    class Rectangle{
    	private double width;
    	private double height;
    	private String color;
    	public Rectangle(double width,double height,String color) {
    		this.setWidth(width);
    		this.setHeight(height);
    		this.setColor(color);
    	}
    	public double getWidth() {
    		return width;
    	}
    	public void setWidth(double x) {
    		width = x;
    	}
    	public double getHeight() {
    		return height;
    	}
    	public void setHeight(double y) {
    		height = y;
    	}
    	public String getColor() {
    		return color;
    	}
    	public void setColor(String z) {
    		color = z;
    	}
    	public void getArea() {
    		System.out.println("面积:"+getHeight()*getWidth());
    	}
    	public void getLength() {
    		System.out.println("周长:"+(getHeight()+getWidth())*2);
    	}
    	public void getTest() {
    		System.out.println("颜色:"+getColor());
    	}
    }
    public class w1 {
    	public static void main(String[] args) {
    		Rectangle per=new Rectangle(5.0,5.0,"red");
    		per.getArea();
    		per.getLength();
    		per.getTest();
    	}
    }
    

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

    package two;
    class Account{
    	private String id;
    	private String time;
    	private String cipher;
    	private String name;
    	private double password;
    	public Account(String id,String time,String cipher,String name,double password) {
    		this.setId(id);
    		this.setTime(time);
    		this.setCipher(cipher);
    		this.setName(name);
    		this.setPassword(password);
    	}
    	
    	public String getId() {
    		return id;
    	}
    	public void setId(String d) {
    		id = d;
    	}
    	public String getTime() {
    		return time;
    	}
    	public void setTime(String a) {
    		time = a;
    	}
    	public String getCipher() {
    		return cipher;
    	}
    	public void setCipher(String b) {
    		cipher = b;
    	}
    	public String getName() {
    		return name;
    	}
    	public void setName(String c) {
    		name = c;
    	}
    	public double getPassword() {
    		return password;
    	}
    	public void setPassword(double d) {
    		password = d;
    	}
    	
    	public void OP() {
    		System.out.println("卡号:"+getId());
    		System.out.println("开户日期:"+getTime());
    		System.out.println("户主:"+getName());
    		System.out.println("余额:"+getPassword());
    	}
    	
    }
    public class w2 {
    	public static void main(String[] args) {
    		Account per=new Account("00000000001","2019/09/19","123456","吴贵君",2000.0);
    		per.OP();
    	}
    }
    

  • 相关阅读:
    C# String 前面不足位数补零的方法
    bootstrap-wysiwyg这个坑
    PRECONDITION_FAILED
    JdbcTemplate in()传参
    Mysql Specified key was too long; max key length is 767 bytes
    获取两日期之前集合并转为String类型的集合
    SQL里的concat() 以及group_concat() 函数的使用
    spring boot如何打印mybatis的执行sql
    MockMvc 进行 controller层单元测试 事务自动回滚 完整实例
    找到 Confluence 6 的日志和配置文件
  • 原文地址:https://www.cnblogs.com/wuguijunniubi/p/11557888.html
Copyright © 2011-2022 走看看