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

    第四周总结&实验报告二

    课程总结

    这周我们学习了string类,以及很多string类的很多操作方法,同时string也是一个对象,在用到它时我们首字母需要大写,这周我们还加深了对函数构造的理解与运用,这周的我和上周就不一样了,上周是真的什么都不懂,这周就有那么一点点理解了,这一次可能没什么,但要是每周都这样那就是一个大进步了

    实验总结

    第四周课程总结&试验报告(二)

    1.写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。要求该类具有:
    (1) 使用构造函数完成各属性的初始赋值
    (2) 使用get…()和set…()的形式完成属性的访问及修改
    (3) 提供计算面积的getArea()方法和计算周长的getLength()方法

    package test;
    
    class lft {
        	private String color;
        	private double width;
        	private double height;
        	public lft(){
        	}
        	public lft(String color,double width,double height) {
        		this.setColor(color);
        		this.setWidth(width);
        		this.setHeight(height);
        	}
        	public void setColor(String c) {
        		color=c;
        	}
        	public void setWidth(double w) {
        		width=w;
        	}
        	public void setHeight(double h) {
        		height=h;
        	}
        	public String getColor() {
        		return color;
        	}
        	public double getWidth() {
        		return width;
        	}
        	public double getHeight() {
        		return height;
        	}
        	public double getArea() {
        		return width*height;
        	}
        	public double getLength() {
        		return (width+height)*2;
        	}
    
    };
    public class cft{
    	public static void main(String args[]) {
    		lft l=null;
    		l=new lft("blue",7.0f,8.0f);
    		System.out.println("长方体面积: "+l.getArea());
    		System.out.println("长方体周长: "+l.getLength());
    		System.out.println("颜色"+l.getColor());
    	}
    }
    

    这个题目的话还是比较简单,但对我来说还是有点难度,我是看书上的例题,然后才写出来的

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

    package test2;
    import java.util.Scanner;
    
    class Zl{
    	private String id;
    	private String name;
        private String begindate;
        private String password;
        private float menoy;
        public Zl() {
    	
         }
        public Zl(String id,String name,String begindate,float menoy) {
        	this.setId(id);
        	this.setName(name);
        	this.setBegindate(begindate);
        	this.password="123456";
        	this.setMenoy(menoy);
        	
        }
        //设置参数
        public void setId(String i) {
        	id=i;
        }
        public void setName(String n) {
        	name=n;
        }
    
        public void setBegindate(String b) {
        	begindate=b;
        }
        public void setMenoy(float m) {
        	menoy=m;
        }
        //取的参数
        public String getId() {
        	return id;
        }
        public String getName() {
        	return name;
        }
        public String getBegindate() {
        	return begindate;
        }
        public float getMenoy() {
        	return menoy;
        }
        public float cqian() {           //存钱
        	return menoy+cqian();  
        }
        public float qqian() {               //取钱
        	return menoy-qqian();
        }
        public void changepassword() {      //改密码
        	System.out.println("输入新密码 ");
        	Scanner in=new Scanner(System.in);
            int password=in.nextInt();
        }
    };
    public class Bank {
    
    	public static void main(String args[]) {
    		Zl z=null;
    		z=new Zl("CN-12345678","张三","2008.12.13",5000.0f);
    		System.out.println("账号 "+z.getId());
    		System.out.println("姓名 "+z.getName());
    		System.out.println("开户日期 "+z.getBegindate());
    		System.out.println("余额 "+z.getMenoy());
    		
    		
    	}
    }
    

    老实说这个题目我不会,这里提交的只是一部分,而现在对于我来说也只能完成一部分了,我以后会加强学习,争取把这些题目都搞懂弄会

  • 相关阅读:
    php多进程和多线程的比较
    设计模式学习系列——建造者模式
    设计模式学习系列——单例模式
    设计模式学习系列——前言
    设计模式学习系列——工厂模式
    记一次给nginx的web服务器目录加软链接
    某公司后端开发工程师面试题学习
    2010年腾讯前端面试题学习(jquery,html,css部分)
    2010年腾讯前端面试题学习(js部分)
    winfrom 隐藏任务栏(win7)
  • 原文地址:https://www.cnblogs.com/djhxxx/p/11556422.html
Copyright © 2011-2022 走看看