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 包名称。子包名称;

    学习总结

    好好学习,天天向上。

  • 相关阅读:
    Pixel XL编译和烧录Android 8.0
    公式编辑器CVE-2018-0798样本分析
    CVE-2021-33739 EOP漏洞分析
    Firefox 设置 Burpsuite 代理抓取本地数据包
    前端ECharts框架绘制各种图形
    c 除法反汇编算法
    IDA sig签名批量脚本
    从零构建自己的远控•客户端设计面向对象(13)
    从零构建自己的远控•AES加解密Demo(12)
    从零构建自己的远控•图像切割算法构思(11)
  • 原文地址:https://www.cnblogs.com/yuhaner/p/11556565.html
Copyright © 2011-2022 走看看