Program to calculate the perimeter of a square, rectangle and triangle

programtocalculatetheperimeterofasquarerectangleandtriangle.java

// Program to calculate the perimeter of a square, rectangle and triangle

public class Shape
{
 private String shape;
 private int perimeter;
 public String m;

 // constructors

 public Shape()
 {
  setPerimeter();
  setShape("point");

 }

 public Shape(int x)
 {
  setPerimeter(x);
  setShape("Square");
 }

 public Shape(int x, int y)
 {
  setPerimeter(x,y);
  setShape("Rectangle");
 }

 public Shape(int x, int y, int z)
 {
  setPerimeter(x,y,z);
  setShape("Triangle");
 }

 // method to set the name of the shape

 public void setShape(String m)
 {
  shape = m;
 }

 // Methods to calculate the perimetre of the shapes

 public void setPerimeter()
 {
  perimeter=0;
 }

 public void setPerimeter(int x)
 {
  perimeter=x*4;
 }

 public void setPerimeter(int x, int y)
 {
  perimeter=(x*2)+(y*2);
 }

 public void setPerimeter(int x , int y, int z)
 {
  perimeter = x+y+z;
 }

 // methods to return the values of the perimeters

 public int getPerimeter()
 {
  return perimeter;
 }

 public String getShape()
 {
  return shape;
 }
}// ends the class

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.