zoukankan      html  css  js  c++  java
  • 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 包名称。子包名称;

    学习总结

    好好学习,天天向上。

  • 相关阅读:
    Python正则表达式------进阶
    基本数据类型(字符串_数字_列表_元祖_字典_集合)
    python目录
    python------异步IO数据库队列缓存
    saltstack技术入门与实践
    扒一扒JavaScript 预解释
    微信二维码防伪
    web前端页面性能优化小结
    js 中 continue 与 break 熟练使用
    倒计时原生js
  • 原文地址:https://www.cnblogs.com/yuhaner/p/11556565.html
Copyright © 2011-2022 走看看