日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java类与对象实验报告心得体会_第四周课程总结与实验报告(Java简单类与对象)...

發(fā)布時間:2023/12/10 java 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java类与对象实验报告心得体会_第四周课程总结与实验报告(Java简单类与对象)... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.寫一個名為Rectangle的類表示矩形。其屬性包括寬width、高height和顏色color,width和height都是double型的,而color則是String類型的。要求該類具有:

(1) 使用構造函數(shù)完成各屬性的初始賦值

(2) 使用get…()和set…()的形式完成屬性的訪問及修改

(3) 提供計算面積的getArea()方法和計算周長的getLength()方法

實驗代碼

public class Rectangle {

private double height;

private double width;

private String color;

public double getHeight(){

return height;

}

public void setHeight(double height){

this.height = height;

}

public double getWidth(){

return width;

}

public void setWidth(double width){

this.width = width;

}

public String getColor(){

return color;

}

public void setColor(String color){

this.color = color;

}

public Rectangle(double height,double width,String color ){

this.setHeight(height);

this.setWidth(width);

this.setColor(color);

}

public void getArea(){

double area = 0;

area = this.height*this.width;

System.out.println("矩形的面積" + area);

}

public void getGirth(){

double girth = 0;

girth = (this.height + this.width)*2;

System.out.println("矩形的周長" + girth);

}

public String toString(){

String recStr = "矩形的高度:" + this.getHeight() + "矩形的高度:" + this.getWidth() + "顏色:" + this.getColor();

return recStr;

}

public static void main(String args[]){

Rectangle rec = new Rectangle(8,9,"黑色");

rec.getArea();

rec.getGirth();

System.out.println(rec.toString());

}

}

原文:https://www.cnblogs.com/buxiu888/p/11536002.html

總結

以上是生活随笔為你收集整理的java类与对象实验报告心得体会_第四周课程总结与实验报告(Java简单类与对象)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。