• JAVA第四周总结


    Java实验报告二

    第一题

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

    实验代码

    public class Rectangle{
    	private double width;
    	private double height;
    	private String color;
    	
        public Rectangle(double width, double height, String color) {
            this.setWidth(width);
            this.setHeight(height);           
            this.setColor(color);
        }
        public Rectangle() {
            
        }
        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) {
            Rectangle a=null;
            a = new Rectangle();          
            a.width=2.0;                                          
            a.height=3.0;
            System.out.println(+a.getArea());                
            System.out.println(+a.getGetlength());
        }
    }
    
    

    运行结果

    第二题

    不会

    第四周学习总结

    1、String类
    (1)、String首字母大写。
    (2)、一个字符串就是一个String类的匿名对象。
    (3)、使用“equals()”来比较字符串的内容,“==”是用来进行地址值的比较。
    (4)、字符串的内容一旦声明则不可改变。
    (5)、s=s.replace(a;b)把a的值替换成b。substring( ; )截取字符串。
    2、包
    (1)、管理文件,避免同名文件。
    (2)、包的定义:package 包名称。子包名称;

    学习总结

    好好学习,天天向上。

  • 相关阅读:
    生活感悟(一)
    DOM数据制作(采用卫星遥感图像数据制作)
    对话框显示前的操作
    sqlHelper中DataReader的关闭问题
    整数的取余运算
    C#中的字符串格式String.Format
    SQL分页查询
    级联删除与更新的例子
    C#中的运算符重载(以重载+为例)
    [高效编程读书笔记]用readonly而不是const
  • 原文地址:https://www.cnblogs.com/yuhaner/p/11556565.html
Copyright © 2020-2023  润新知