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

    实验二 Java简单类与对象

    一.实验目的

    (1).掌握类的定义,熟悉属性、构造函数、方法的作用,掌握用类作为类型声明变量和方法返回值

    (2).理解类和对象的区别,掌握构造函数的使用,熟悉通过对象名引用实例的方法和属性

    (3).理解static修饰付对类、类成员变量及类方法的影响

    二.实验内容

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

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

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

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

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

    实验源码

        public class new1{
            private double width, height;
            private String color;
        
            public new1(double width, double height, String color) {
                this.setWidth(width);
                this.setHeight(height);           
                this.setColor(color);
            }
            public new1() {
                // TODO Auto-generated constructor stub  
            }
            public void setWidth(double width) {
                this.width = width;
            }
            public void setHeight(double height) {
                this.height = height;
            }
            public void setColor(String color) {                  
                this.color = color;
            }
            public double getWidth() {
                return width;
            }
            public double getHeight() {
                return height;
            }
            public String getColor() {                           
                return color;
            }
            public double getArea() {
                return this.width*this.height;              
            }
            public double getGetlength() {
                return (this.height+this.width)*2;       
            }
            public static void main(String[] args) {
                new1 a=null;
                a = new new1();        
                a.width=7.0;                                          
                a.height=8.0;
                System.out.println(+a.getArea());              
                System.out.println(+a.getGetlength());
            }
        }
    

    太难了

    实验结果

    第四周总结

    1.字符串的连接

    public String concat(String str)
    该方法的参数为一个String类对象,作用是将参数中的字符串str连接到原来字符串的后面.

    2.important语句

    有了解在important static静态输入之后比原来的代码输入要更为简洁,不必在System.out.println中键入System。

    3.包的概念:

    包是java里的文件夹,包是在使用多个类或接口时,为了避免名称重复而采用的一种措施。程序中的关键字为package。

    4.对象数组

    数组一定要先开辟空间;并且数组里面的每一个对象都是null值,所以在使用的时候数组中的每一个对象必须分别进行实例化。

  • 相关阅读:
    my read map subway / metro / map / ditie / gaotie / traffic / jiaotong
    hd printer lexmark / dazifuyin / dayin / fuyin
    软件应用程序的打包和部署
    99款高质量免费(X)HTML/CSS模板
    PetShop4.0的安装、设置、调试与体验(草稿)
    山塞一个PetShop(Task000)——架构
    如何用C#开发的计算器小软件
    DIV+CSS布局参考站点
    影响计算机性能的设置
    ASP.NET知识点:母版页的路径问题
  • 原文地址:https://www.cnblogs.com/9557yxl/p/11560034.html
Copyright © 2011-2022 走看看