zoukankan      html  css  js  c++  java
  • 第四周总结&实验报告二

    实验报告二

    实验目的
    掌握类的定义,熟悉属性、构造函数、方法的作用,掌握用类作为类型声明变量和方法返回值;
    理解类和对象的区别,掌握构造函数的使用,熟悉通过对象名引用实例的方法和属性;
    理解static修饰付对类、类成员变量及类方法的影响。
    实验内容
    1.写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。要求该类具有:
    (1) 使用构造函数完成各属性的初始赋值

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

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

    package test;
    
    class Rectangle {
    	private double width;
    	private double height;
    	private String color;
    	public Rectangle(double width,double height,String color) {
    		this.width = width;
    		this.height = height;
    		this.color = color;
    	}
    	public double getWidth(){
    		return width;
    	}
    	public void setwidth(double a){
    		width = a;
    	}
    	public double getheight(){
    		return height;
    	}
    	public void setheight(double b){
    		height = b;
    	}
    	public String getColor(){
    		return color;
    	}
    	public void setcolor(String c){
    		color = c;
    	}
    	public double getLengh(){
    		return (height+width)*2;
    	}
    	public double getArea() {
    		return width*height;
    	}
    }
    
    package test;
    
    public class test {
    	public static void main(String[] args) {
    		// TODO 自动生成的方法存根
    		Rectangle rec = null;
    		rec = new Rectangle(10,20,"蓝色");
    		System.out.println("宽:" + rec.getWidth());
    		System.out.println("高:" + rec.getheight());
    		System.out.println("颜色:" + rec.getColor());
    		System.out.println("面积:" + rec.getArea());
    		System.out.println("周长:  " + rec.getLengh());
    
    	}
    
    }
    
    

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

    package test1;
    
    class Account {
    	private String id;         //账户
    	private String name;      //姓名
    	private int date;        //开户日期
    	private int cipher;      //密码
    	private int balance;     //账户余额
    	
    	
    	public Account (String id,String name,int cipher,int balance) {
    		this.id=id;
    		this.name=name;
    		this.cipher=123456;
    		this.balance=balance;
    	}
    	
    	public String getId() {
    		return id;
    	}
    	public void setId1(String a) {
    		id = a;
    	}
    	
    	
    	public String getName() {
    		return name;
    	}
    	public void setName(String b) {
    		name = b;
    	}
    	
    	
    	public int getDate() {
    		return date;
    	}
    	
    	public void setDate(int c) {
    		date = c;
    	}
    	
    	
    	public int getCipher() {
    		return cipher;
    	}
    	
    	public void setCipher(int d) {
    		cipher = d;
    	}
    	
    	public int getBalance() {
    		return balance;
    	}
    	
    	public void setbalance(int e) {
    		balance = e;
    	}
    	
    }
    
    package test1;
    
    public class test {
    
    	public static void main(String[] args) {
    		Account acc=null;
    		acc=new Account("987456321", "zhangsan",123456,0);
    		System.out.println("账户:"+acc.getId());
    	    System.out.println("姓名:"+acc.getName());
    	    System.out.println("余额:"+acc.getBalance());
    	    System.out.println("密码:"+acc.getCipher());
    		
    
    	}
    
    }
    

    第三次学习总结
    这一周学习了String类,String的赋值
    复习了一下之前学的以及讲解了一些习题,老师放慢了一些节奏让我们能够跟上来,还有就是讲了一下数组
    包的基本概念和用法
    包的定义:package 包名称.子包名称;

  • 相关阅读:
    开发中常见的七种加密算法及实现
    MySql 函数大全(一)
    MySql 函数大全(二)
    MySql中查询优化方法
    double类型保留一位小数, 其他位数舍弃方法
    java.lang.IllegalArgument,Parse error in application web.xml file at jndi:/localhost/WEB-INF/web.xml
    c#版HOOK微信来了。实时获取微信消息以及公众号文章等
    c#hook微信,实现实时获取微信公众号文章
    C# 未能创建 SSL/TLS 安全通道 和C# 基础连接已经关闭: 发送时发生错误. 解决方案
    .net post一个xml文件到url
  • 原文地址:https://www.cnblogs.com/cxnkkk/p/11560210.html
Copyright © 2011-2022 走看看