Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Desiree Luciane
Rectangle
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


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()


Advertisement
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
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
Advertisements
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
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
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
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.  By using draw() method of class
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... 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
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
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
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.  
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.... Now use parseInt for both length and width of the rectangle
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... of the rectangle.         Create Stored Procedure
Change the user input to integer
of a rectangle by using two classes named Rectangle and EnterValuesFromKeyboard...() calculates the area of a rectangle. In the second class which is also our main... will create a object of a Rectangle class. Now we ask the user to input two values
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...;Paint Round Rectangle");   frame.addWindowListener
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
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...;Canvas1 extends JPanel {   double p, q, width
Show Stroke with Effect
the stroke inside the rectangle: rectangle.setFrame(p + 90, q, width...; g2d.draw(rectangle);   rectangle.setFrame(p + 180, q... gradient pattern. The class Rectangle2D provides the rectangle figure
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...; class. This class represent an arc defined by a bounding rectangle and closure
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
Advertisements
 

 

 

DMCA.com