Home Discussion Discuss: Write a program for calculating area and perimeter of a rectangle

  • Rectangle Classjavaheadache September 29, 2011 at 9:57 PM

    I have tried to get this java program to run without success using NetBean IDE public class Rectangle2 { /** Main method */ /** The area of the rectangle */ double area; /** The number of objects created */ static int numberOfObjects = 0; /** Construct a rectangle with area 1 */ Rectangle2() { area = 1.0; numberOfObjects++; } /** Construct a rectangle with a specified area */ Rectangle(double newArea) { area = newArea; numberOfObjects++; } /** Return numberOfObjects */ static int getNumberOfObjects() { return numberOfObjects; } /** Return the area of this rectangle */ double getArea() { return area * area * Math.PI; } } Instruction: Design a class named Rectangle to represent a rectangle. The class contains: two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. A method named getPerimeter() that returns the perimeter. I also ran this program; however it is not setup according to instruction. import java.io.*; public class Rectangle { public static void main(String[] args) { int l=1; int w=1; try{ BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter length of rectangle (e.g. 1, 2,etc) : "); l = Integer.parseInt(br1.readLine()); System.out.println("Enter width of rectangle (e.g. 1, 2, etc) : "); w = Integer.parseInt(br1.readLine()); int area = l*w; System.out.println("Area of Rectangle : "+area); int perimiter = 1*(l+w); System.out.println("Perimeter of Total: " + perimiter); }catch(Exception e){System.out.println("Error : "+e);} } }

  • c programmingekta gupta November 15, 2011 at 7:46 PM

    hello sir ji

  • javaChandrashekhar Singh February 26, 2013 at 2:46 PM

    java Question and programe discuss.

  • Question on how to write a program codeShara Carter February 23, 2012 at 2:00 AM

    Write a program that prompts user to input the length and width of a rectangle and then prints the rectangle's area dn perimeter. (Assume that the length and width are decimal numbers).

  • congratscarol kangina April 2, 2012 at 4:10 PM

    thanx for the gud job u r doing.

  • computerjoseph tuguinay September 2, 2012 at 5:18 AM

    good

  • core javarajesh September 14, 2012 at 12:26 PM

    what is buffer reader

  • ask me questionrajesh September 14, 2012 at 12:34 PM

    try,catch,why r u use in programe

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Tips and Examples

Write a program for calculating area and perimeter of a rectangle
Write a program for calculating area and perimeter of a rectangle... this lesson, you will be able to write program for calculating the area and perimeter of a rectangle.  First of all create a class named RecArea under Java.io 

Java Tips and Examples

Write a program to calculate area and perimeter of a circle
Write a program to calculate area and perimeter of a circle.... Write the program for both the cases: radius and perimeter.  Before ending... example will teach you the method for preparing a program to calculate the area 

Java Tips and Examples

A Program to find area and perimeter of Rectangle
A Program to find area and perimeter of Rectangle In this section we...; a rectangle. To find area and perimeter of a rectangle is a simple program... result. Program using function to find the area and perimeter of rectangle 

Java Beginners

accepts the area of a square and will calculate its perimeter.
accepts the area of a square and will calculate its perimeter.  Develop a program that accepts the area of a square and will calculate its perimeter... input=new Scanner(System.in); System.out.println("Enter Area of Square 

General

How to calculate area of rectangle
How to Calculate Area of Rectangle   ... of rectangle. The area of rectangle is specifies an area in a coordinate space that is enclosed by the rectangle object. In the program coordinate of space its 

General

How to calculate area of Circle
of calculating  the area of circle. In this program you will be taught each and every steps that have used in this program. The description of this program is given... How to Calculate Area of Circle    

Java Beginners

Java Program for Calculating Marks
Java Program for Calculating Marks  Hi Everyone, I have a assignment that requires me to a write simple java program that will calculate marks for 10 students. I must use an array to ask user to key in the marks for the 10 

Java Beginners

Java Program for Calculating Marks
Java Program for Calculating Marks  Hi Everyone, I have a assignment that requires me to a write simple java program that will calculate marks for 10 students. I must use an array to ask user to key in the marks for the 10 

Java Beginners

Java Program for Calculating Marks
Java Program for Calculating Marks  Hi Everyone, I have a assignment that requires me to a write simple java program that will calculate marks for 10 students. I must use an array to ask user to key in the marks for the 10 

Java Beginners

Java Program for Calculating Marks
Java Program for Calculating Marks  Hi Everyone, I have a assignment that requires me to a write simple java program that will calculate marks for 10 students. I must use an array to ask user to key in the marks for the 10 

HTML5

Area Tag in html5, Definition of tag in HTML5.
Area Tag in html5, Definition of  <area> tag in html5... in the html document. The <area> tag is used for creating an area...: The syntax for the <area> tag is as follows: <area 

MySQL

MySQL Area
MySQL Area  This example illustrates how to find the area of rectangle in MySQL. In this example we create a procedure to find the area of rectangle. In the query below we declare two integer type variable w and h with default 

SQL Tutorial

MySQL Area
MySQL Area       This example illustrates how to find the area of rectangle in MySQL. In this example we create a procedure to find the area of rectangle. In the query below we take 

Java Beginners

program
program  accepts the area of a square and will calculate its perimeter.   Hello Friend, Visit Here Thanks 

Applet Questions

Java gui program for drawing rectangle and circle
Java gui program for drawing rectangle and circle   how to write java gui program for drawing rectangle and circle? there shoud be circle and rectangle button, check box for bold and italic, and radio button red,green and blue 

Java Beginners

Find Cylinder area By inputting value from user
Find Cylinder area By inputting value from user  Hello Sir I need the code for calculating the area of a cylinder in which it asks radius value from user and then calculate area using this radius value. Please provide me 

Java Beginners

Rectangle
Rectangle  Could anybody help me on this problem, Write two Rectangle objects with the following properties: Rectangle1: Height 15 width 53 Y 25 X 15 Rectangle2: height 47 Width 60 Y 12 X 0 It's to be used four-argument 

Java Tips and Examples

Change the user input to integer
a method parseInt(). In this program we are going to calculate a area...() calculates the area of a rectangle. In the second class which is also our main... of Rectangle class.  Here is the code of the program 

Java Beginners

Program to draw rectangle on each mouse click and erase priviouse rectangles
Program to draw rectangle on each mouse click and erase priviouse rectangles  Program to draw rectangle on each mouse click and erase previous rectangle on next mouse click 

Development process Questions

c program
c program  WAP to show the area of a perimeter of a rectanglar by using input command 

Java Beginners

java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding 

Java Beginners

java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding 

PHP Tutorial

PHP GD Draw Rectangle
; After running the program you will get the following output 

Java Beginners

BlueJ (area of circle)
BlueJ (area of circle)  How does one write a program to calculate the area of a circle in BlueJ? Note that the user will have to provide the radius.   A simple program to calculate the area of a circle. radius provided 

Java Beginners

area of a circle - Java Beginners
area of a circle  Write a class circle which consists of functions getdata() and area(), and also write a main program to create a circle object and to find the area by calling the function area () in circle class and display 

General

Rectangle Image in Java
for filling the color into the rectangle image. Here is the code of this program... Rectangle Image in Java       Introduction In this section, you will learn how to create rectangle 

Java Beginners

according to me its ok but is calculating wrong values in
according to me its ok but is calculating wrong values in   program to calculate roman numbers .....i.e roman number calculator import java.util....); System.out.println("enter the choice for calculating \n 1 for addition \n 2 

Java Code Examples

How to make a Rectangle type pdf
rectangle. The code of the program is given below... How to make a Rectangle type pdf       In this program we are going to tell you how we can 

Java Beginners

Method which returns area of circle - Java Beginners
of Circle : "+area); double perimeter = a.perimeterOfCircle(r...Method which returns area of circle  Need simple Java Method example that returns area of circle  Java Example CodeWith the help of given 

Java Code Examples

Java Swing: Draw rectangle on mouse click
Java Swing: Draw rectangle on mouse click In this tutorial, you will learn how to draw a rectangle on mouse click. Sometimes, there is a need of mouse clicks.... In the given example, we are going to draw a rectangle by clicking the mouse 

DMCA.com