-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion24.java
More file actions
33 lines (30 loc) · 820 Bytes
/
Question24.java
File metadata and controls
33 lines (30 loc) · 820 Bytes
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
import java.util.Scanner;
/* program to declare class Rectangle with data members
length and breadth member functions Input, Output
and CalcArea */
class Rectangle {
float length = 10, breadth = 5;
void Input () {
Scanner input = new Scanner (System.in);
System.out.print ("Enter length: ");
length = input.nextFloat ();
System.out.print ("Enter breadth: ");
breadth = input.nextFloat ();
}
void Output () {
System.out.println ("Length of rectangle: " + length);
System.out.println ("Breadth of rectangle: " + breadth);
float area = CalcArea ();
System.out.println ("Area of rectangle: " + area);
}
float CalcArea () {
return (length * breadth);
}
}
class Question24 {
public static void main (String[] args) {
Rectangle rect = new Rectangle ();
rect.Input ();
rect.Output ();
}
}