Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Create a new application (class) and call it ShapeExercise. Next, within the application, create a super class called Shape, two subclasses called equalSides and unequalSides, and a sub-sub class under equalSides called square and a sub-sub class under unequalSides called trapezoid.

The superclass Shape should have 2 methods - a set and get method to store the shape name.
No methods are needed for subclasses equalSides or unequalSides.
Two methods are needed for sub-sub class square - a set and get method to calculate the area (area of a shape is a side*side).
Two methods are needed for sub-sub class trapezoid - a set and get method to calculate the area (area of a trapezoid is a 0.5*(side1 + side2)*height ).

In the main method, you should ask the user whether they want to calculate the area of a square of trapezoid.

If they choose square, ask them for the length of a side. Set the shape name, set the area, and display the name of the shape, the length of the side, and the area of the square.

If they choose trapezoid, ask them for the length of a side1, length of side2, and the height. Set the shape name, set the area, and display the name of the shape, the length of side1, length of side2, the height, and the area of the trapezoid on the screen with the get methods.
Posted
Updated 10-May-11 5:33am
v2
Comments
Marc A. Brown 10-May-11 11:33am    
What's your question? What have you tried? What specific issues have you encountered?
Nagy Vilmos 10-May-11 11:56am    
Beyond brain-pain, I don't think anything was tried.
Marc A. Brown 10-May-11 11:59am    
I figure you're right, but it's good to give the OP a chance. Oddly, he posted 2 assignments. I saw the second after I'd added the GimmeCode and homework tags to this one. I went in to do the same to the second and he was editing his own post. He added those tags to the second one himself, or so it appears!
Member 7912316 10-May-11 12:02pm    
Look it's the end of the semester and my brain is fried. Can you please just help me out?
Richard MacCutchan 10-May-11 12:14pm    
Why on earth would anyone write your assignment for you just because you are too lazy to do it yourself?


1 solution

class ShapeExercise {
    // add code
}

class Shape {
    // add code

    String getName() {
        // add code
    }

    void setName(String aName) {
        // add code
    }
}

class EqualSides extends Shape {
    // add code
}

class UnequalSides extends Shape {
    // add code
}

class Square extends EqualSides {
    // add code
}

class Trapezoid extends UnequalSides {
    // add code

}


I'll leave the rest to you...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900