Search This Blog

UI/UX Design | Web Development | Mobile Application Development

Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us

Wednesday 19 October 2011

Java program to find area of a square and rectangle using abstract class (by noor diana fauzi)

import java.util.*;
class area
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
double base,height;
System.out.print ("\n\t Enter base of the Rectangle = ");
base=in.nextDouble();
System.out.print ("\n\t Enter height of the Rectangle = ");
height=in.nextDouble();

double side1,side2;
System.out.print ("\n\t Enter length of side1 of the Square = ");
side1=in.nextDouble();
System.out.print ("\n\t Enter length of side2 of the Square = ");
side2=in.nextDouble();

Rectangle ob1 = new Rectangle (base,height);
Square ob2 = new Square (side1,side2);
ob1.area();
ob2.area();
}
}


abstract class Shape
{
abstract void area();
}

class Rectangle extends Shape
{
double base,height,a;
Rectangle(double b, double l)
{
base=b;
height=l;
}
void area()
{
a=base*height;
System.out.println ("\n\t Area of Rectangle = "+a);
}
}

class Square extends Shape
{
double side1,side2,a;
Square (double s1, double s2)
{
side1=s1;
side2=s2;
}
void area()
{
a=side1*side2;
System.out.println ("\n\t Area of Square = "+a);
}
}

No comments:

Post a Comment

Share