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

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

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

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

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

    实验代码

    package pro03;
    
    public class java1 {
    	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 java1 (double width, double height, String color) {
    		this.setColor(color);
    		this.setHeight(height);
    		this.setWidth(width);
    	}
    	
    	public void getArea(){
    		double area = this.height*this.width;
    		System.out.println("矩形的面积为:"+area);
    	}
    	
    	public void getPerimeter() {
    		double Perimeter = (this.height + this.width)*2;
    		System.out.println("矩形的周长为:"+Perimeter);
    	}
    	public void getcolor() {
    		String color = "black";
    		System.out.println("矩形的颜色为:"+color);
    	}
    	public static void main(String[] args) {
    		java1 per = new java1(30,60,"black");
    		per.getArea();
    		per.getPerimeter();
    		per.getcolor();
    	}
    }
    
    

    运行截图

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

    实验代码

    package pro03;
    import java.io.*;
    public class java2 {
    	private String user;
    	private String name;
    	private String Date;
    	private long password;
    	private double money;
    	public void display() {
    		System.out.println("客户信息:");
    		System.out.println("账户标识:"+this.user);
    		System.out.println("姓名:"+this.name);
    		System.out.println("开户日期:"+this.Date);
    		System.out.println("当前余额:"+this.money);
    	}
    	public String getUser() {
    		return user;
    	}
    	public void setUser(String user) {
    		this.user = user;
    	}
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	public String getDate() {
    		return Date;
    	}
    	public void setDate(String date) {
    		Date = date;
    	}
    	public long getPassword() {
    		return password;
    	}
    	public void setPassword(long password) {
    		this.password = password;
    	}
    	public double getMoney() {
    		return money;
    	}
    	public void setMoney(double money) {
    		this.money = money;
    	}
    	public void cq(double money) {
    		this.money+=money;
    		System.out.println("当前余额:"+this.money+"元");
    	}
    	public void qq(double money) {
    		if(money>this.money) {
    			System.out.println("余额小于"+money+"元");
    			return;
    		}
    		else {
    			this.money-=money;
    			System.out.println("当前余额:"+this.money+"元");
    		}
    	}
    	
    	public void changepassword()throws IOException{
    		BufferedReader buffer;
    		String str;
    		buffer=new BufferedReader(new InputStreamReader(System.in));
    		System.out.println("输入要更改的密码:");
    		str=buffer.readLine();
    		this.password=Long.parseLong(str);
    		System.out.println("密码更改为:"+str);
    	}
    	public void Account() {};
    	public void Account(String user, String name,String Date,long password,double money) {
    		this.user=user;
    		this.name=name;
    		this.Date=Date;
    		this.password=password;
    		this.money=money;
    	};
    	public static void main(String args[]) {
    		java2 Bank=new java2("000123","XINGMING","2019/9/20",123456,0.00);
    		Bank.display();
    		try {
    			Bank.changepassword();
    		}catch(IOException a) {
    			a.printStackTrace();
    		}
    		Bank.qq(1200);
    		Bank.cq(1000);
    		
    		
    	}
    }
    

    第三次学习总结

    (1)String声明的是一个字符串,本身是一个类的定义。可以采用直接赋值的方式进行操作 也可以实例化对象。“==”比较的是地址是否相同,而equals()方法则是对内容进行比较。

    (2)字符串一旦声明内容无法改变

    (3)String类的常用操作方法在数110页到111页。

    (4)package是在使用多个类或接口时,为了避免名称重复而采用的一种措施,直接在程序中加入package关键字即可

    (5)使用不同包中的东西需要用import引入。

    (6)对象数组

    类 对象数组名称[]=new 类[数组长度]
    数据类型 数组名称[]=null;
    数组名称=new 数据类型[长度];
    
  • 相关阅读:
    红帽中出现”This system is not registered with RHN”的解决方案
    消息队列
    安装nmap
    工作后才知道
    虚拟空间测速
    Update 两个表之间数据更新 (转)
    破解
    一步步打造自己的代码生成器
    Table轻松实现报表 转载
    sql使用convert转化
  • 原文地址:https://www.cnblogs.com/zzwwll/p/11544230.html
Copyright © 2011-2022 走看看