「java编辑矩形」java画矩形

博主:adminadmin 2022-11-29 18:20:05 78

本篇文章给大家谈谈java编辑矩形,以及java画矩形对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

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

class Rectangle{

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 编写一个矩形类 rect 要求如下:

public class Rect{

    private int length;

    private int width;

    private int startX;

    private int startY

    

    public Rect(){}

    

    public Rect(int length,int width){

            this.length = length;

            this.width = width;

    }

    

    public Rect(int length,int width,int startX,int startY){

            this.length = length;

            this.width = width;

            this.startX = startX;

            this.startY = startY;

    }

    

    //不知道你要什么成员方法,我随便点....

    

    

    public void louzhuhao(){

            System.out.println("楼主好....");

    }

public int getLength() {

    return length;

}

public void setLength(int length) {    

    this.length = length;

}

public int getWidth() {

    return width;

}

public void setWidth(int width) {

    this.width = width;

}

public int getStartX() {

    return startX;

}

public void setStartX(int startX) {

    this.startX = startX;

}

public int getStartY() {

    return startY;

}

public void setStartY(int startY) {

this.startY = startY;

}

}

java编辑矩形的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java画矩形、java编辑矩形的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-29,除非注明,否则均为首码项目网原创文章,转载请注明出处。