Java编程简介

时间:2014-03-16 20:21:29

标签: java

我获得了创建三维形状的任务,并提示用户表面区域和体积。我的编码中有多个错误,但经过研究,我无法解决问题。我试图解决问题,但不能这样,我已经把它解决了。谁能解决或引导我朝着正确的方向前进?

代码如下:

//Point originOne = new Point(23, 94);
//Rectangle rectOne = new Rectangle(originOne, 100, 200);
//Rectangle rectTwo = new Rectangle(50,100);
//Point originOne;
//Point originOne = new Point(23, 94);
import javax.swing.JOptionPane;
public static void main(String[] args) {
    int width;
    int height;
    Rectangle(volume,area);
    JOptionpane.showMessageDialog("please input integer");

public static int volume;
    int vol;
    int side;
    vol =side*3;
public static int area;
    int 

JOptionPane.showMessageDialog( null,"information",
, JOptionPane.OK_CANCEL_OPTION);
JOptionPane.showInputDialog("Please input a value");
public static int surfacearea;
}
public class Rectangle {
    public int x = 0;
    public int y = 0;
    //constructor
    public void Point(int a, int b) {
        x = a;
        y = b;
    }

    public int width = 0;
    public int height = 0;
    public int Point ;
    public int origin;

    // four constructors
    public Rectangle() {
        origin = new Point(0, 0);
    }
    public Rectangle(Point p) {
        origin = p;
    }
    public Rectangle(int w, int h) {
        origin = new Point(0, 0);
        width = w;
        height = h;
    }
    public Rectangle(Point p, int w, int h) {
        origin = p;
        width = w;
        height = h;
    }

    // a method for moving the rectangle
    public void move(int x, int y) {
        origin.x = x;
        origin.y = y;
    }

    // a method for computing the area of the rectangle
    public int Area() {
        //return width * height;
    }
}

1 个答案:

答案 0 :(得分:0)

这应该有点帮助..它仍然有很多错误。我希望我的评论有所帮助,如果你还需要其他任何评论的话。

import javax.swing.JOptionPane;
import java.awt.Point;

public class Rectangle {

    public static int area;
    public static int volume;

    public int x = 0;
    public int y = 0;

    public int width = 0;
    public int height = 0;
    public int Point; // Uh?
    public int origin; // this isnt a Point and yet you are creating an instance of Point..
    //constructor

    /**
     * What is even the point of this????
     */
    public void Point(int a, int b) {
        x = a;
        y = b;
    }

        // main needs to go in a class
    public static void main(String[] args) {
        int width;
        int height;
        Rectangle myRectangle = new Rectangle(volume,area); // actually set a variable
        //JOptionpane.showMessageDialog("please input integer"); // research this..
        int vol;
        int side; //side isnt initialized?
        vol = side*3; //this will not work
        //JOptionPane.showMessageDialog( null,"information", JOptionPane.OK_CANCEL_OPTION);
        //JOptionPane.showInputDialog("Please input a value");
    }

    // four constructors
    public Rectangle() {
        origin = new Point(0, 0);
    }

    public Rectangle(Point p) {
        origin = p;
    }

    public Rectangle(int w, int h) {
        //This isnt calling your point method...
        origin = new Point(0, 0);
        width = w;
        height = h;
    }
    public Rectangle(Point p, int w, int h) {
        origin = p;
        width = w;
        height = h;
    }

    // a method for moving the rectangle
    public void move(int x, int y) {
        origin.x = x; // Again, this is declared as an int.
        origin.y = y; // this is declared as a int.
    }

    // a method for computing the area of the rectangle
    public int Area() {
        return width * height;
    }
}