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 constructor, toString(), getWidth(), getHeight(), Println()

View Answers

January 14, 2011 at 12:27 PM

Hi Friend,

Try the following code:

class Rectangle{
   private int width;
   private int height;
   int x;
   int y;
   Rectangle(int newx, int newy, int newwidth, int newheight) {
      this.x=newx;
      this.y=newy;
      this.width=newwidth;
      this.height=newheight;
   }
   public int getWidth() {
       return width; 
   }
   public int getHeight() {
       return height;
   }
   public int getX() {
       return x;
   }
   public int getY() {
       return y;
   }
   void Println() {
       System.out.println(toString());
   }

   public String toString(){
   return "Rectangle(" + getX() + ", " + getY() +"), width " + getWidth() + ", height " + getHeight();
   }
   public static void main(String[]args){
       Rectangle Rectangle1=new Rectangle(15,25,53,15);
       Rectangle1.Println();
       Rectangle Rectangle2=new Rectangle(0,12,60,47);
       Rectangle2.Println();
   }
}

Thanks









Related Tutorials/Questions & Answers:
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
ModuleNotFoundError: No module named 'rectangle'
ModuleNotFoundError: No module named 'rectangle'  Hi, My Python... 'rectangle' How to remove the ModuleNotFoundError: No module named 'rectangle' error? Thanks   Hi, In your python environment you
Advertisements
plotting of points inside a rectangle
plotting of points inside a rectangle  I want to plot various points inside a rectangle such that any two points are at a distance of at least 3... example ,if I have a Rectangle of 20m by 14m then one possible placement of points
print rectangle pattern in java
print rectangle pattern in java  * * * * * * * how to generate this pattern in java??   Hi friend try this code may this will helpful for you public class PrintRectangle { public static void main
ModuleNotFoundError: No module named 'rectangle-overlap'
ModuleNotFoundError: No module named 'rectangle-overlap'  Hi, My... named 'rectangle-overlap' How to remove the ModuleNotFoundError: No module named 'rectangle-overlap' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'rectangle-packer'
ModuleNotFoundError: No module named 'rectangle-packer'  Hi, My... named 'rectangle-packer' How to remove the ModuleNotFoundError: No module named 'rectangle-packer' error? Thanks   Hi, In your
print a rectangle - Java Beginners
print a rectangle  how do I print a rectangleof stars in java using simple while loop?Assuming that the length n width of the rectangle is given.  Hi friend, I am sending running code. import java.io.
By using Applet display a circle in a rectangle
By using Applet display a circle in a rectangle  Write a java applet to display a circle in a rectangle
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
drawing rectangle in java/Creating a draw rectangle filled with black color function in Java for a grid
drawing rectangle in java/Creating a draw rectangle filled with black color function in Java for a grid  drawing rectangle in java/Creating a draw rectangle (filled with black color) function in Java for a grid
print rectangle triangle with ?*? using loops
print rectangle triangle with ?*? using loops   * * * * * * i want print like this.what is the code?   import java.lang.*; class Traingles { public static void main(String args[]) { for(int i=1;i<=5
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
Rectangle Canvas MIDlet Example
Rectangle Canvas MIDlet Example   ... of rectangle in J2ME. We have created CanvasRectangle class in this example that extends to the Canvas class to draw the given types of rectangle. In this figure
Draw Ellipse in Rectangle
Draw Ellipse in Rectangle     ... the rectangle. To draw an Ellipse inside the rectangle, we have defined two classes... a rectangle and a circle respectively. ADS_TO_REPLACE_1 By using draw() method
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
How to make a Rectangle type pdf
How to make a Rectangle type pdf   ... make a pdf file in the rectangle shape irrespective of the fact whether... is created and it is of type rectangle. The code of the program is given below
J2ME Draw Triangle, Rectangle, Arc, Line Round Rectangle Example
J2ME Draw Triangle, Rectangle, Arc, Line Round Rectangle Example... tutorial, we are going to describe how to draw a triangle, rectangle, arc, line or a round rectangle in one small application. Although we have already explained
Rectangle Image in Java
Rectangle Image in Java       Introduction In this section, you will learn how to create rectangle... , rectangle Drawing , curve drawing and Circle. All types of Geometry classes parts
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
four rectangle/image of the shape of the button.then Draw these on some x and y co-ordinated in j2me then how to draw ?
four rectangle/image of the shape of the button.then Draw these on some x and y co-ordinated in j2me then how to draw ?  hi, i have button use in j2me. then use a imaga for lick a button. then process is four rectangle/image
PHP GD Draw Rectangle
Draw Rectangle in J2ME
Draw Rectangle in J2ME      ... are used to draw a rectangle using J2ME language: g.setColor (255, ... it to create rectangle and to set the color of canvas and draw line or box.ADS
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... and perimeter of a rectangle in java. Code Description : Using this example
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
Write a program for calculating area and perimeter of a rectangle
Write a program for calculating area and perimeter of a rectangle... of a rectangle.  First of all create a class named RecArea under Java.io... it in the buffer class. Now use parseInt for both length and width of the rectangle
Change the user input to integer
a area of a rectangle by using two classes named Rectangle... method calculate() calculates the area of a rectangle. In the second class which... this method we will create a object of a Rectangle class. Now we ask the user
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
Another Example of Gradient Paint
corner rectangle. A gradient is like a colored strip. It is created by specifying.... The class RoundRectangle2D defines a rectangle with rounded corners...;new JFrame("Paint Round Rectangle");   
How to design a text button.
How to design a text button.       With this tutorial you will be able to learn a design of the text button, mostly we use simple buttons of circle and rectangle shape
Show Stroke with Effect
gradient pattern. The class Rectangle2D provides the rectangle figure.ADS_TO_REPLACE_1 Following code shows the simple rectangle filled with color gradient pattern: g2d.setPaint(gradientPaint); g2d.fill(rectangle
Mouse Drag and Drop
a rectangle. This rectangle has been shown on the frame. When you drag the rectangle and move, a number of figures will be drawn connected to each other...;double p, q, width, height;   int p1, q1
Adapters Example
been used as an anonymous inner class to draw a rectangle within an applet... click of the mouse from top left corner, we get a rectangle on the release
Arcs Drawing In Java
superclass for all objects that store a 2D arc defined by a bounding rectangle... rectangle and closure type. Here is the code of this program:ADS_TO_REPLACE_2
graphics - Java Beginners
graphics  In java-graphics.. I want to draw a rectangle and resize that rectangle(small,big) ..by using mouse cursors
Program - Java Beginners
Program   calculates the area of rectangle which make use... code: class Rectangle{ int length,breadth; Rectangle(int length,int...){ Rectangle rectangle=new Rectangle(5,6); int area
applet Question
applet Question  Write a java applet to display a circle in a rectangle
applet question
applet question  Write a java applet to display a rectangle inside a circle
c++
c++  write a programme that calculates the area and circumference of a rectangle
core java - Applet
core java  how can draw rectangle in applet. when i pressed in mouse button the rectangle's size will also increase
Help
Help  Description: Display 3 red rectangles as indicated. Use 3 different rectangle objects, one for each rectangle. Dimensions of each rectangle: 40 x 40 pixels Starting position: The first rectangleââ?¬â?¢s top left hand
MEANING OF THe CODE IN BOLD LETTERS
MEANING OF THe CODE IN BOLD LETTERS  public static void main(sting args[]) { shape s[] = {new circle(),new rectangle()}; } //HERE SHAPE RECTANGLE AND CIRCLE ARE THREE CLASSES WHICH ARE DEFINED EARLIER IN THE PROGRAM
How to draw a television
with this example. New File: Take a new file with required size. Rectangle Shape: First draw a Rectangle shape with black color by using Rectangle tool (U... Rectangle Shape: Choose "d3d3d3" color and make a rectangle shape in side
menu driven programme
menu driven programme   calculate the area of circle, square, rectangle in menu driven programme in java
java Question
java Question  Design a class named rectangle to represent a rectangle. The Class contain: * Two double data fielda named width and heigth.... the default color white. * A no-arg constructor that creates a default rectangle
java Question
java Question  Design a class named rectangle to represent a rectangle. The Class contain: Two double data fielda named width and heigth.... the default color white. A no-arg constructor that creates a default rectangle
How to make a navigation bar
: Take a new file with any size. Rectangle Shape: Choose Rectangle tool (U key) and this color "b2afaf" then draw a rectangle shape.ADS_TO_REPLACE_1.... ADS_TO_REPLACE_2 Your image will look like this. Rectangle Shape: Choose
?
. Radius for a circle, length and height for a rectangle, etc...), square(s), rectangle(r), triangle (t
private method
it in another class in a same package? my source code: class rectangle{ int...(String args[]){ rectangle r=new rectangle(); r.show(5,6); int area=r.calculate(); System.out.println("this Area of rectangle is"+area
class - Java Beginners
display(). Class Rectangle should implement the abstract class shapes Interface Shapes has abstract methods-area(),display(). Classes Rectangle and Triangle should... perimeter inherits from the Shapes interface. (). Classes Rectangle and Square should
class - Java Beginners
display(). Class Rectangle should implement the abstract class shapes Interface Shapes has abstract methods-area(),display(). Classes Rectangle and Triangle should... perimeter inherits from the Shapes interface. (). Classes Rectangle and Square should

Ads