Saturday, December 11, 2021

Average of Three Numbers Using Inheritance in Java

 A simple program to ask the user to give three numbers and then the program will compute the average of three numbers using Inheritance in Java programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.


My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Program Listing


import java.util.Scanner;


class A {


    int a, b, c, average;

    Scanner sc = new Scanner(System.in);


    void input() {

    System.out.println("\n");

    System.out.print("\tAverage of Three Numbers Using Inheritance in Java");

    System.out.println("\n");

        System.out.print("\tEnter three numbers:");

        a = sc.nextInt();

        b = sc.nextInt();

        c = sc.nextInt();

    }

}


class Main extends A {


    void Solve_Average() {

        average = (a + b + c)/3;

    }


    void display() {

        System.out.println();

        System.out.println("\tThe average is " + average + ".");

        System.out.println();

        System.out.println("\tEnd of Program");

        System.out.println();

    }


    public static void main(String args[]) {

        Main obj = new Main();

        obj.input();

        obj.Solve_Average();

        obj.display();

    }

}


No comments:

Post a Comment