ICSE Class 10 Computer Applications
Question 4 of 6
Solved 2012 Question Paper ICSE Class 10 Computer Applications — Question 4
Back to all questions 4
Question Question 7
Design a class to overload a function polygon() as follows:
- void polygon(int n, char ch) — with one integer and one character type argument to draw a filled square of side n using the character stored in ch.
- void polygon(int x, int y) — with two integer arguments that draws a filled rectangle of length x and breadth y, using the symbol '@'.
- void polygon() — with no argument that draws a filled triangle shown below:
Example:
- Input value of n=2, ch = 'O'
Output:
OO
OO - Input value of x = 2, y = 5
Output:
@@@@@
@@@@@ - Output:
*
**
***
public class KboatPolygon
{
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}
public void polygon(int x, int y) {
for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
System.out.print('@');
}
System.out.println();
}
}
public void polygon() {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}
public static void main(String args[]) {
KboatPolygon obj = new KboatPolygon();
obj.polygon(2, 'o');
System.out.println();
obj.polygon(2, 5);
System.out.println();
obj.polygon();
}
}