Results 1 to 2 of 2
- 09-07-2012, 06:44 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 13
- Rep Power
- 0
Im having trouble with my Shape classes in java! im lost please help
hi I dont know what im doing anymore ...im lost and Im getting an error message please help me...I dont know where to go from here ..im getting the error below and these are my classes im stuck! please help!
this is my error message
XML Code:Exception in thread "main" java.lang.Error: Unresolved compilation problem: Void methods cannot return a value at Shape.<init>(Shape.java:40) at Circle.<init>(Circle.java:6) at ShapeApp.main(ShapeApp.java:17)
XML Code:public class Rectangle implements Triangle { private double length; private double heigth; public Rectangle() { super(); setLength( super.DEFAULT_SIZE ); setHeight( Shape.DEFAULT_SIZE ); } public Rectangle(String string, String string2 ){ super(); } public double getSurfaceArea() { return this.length * this.heigth; } public double getPeremeter() { return 2 * this.length + 2 * this.length; } public double getLength(){ return this.length; } public double getHeight(){ return this.heigth; } public void setLength( double theLength ){ if ( theLength <= 0 ) return; this.length = theLength; } public void setHeight( double theHeight ){ if (theHeight <= 0 ) return; this.heigth = theHeight; } public String toString(){ return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f", "Rect Surface Area ", "Rect Peremeter", getSurfaceArea(), getPeremeter()); } public double getSizeAmount(){ return heigth; } }XML Code:public abstract class Shape implements Triangle{ protected static final double DEFAULT_SIZE = (double) 1.0; protected static final String DEFAULT_NAME = "Unknown"; private String shapeName; public Shape(){ this.shapeName = DEFAULT_NAME; } public Shape(String name) { setShapeName(name); } protected void setShapeName(String name) { if( name.trim().length() == 0 ) shapeName = DEFAULT_NAME; else shapeName = new String ( name ); } public String getShapeName() { //name return shapeName; } public abstract double getSurfaceArea(); public abstract double getPerimeter(); public String toString;{ return String.format("%s %s\nshape name: %s",getShapeName()); } }XML Code://triangle interface decleration public interface Triangle { double getSizeAmount(); //calculate sizes of triangle; no implementation }//end interface triangle
XML Code:public class Circle extends Shape { private double radius; public Circle( double theRadius ){ super(); if ( theRadius <= 0.0 ) setRadius( Shape.DEFAULT_SIZE ); else setRadius( theRadius ); } public double getSurfaceArea(){ return this.radius * this.radius * Math.PI; } public double getPeremeter(){ ; return 2 * this.radius + Math.PI; } public double getRadius(){ return this.radius; } public void setRadius( double theRadius ) { if( theRadius <= 0 ) return; this.radius = theRadius; } @Override public double getPerimeter() { // TODO Auto-generated method stub return 0; public String toString(){ return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f", "Circle Surface Area ", "Circle Peremeter", getSurfaceArea(), getPeremeter()); } } @Override public double getSizeAmount() { // TODO Auto-generated method stub return 0; } }XML Code:import javax.swing.JOptionPane; public class ShapeApp { //public static void main(String args[]) public static void main(String[] args) { Triangle triangleObjects[] = new Triangle[ 3 ]; triangleObjects[ 0 ] = new Rectangle("3.5","4.6"); triangleObjects[ 1 ] = new Rectangle("3","2"); triangleObjects[ 2 ] = new Circle(0); System.out.println( "List of all Shapes:\n" ); for( Triangle currentTriangle : triangleObjects ){ System.out.printf("%s \n%s: $%,.2f\n\n", currentTriangle.toString(), "ovo testiramo", currentTriangle.getSizeAmount()); } /* Shape[] object = new Shape[5]; int x = 0; object[0] = new Rectangle("this is rectanlge",0,0); object[1] = new Circle(); do{ try{ for(Shape p : object) { String msg = p.getSurfaceArea() +","+ p.getPerimeter(); JOptionPane.showMessageDialog(null, "Message", msg, JOptionPane.INFORMATION_MESSAGE); x=2; } }catch(Exception e) { } }while(x==1);*/ } }
- 09-07-2012, 08:57 AM #2
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Similar Threads
-
Trouble with loops/classes/something
By SykoPyro in forum New To JavaReplies: 3Last Post: 09-05-2012, 12:34 PM -
More trouble with classes and arrays
By CuddlyKittens11 in forum Advanced JavaReplies: 9Last Post: 04-27-2011, 01:25 AM -
Trouble with arrays and classes
By CuddlyKittens11 in forum Advanced JavaReplies: 3Last Post: 04-25-2011, 12:42 AM -
I'm having trouble with extending classes
By ziongio in forum New To JavaReplies: 2Last Post: 03-15-2011, 07:33 AM -
Having trouble with Classes
By Skyton in forum EclipseReplies: 7Last Post: 03-04-2011, 01:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks