十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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;
}
}
麻烦采纳呦~~~亲
// 矩形
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()重新设置矩形宽
兄弟帮你写了一个:
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
public class Print {
public static void main(String[] args) {
new Te();
}
}
class Te extends Frame implements ActionListener {
Color cc = Color.red;
int x = -20, y = -50;
Random r = new Random();
public Te() {
this.setLayout(null);
Button b = new Button("画圆");
this.add(b);
b.setBounds(30,30,50,50);
b.addActionListener(this);
this.addWindowListener(new WindowAdapter () {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBounds(200,200,500,400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
this.cc = Color.red;
this.x = r.nextInt(400);
do {
int x1 = r.nextInt(300);
this.y = x1;
} while (this.y 50);
this.repaint();
}
@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(cc);
g.drawRect(x,y,50,50);
g.setColor(c);
}
}
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;
}
}
public class Rectangle{
private int width;
private int height;
public Rectangle(){
this.width = 10;
this.height = 10;
}
public Rectangle(int width, int height){
this.width = width;
this.height = height;
}
public int area(){
return width * height;
}
//省略getter/setter
}
这个我做完了 希望您能满意
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 width,double height,String color){
this.setColor(color);
this.setHeight(height);
this.setWidth(width);
}
public void getArea(){
double area=0;
area=this.height*this.width;
System.out.println("矩形的面积为"+area);
}
public String toString(){
String recStr="矩形的高度:"+this.getHeight()+"宽度:"+this.getWidth()
+"颜色:"+this.getColor();
return recStr;
}
/**
* 测试函数
* @param args
*/
public static void main(String[] args) {
Rectangle rec=new Rectangle(3, 4, "红色");
rec.getArea();
System.out.println(rec.toString());
}
}