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




Have Programming Question? Ask it here!
 
 
 


Desiree Luciane
Rectangle
1 Answer(s)      3 years and 6 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
Methods - Example
Java NotesMethods - Example Example This example shows a simple method that computes the area of a rectangle: 1. public static int computeArea(int width, int height) { 2. int area; // This is a local variable 3
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
c++
c++  write a programme that calculates the area and circumference of a rectangle
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
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... and Emboss and use both settings. Rectangle Shape: Choose "d3d3d3
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. Stroke: Go... will look like this. Rectangle Shape: Choose Rectangle tool and make a shape
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
?
. Radius for a circle, length and height for a rectangle, etc...), square(s), rectangle(r), triangle (t
pls answer these question
to input the length and width of a rectangle. Then calculate and prints the rectangle‚??s area and perimeter.   import java.io.*; class rectangle...("Area of Rectangle: "+area); System.out.println("Perimeter of Rectangle
method overriding in java
method overriding in java  program to compute area of square,rectangle,triangle,circle and volume of sphere,cylinder and perimeter of a cube using method overriding
method overriding in java
method overriding in java  program to compute area of square,rectangle,triangle,circle and volume of sphere,cylinder and perimeter of a cube using method overriding
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
 

 

 

DMCA.com