Results 1 to 5 of 5
Thread: javac errors
- 10-17-2011, 12:41 PM #1
Member
- Join Date
- Sep 2011
- Location
- Sale, Cheshire
- Posts
- 10
- Rep Power
- 0
javac errors
I am trying to compile the program below, which gives 2 errors:
<identifier> expected (lines 6 & 7)
class, interface, or enum expected (lines 9,10,11,12). Would anyone know why please?
Thanks MBD.Java Code:class TwoDShape { private double width; private double height; private String name; { width = height = 0.0; name = "null"; } TwoDShape(double w, double h, String n) { width = w; height = h; name = n; } TwoDShape(double x, String n) { width = height = x; name = n; } TwoDShape(TwoDShape ob) { width = ob.width; height = ob.height; name = ob.name; } double getWidth() { return width; } double getHeight() { return height; } void setWidth(double w) { width = w; } void setHeight(double h) { height = h; } String getName() { return name; } void showDim() { System.out.println("Width and height are " + width + " and " + height); } double area() { System.out.println("area() must be overridden"); return 0.0; } } class Triangle extends TwoDShape { private String style; Triangle() { super(); style = "null"; } Triangle(String s, double w, double h) { super(w, h, "triangle"); style = s; } Triangle(double x) { super(x, "triangle"); style = "isosceles"; } Triangle(Triangle ob) { super(ob); style = ob.style; } double area() { return getWidth() * getHeight() / 2; } void showStyle() { System.out.println("Triangle is " + style); } } class Rectangle extends TwoDShape { Rectangle() { super(); } Rectangle(double w, double h) { super(w, h, "rectangle"); } Rectangle(double x) { super(x, "rectangle"); } Rectangle(Rectangle ob) { super(ob); } boolean isSquare() { if(getWidth() == getHeight()) return true; return false; } double area() { return getWidth() * getHeight(); } } class DynShapes { public static void main(String args[]) { TwoDShape shapes[] = new TwoDShape[5]; shapes[0] = new Triangle("right", 8.0, 12.0); shapes[1] = new Rectangle(10); shapes[2] = new Rectangle(10, 4); shapes[3] = new Triangle(7.0); shapes[4] = new TwoDShape(10, 20, "generic"); for(int i=0; i < shapes.length; i++) { System.out.println("object is " + shapes[i].getName()); System.out.println("Area is " + shapes[i].area()); System.out.println(); } } }Last edited by JosAH; 10-17-2011 at 01:10 PM.
- 10-17-2011, 01:23 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 10-17-2011, 09:37 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 83
- Rep Power
- 0
Re: javac errors
Actually, the code he showed is syntactically off in that general area. There is a superfluous pair of curly braces in lines 5 and 8. MBD, I'm guessing you meant to make lines 5-8 a constructor? You just forgot the "TwoDShape()" bit before the opening curly brace.
- 10-17-2011, 09:43 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: javac errors
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-17-2011, 11:37 PM #5
Similar Threads
-
help with javac
By copy you in forum New To JavaReplies: 8Last Post: 09-18-2011, 08:54 PM -
javac
By Sephij in forum New To JavaReplies: 9Last Post: 08-05-2011, 08:00 AM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
javac DOS
By rdunne in forum New To JavaReplies: 3Last Post: 01-01-2008, 11:49 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks