-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion28.java
More file actions
51 lines (48 loc) · 1.65 KB
/
Question28.java
File metadata and controls
51 lines (48 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
// program to demonstrate concept of this
class Rectangle {
float x, y, width, height;
float area;
Rectangle () { this (0, 0, 10, 10); }
Rectangle (float width, float height) { this (0, 0, width, height); }
Rectangle (float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
float Area () {
area = width * height;
return (area); }
void display () {
System.out.println ("Position of rectangle: (" + x + ", " + y + ")");
System.out.println ("Area of rectangle: " + Area () + " sq. units");
}
}
public class Question28 {
public static void main (String[] args) {
float xpos, ypos, width, height;
Scanner input = new Scanner (System.in);
System.out.println ("Rectangle1: ");
Rectangle r1 = new Rectangle ();
r1.display ();
System.out.println ("Rectangle2: ");
System.out.print ("Enter width: ");
width = input.nextFloat ();
System.out.print ("Enter height: ");
height = input.nextFloat ();
Rectangle r2 = new Rectangle (width, height);
r2.display ();
System.out.println ("Rectangle3: ");
System.out.print ("Enter x-position: ");
xpos = input.nextFloat ();
System.out.print ("Enter y-position: ");
ypos = input.nextFloat ();
System.out.print ("Enter width: ");
width = input.nextFloat ();
System.out.print ("Enter height: ");
height = input.nextFloat ();
Rectangle r3 = new Rectangle (xpos, ypos, width, height);
r3.display ();
}
}