• 第四周学习总结&实验报告


    学习总结;

    String类:

    1.方法只会开辟一块堆内存空间,且会自动保存在对象池中以供下次重复使用;
    2方法会开辟两块堆内存空间,其中一块会成为垃圾空间。
    1.“==”比的是地址值;equals()方法比的是内容。
    字符串的内容不可改变,如果同一个字符变量的内容改变了,则说明该变量指向不同的地址,
    String类常用方法:使用String声明字符串,在java中是一个比较特殊的类,

    实验目的:

    1,明晰类的定义,属性、熟悉构造函数、知道构造方法的作用,
    2,实现用类作为类型声明变量和方法返回值;
    3,理解类和对象的区别,构造函数的使用,熟悉通过对象名引用实例的方法和属性;
    4,理解static修饰付对类、类成员变量及类方法的影响。

    包的含义:类似开辟一个新模块。

    实验报告:

    使用java写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,
    width和height都是double型的,而color则是String类型的。

    要求矩形具有:

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

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

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

    package Java11;
    
    public class tzqd {
    		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 tzqd(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 void perimeter() {
    			double Perimeter = (this.height + this.width)*2;
    			System.out.println("周长:"+Perimeter);
    		}
    		public void colour() {
    			String color = "yellow";
    			System.out.println("颜色:"+color);
    		}
    		public static void main(String[] args) {
    			tzqd per = new tzqd(10,10,"yellow");
    			per.getArea();
    			per.perimeter();
    			per.colour();
    			
    }
    }
    


    实验2:

    银行的账户记录Account有账户的唯一性标识(11个长度的字符和数字的组合),

    1,用户的姓名,开户日期,账户密码(六位的数字,可以用0开头),当前的余额。

    2,银行规定新开一个账户时,银行方面提供一个标识符、账户初始密码123456,

    3,客户提供姓名,开户时客户可以直接存入一笔初始账户金额,不提供时初始余额为0。

    4,定义该类,并要求该类提供如下方法:存款、取款、变更密码、可以分别查询账户的标识、姓名、开户日期、当前余额等信息。

    package Java11;
    
    public class Tzqd2 {
    	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 Tzqd2(String string, String string2, String string3, String string4, double d) {
    	}
    		public static void main(String[] args) {
    	        Tzqd2 per=new Tzqd2("00000000006","2019/09/20","123456","滕自强",1314.0);
    	        per.OP();
    	    }
    		private void OP() {
    		}
    	}
    


  • 相关阅读:
    委托返回类型的协变性
    委托参数的逆变性
    单例采用双锁定技术
    Jupyter Notebook 工作空间 / 默认路径 的设置方式
    Runaway argument错误 [Overleaf: 在线Latex] [Type 3问题后续]
    [Android ADB] An auto-input method for Android and Windows
    [Latex] 所有字体embedded: Type3 PDF文档处理 / True Type转换为Type 1
    螺旋矩陣 非数组解法
    2014.9.11 Research Meeting Report
    2014.8.23 Research Meeting Report
  • 原文地址:https://www.cnblogs.com/tengziqiang/p/11559090.html
Copyright © 2020-2023  润新知