2014-06-21 84 views
-6

好吧我一直堅持這10個錯誤,有人可以幫助我嗎?這些錯誤是關於標識符和東西的問題。我堅持了這一段時間,只是不知道我錯了哪裏?我沒有正確設置變量或什麼?這個錯誤:我應該如何解決這個問題

DemoSquare.java:36:錯誤:預期 公共廣場(高度,寬度) ^

DemoSquare.java:36:錯誤:預期 公共廣場(高度,寬度) ^

DemoSquare.java:36:error:';'預期 公共廣場(高度,寬度) ^

DemoSquare.java:39:錯誤:預期 square_width =寬度; ^

DemoSquare.java:42:錯誤:類,接口,或枚舉預期 公衆詮釋的getHeight() ^

DemoSquare.java:47:錯誤:類,接口,或枚舉預期 } ^

DemoSquare.java:48:錯誤:類,接口,或枚舉預期 公衆詮釋的getWidth(){ ^

DemoSquare.java:50:錯誤:類,INTE rface,或枚舉預期 } ^

DemoSquare.java:51:錯誤:類,接口,或枚舉預期 公衆詮釋computeSurfaceArea() ^

DemoSquare.java:54:錯誤:類,接口或枚舉預期 surfaceArea =(getheight()* getwidth()); ^

DemoSquare.java:55:error:class,interface,or enum expected return surfaceArea; ^

DemoSquare.java:57:錯誤:類,接口,或枚舉預期 } ^ 12錯誤

工具退出碼1

`import java.util.Scanner; 
public class DemoSquare 
{ 
public static void main(String args[]) 
{ 
Scanner input = new Scanner(System.in); 

    //Prints asking for Square user input 
    System.out.println("Please enter square height: "); 
    int square_height = input.nextInt(); 
    System.out.println("Please enter square width: "); 
    int square_width = input.nextInt(); 

    //Prints asking for Cube user input 
    System.out.println("Please enter cube height: "); 
    int cube_height = input.nextInt(); 
    System.out.println("Please enter cube width: "); 
    int cube_width = input.nextInt(); 
    System.out.println("Please enter cube depth: "); 
    int cube_depth = input.nextInt(); 

    //Prints for Square Area :) 
    Square aSquare = new Square(square_height, square_width); 
    System.out.println("Square Area is: "+ square.computeSurfaceArea()); 
    Cube aCube = new Cube(cube_height, cube_width, cube_depth); 
    System.out.println("Cube Area is: " + cube.computeSurfaceArea()); 

} 

} 

public class Square 
{ 
    int square_height = 0; 
    int square_width = 0; 

    public Square(height, width) (
    square_height= height; 
    square_width= width; 
    } 

    public int getheight() 
{ 

    return square_height; 

    } 

    public int getwidth(){ 

    return square_width; 
    } 

    public int computeSurfaceArea() 
    { 
    int surfaceArea = square_height * square_width; 
    surfaceArea = (getheight() * getwidth()); 
    return surfaceArea; 

    } 

    } 
    public class Cube extends Square 
    { 

     int cube_height = 0; 
     int cube_width = 0; 
     int cube_depth = 0; 


     public Cube(int height, int width, int depth) { 
     super(cube_height, cube_width); 
     cube_depth = depth; 
    } 

    @Override 
    public int getcube_width() { 
     return cube_width; 
    } 

    @Override 
    public int getcube_height() { 
     return cube_Height; 
    } 

    public int getcube_depth() { 
     return cube_depth; 
    } 

    @Override 
    public int computeSurfaceArea() { 

     int cube_surface_area = (cube_height * cube_width * cube_depth); 

     return cube_surface_area; 
    } 
    }` 
+0

在這裏,他們是:1。更具體2.更具體3.更具體4.更具體5。更具體6.更具體7.更具體8.更具體9.更具體10.更具體 – awksp

+0

我投票結束。閱讀幫助中心。 –

+0

請記住,Java是區分大小寫的。 – Christian

回答

0

我注意到的第一件事完成在這裏,

public Square(height, width) 

應該是

public Square(int height, int width) 

我注意到接下來的事情

public int computeSurfaceArea() 
{ 
    // int surfaceArea = square_height * square_width; 
    // surfaceArea = (getheight() * getwidth()); 
    return getheight() * getwidth(); 
} 

最後,我建議你遵循標準的Java命名慣例; getHeight()getWidth(),然後getHeight(),getWidth()getDepth()Cube。也可以稱它爲getSurfaceArea()。一致性很好(並記住maintenance programmer)。

注意這也適用於您的Cube構造,速戰速決 -

public Cube(int height, int width, int depth) { 
    super(height, width); // cube_height, cube_width are defaulting to 0. 
    cube_depth = depth; 
    cube_height = height; // <-- you called it cube_height, not just height. 
    cube_width = width; 
} 
+0

@ElliottFrish是computeSurfaceArea灰色文本你的建議或我錯在哪裏? – user3761973

+0

@ user3761973我在評論你現有的代碼。您不需要臨時變量,或者每次調用計算表面積兩次。只需返回結果。 –

+0

@ElliottFrish謝謝我把它縮小到2。它說它找不到符號System.out.println(「Cube Area is:」+ cube.computeSurfaceArea()); – user3761973