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);}
}
}
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).
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);} } }
programming principle & algorithmekta gupta November 15, 2011 at 7:44 PM
hello sir can you help me?
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