「java矩形等分」java画矩形

博主:adminadmin 2023-03-19 10:33:10 504

今天给各位分享java矩形等分的知识,其中也会对java画矩形进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java中关于矩形类

public class Rectangle2 {

// 属性:

private double m_height;

private double m_width;

private double m_x1;

private double m_y1;

private double m_x2;

private double m_y2;

private boolean m_isRectangle;

// 操作:

public Rectangle2() {

this(0.0, 0.0, 0.0, 0.0);

}

public Rectangle2(double aX1, double aY1, double aX2, double aY2) {

setCoordinates(aX1, aY1, aX2, aY2);

}

public void setCoordinates(double aX1, double aY1, double aX2, double aY2) {

m_x1 = aX1;

m_y1 = aY1;

m_x2 = aX2;

m_y2 = aY2;

setHeight();

setWidth();

isRectangle();

}

public boolean isRectangle() {

if ((m_height = 0 m_width = 0) (m_x1 != m_x2 || m_y1 != m_y2)) {

System.err.println("输入的坐标构成一个矩形");

m_isRectangle = true;

} else {

if ((m_x1 == m_x2 m_y1 != m_y2)

|| (m_x1 != m_x2 m_y1 == m_y2)) {

System.err.println("输入的坐标构成一条直线");

} else if (m_x1 == m_x2 m_y1 == m_y2) {

System.err.println("输入的坐标构成一点");

}

m_isRectangle = false;

}

return m_isRectangle;

}

public boolean isSquare() {

return isRectangle() m_height == m_width;

}

private void setHeight() {

double side1 = Math.abs(m_x1 - m_x2);

double side2 = Math.abs(m_y1 - m_y2);

m_height = side1 = side2 ? side1 : side2;

}

private void setWidth() {

double side1 = Math.abs(m_x1 - m_x2);

double side2 = Math.abs(m_y1 - m_y2);

m_width = side1 = side2 ? side1 : side2;

}

public double getHeight() {

return m_height;

}

public double getWidth() {

return m_width;

}

public double perimeter() {

return 2 * (m_height + m_width);

}

public double area() {

return m_height * m_width;

}

}

public class Rectangle2Test {

public static void main(String[] args) {

// TODO Auto-generated method stub

Rectangle2 rect1 = new Rectangle2();

System.err.println(rect1.isRectangle());

System.err.println(rect1.isSquare());

System.err.println(rect1.getHeight());

System.err.println(rect1.getWidth());

System.err.println(rect1.perimeter());

System.err.println(rect1.area());

Rectangle2 rect2 = new Rectangle2(22, 33, 66, 99);

System.err.println(rect2.isRectangle());

System.err.println(rect2.isSquare());

System.err.println(rect2.getHeight());

System.err.println(rect2.getWidth());

System.err.println(rect2.perimeter());

System.err.println(rect2.area());

}

}

Java 编写一个矩形类Rect

public class Rect {

private double length;//矩形的长

private double width;//矩形的宽

public Rect() {}//默认构造器

public Rect(double length,double width) {

this.length = length;

this.width = width;

}

/**

* 取得矩形的面积

* */

public double getArea(){

return this.getLength() * this.getWidth();

}

/**

* 取得矩形的周长

* */

public double getPerimeter(){

return (this.getLength() + this.getWidth()) * 2;

}

/**

* 取得矩形的面积,需传入矩形长与宽

* */

public double getArea(double length,double width){

return length * width;

}

/**

* 取得矩形的周长,需传入矩形长与宽

* */

public double getPerimeter(double length,double width){

return (length + width) * 2;

}

public double getLength() {

return length;

}

public void setLength(double length) {

this.length = length;

}

public double getWidth() {

return width;

}

public void setWidth(double width) {

this.width = width;

}

}

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编写一个矩形类,至少包含以下方法:

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创建一个矩形类Rectangle

这个问题是java最基础的了,希望你自己可以好好地看一下书本,上面都是有的,而且自己看书解决,比来这提问有效的多。

关键是自己注意你所需要定义的类有哪些属性,然后按照这些慢慢去写就好了。

关于java矩形等分和java画矩形的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。