矩形类的创建java代码 java设计一个矩形类rectangle

Java编写一个矩形类,并计算面积和周长?

class Rectangle{

目前成都创新互联公司已为1000+的企业提供了网站建设、域名、网页空间、网站托管、服务器托管、企业网站设计、增城网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

private int width = 2;

private int length = 1;

public int getWidth(){

return this.width;

}

public void setWidth(int w){

this.width = w;

}

public int getLength(){

return this.length;

}

public void setLength(int l){

this.length = l;

}

public int getArea(){

return this.length * this.width;

}

public int getCircumference(){

return (this.length + this.width) * 2;

}

public Rectangle(){}

public Rectangle(int l, int w){

this.length = l;

this.width = w;

}

}

public class demo{

public static void main(String[] args) {

Rectangle rect = new Rectangle(30, 8);

System.out.print("长方形的面积是:");

System.out.println(rect.getArea());

System.out.printf("长方形的周长是:%d\n", rect.getCircumference());

}

}

Java编写一个矩形类,至少包含以下方法:

import java.awt.Point;

public class Rectangle {

private int widthT = 0;

private int heightT = 0;

Point point = new Point();

public Rectangle(int width, int height, int centerX, int centerY) {

widthT = width;

heightT = height;

point.x = centerX;

point.y = centerY;

}

public int width() {

return widthT;

}

public int height() {

return heightT;

}

public int centerX() {

return point.x;

}

public int centerY() {

return point.y;

}

}

麻烦采纳呦~~~亲

编写一个JAVA程序,描写一个矩形类,并输出某个矩形的长,宽,面积。具体描述如下?

// 矩形

public class RectangleDemo {

public static void main(String[] args) {

RectangleDemo demo = new RectangleDemo(12, 32);

System.out.println(demo.getPerimeter());

System.out.println(demo.getArea());

demo = new RectangleDemo();

System.out.println(demo.getArea());

System.out.println(demo.getPerimeter());

demo.setHeight(50);

demo.setWidth(30);

System.out.println(demo.getArea());

System.out.println(demo.getPerimeter());

}

// 求周

public double getPerimeter() {

return (height + width) * 2;

}

// 求面积

public double getArea() {

return height * width;

}

public RectangleDemo(double height, double width) {

this.height = height;

this.width = width;

}

public RectangleDemo() {

this.height = 10;

this.width = 10;

}

private double height;// 高度

private double width;// 宽度

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;

}

}

编写矩形类RectangleJava程序矩形类两数据员别rLength宽rWidth通getLength()、getWidth()、getArea()别查看矩形、宽面积通setLength()setWidth()重新设置矩形宽


网页名称:矩形类的创建java代码 java设计一个矩形类rectangle
本文URL:http://lszwz.com/article/dospdce.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款