Skip to main content

FEATURED POST

Why the World is Running Out of Computers

Question: Develop an abstract class “GeometricObject” which will have two variables colourand weight. It would have constructor function for setting the colour as “white” and the weight as 1.0 as default values. The class should have methods getColour() and getWeight() to return the colour and weight values to the caller. The class should have two abstract methods findArea() and findCircumference(). Write a subclass for “GeometricObject” called “Triangle” which will be able to calculate area and circumference for a triangle.

Question: Develop an abstract class “GeometricObject” which will have two variables colourand weight. It would have constructor function for setting the colour as “white” and the weight as 1.0 as default values. The class should have methods getColour() and getWeight() to return the colour and weight values to the caller. The class should have two abstract methods findArea() and findCircumference().  Write a subclass for “GeometricObject” called “Triangle” which will be able to calculate area and circumference for a triangle.


import java.util.*;

import java.math.*;

abstract class GeometricObject

{

            String colour;

            double weight;

            public GeometricObject()

            {

                        colour="White";

                        weight=1.0;

            }

            public String getColour()

            {

                        return colour;

            }

            public Double getWeight()

            {

                        return weight;

            }

            abstract void findArea(double x,doubley,double z);

            abstract void findCircum(double x,doubley,double z);

}

class Triangle extends GeometricObject

{

            double height,base,s1,s2,s3;

            public void findArea(double x,doubley,double z)

            {

                        double area,p;

                        s1=x;

                        s2=y;

                        s3=z;

                        p=(s1+s2+s3)/2;

                        area=Math.sqrt((p*(p-s1)*(p-s2)*(p-s3)));

                        System.out.println("The area of triangle: "+area);

            }

            public void findCircum(double x,doubley,double z)

            {

                        s1=x;

                        s2=y;

                        s3=z;

                        double circum=s1+s2+s3;

                        System.out.println("The circumference of triangle: "+circum);

            }

}

class Geometry

{

            public static void main(String arg[])

            {

                        Scanner sc=new Scanner(System.in);

                        double c,d,e;

                        System.out.print("Enter side1 of triangle:");

                        c=sc.nextDouble();

                        System.out.print("Enter side2 of triangle:");

                        d=sc.nextDouble();

                        System.out.print("Enter side3 of triangle:");

                        e=sc.nextDouble();

                        Triangle t=new Triangle();

                        t.findArea(c,d,e);

                        t.findCircum(c,d,e);

                        GeometricObject go=t;

                        System.out.println("The colour of triangle is:"+t.getColour());

                        System.out.println("The weight of triangle is:"+t.getWeight());

            }

}
OUTPUT:

Keywords:

How to recover the classnotfoundexception in Java?
What are the top most requirements or expectations of client for develop Java web application?
Java program question paper in 2020

Comments

Popular Posts

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes:  Ø “Car” that inherits “Vehicle” and also stores number of passengers.  Ø “Truck” that inherits “Vehicle” and also stores the load limit.  Write a main() function to create objects of these classes and display all the information about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and display “faster” or “slower” if Car is faster or slower than Truck. import java.util.*; class Vehicle{   int wheels;   double speed; } class Car extends Vehicle{   int pass;   void input(){    Scanner sc=new Scanner(System.in); System.out.println("Enter the car's details:\nNo. of wheels:");    wheels=sc.nextInt(); System.out.println("Speed of Car(Km/hr):");    speed=sc.nextDouble(); System.out.println("No. of passengers:");   ...

Question: Write a java program that implements bank transactions using user defined exception.

Question: Write a java program that implements bank transactions using user defined exception. import java.util.*; class UDE{     public static void main(String ts7[]) throws MinimumBal {         Scanner sc= new Scanner(System.in);         double bal; System.out.println("Enter current balance:"); bal=sc.nextDouble(); System.out.println("Enter amount to withdrawal");         int n = sc.nextInt();         try {             if (bal<n)                   throw new MinimumBal("Account ae taka nei bhai !\nYour Current balance is "+bal);             else      System.out.print...

How to view hidden files in computer?

It is very easy to see hidden files or folders in a Windows computer. In this answer, I will show you how to hidden files as well as how to hide a file or folder. So let's understand step-by-step How to hide a file or folder: Step 1 : Select any file (or folder) you want to hide by clicking once on the icon of that folder.                                                                     Safe Online - सेफ ऑनलाइन Step 2: Now right-click it on the folder and click on 'Properties' at the bottom of the menu which is open. To open the properties of a folder, you can also select the folder and use the shortcut Alt + Enter.                                                 ...