Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

2D Shapes assignment

Basically have to do this assignment for class and need some help.

Program a class for each of the following 2D shapes:
Circle
Triangle
Rectangle
Trapezoid

Each 2D shape class must have the following:
  • Appropriate instance variables that are all set to private. (i.e. length, width, area, etc.)
    One static variable that holds the number of instantiated objects of the class.
    Use of the this keyword in constructors/methods when dealing with a class' instance variables.
    Overloaded constructors, except for the Circle class. For example...


Code
Rectangle(double length)
Rectangle(double length, double width)
  • One private void method that calculates circumference/perimeter. For example...


Code
private void calculatePerimeter()
  • One private void method that calculates area. For example...


Code
private void calculateArea()
  • Public getter methods for each private variable. For example...


Code
public double getLength()
  • Overloaded public setter methods in the same manner as the constructors. For example...


Code
public void setRectangle(double length)
public void setRectangle(double length, double width)
  • One public print method to print out all its instance variables. For example...


Code
public void print()

Your Main class should have the following:
  • Declaration of two instances of each class, each initialized with different values.

  • Printout of each instance using their print methods.

  • A resetting of each instance using their setter methods, giving them different values.

  • Another printout of each instance using their print methods.


You never specified as to what you need help with.
(Feb 21, 2018 10:37 PM)Untold Wrote:  You never specified as to what you need help with.

He may want a pseudo-code outline of one of the shapes to compare to.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™Apr 4, 2018 07:34 PM 6 187 Apr 4, 2018 07:34 PM
Last Post: ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™
[Shell] by ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™Mar 23, 2017 09:21 PM 0 178 Mar 23, 2017 09:21 PM
Last Post: ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™
[Java] by GreyCoderJul 18, 2015 08:57 AM 0 132 Jul 18, 2015 08:57 AM
Last Post: GreyCoder