import java.io.*; class function { void square(int side,int b) { int perimeter;
ID: 3643132 • Letter: I
Question
import java.io.*;class function
{
void square(int side,int b)
{
int perimeter;
perimeter=4*side;
System.out.println("Perimeter of the Square is :"+perimeter);
}
void rectangle(int length,int width)
{
int perimeter;
perimeter=2*(length+width);
System.out.println("Perimeter of the Rectangle is :"+perimeter);
}
void circle(int radius,int b)
{
double perimeter;
perimeter=2*3.14*radius;
System.out.println("Perimeter of the Circle is :"+perimeter);
}
}
class polymorphism extends function
{
public static void main(String argv[])
{
try
{
DataInputStream in =new DataInputStream(System.in);
int a,b,choice;
polymorphism function=new polymorphism();
do
{
System.out.println(" * * M E N U * *");
System.out.println(" 1 : Square");
System.out.println(" 2 : Rectangle");
System.out.println(" 3 : Circle");
System.out.println(" 5 : Exit");
System.out.print(" Enter your choice :");
choice=Integer.parseInt(in.readLine());
switch(choice)
{
case 1:System.out.print("Enter any one side :");
a=Integer.parseInt(in.readLine());
function.square(a,0);
break;
case 2:System.out.print("Enter the length :");
a=Integer.parseInt(in.readLine());
System.out.print("Enter the width :");
b=Integer.parseInt(in.readLine());
function.rectangle(a,b);
break;
case 3:System.out.print("Enter the radius :");
a=Integer.parseInt(in.readLine());
function.circle(a,0);
break;
}
}while(choice!=5);
}catch(Exception e){}
}
}
Explanation / Answer
please rate
import javax.swing.JOptionPane;
class function {
String output;
void square(int side, int b) {
int perimeter;
perimeter = 4 * side;
output = "Perimeter of the Square is :" + perimeter;
JOptionPane.showMessageDialog(null, output, "Perimeter", JOptionPane.PLAIN_MESSAGE);
}
void rectangle(int length, int width) {
int perimeter;
perimeter = 2 * (length + width);
output = "Perimeter of the Rectangle is :" + perimeter;
JOptionPane.showMessageDialog(null, output, "Perimeter", JOptionPane.PLAIN_MESSAGE);
}
void circle(int radius, int b) {
double perimeter;
perimeter = 2 * 3.14 * radius;
output = "Perimeter of the Circle is :" + perimeter;
JOptionPane.showMessageDialog(null, output, "Perimeter", JOptionPane.PLAIN_MESSAGE);
}
}
class polymorphism extends function {
public static void main(String argv[]) {
try {
int a, b, choice;
polymorphism function = new polymorphism();
do {
String input;
String message = " * * M E N U * *" +
" 1 : Square" +
" 2 : Rectangle"+
" 3 : Circle" +
" 5 : Exit " +
" Enter your choice :";
choice = Integer.parseInt(JOptionPane.showInputDialog(null, message, "Perimeter", JOptionPane.QUESTION_MESSAGE));
switch (choice) {
case 1:
input = "Enter any one side : ";
a = Integer.parseInt(JOptionPane.showInputDialog(null, input, "Perimeter", JOptionPane.QUESTION_MESSAGE));
function.square(a, 0);
break;
case 2:
input = "Enter the length :";
a = Integer.parseInt(JOptionPane.showInputDialog(null, input, "Perimeter", JOptionPane.QUESTION_MESSAGE));
input = "Enter the width :";
b = Integer.parseInt(JOptionPane.showInputDialog(null, input, "Perimeter", JOptionPane.QUESTION_MESSAGE));
function.rectangle(a, b);
break;
case 3:
input = "Enter the radius :";
a = Integer.parseInt(JOptionPane.showInputDialog(null, input, "Perimeter", JOptionPane.QUESTION_MESSAGE));
function.circle(a, 0);
break;
}
} while (choice != 5);
} catch (Exception e) {
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.