Showing posts with label power of a number in java oop. Show all posts
Showing posts with label power of a number in java oop. Show all posts

Sunday, May 14, 2017

Power of a Number in Java OOP

Here is a simple program to demonstrate Object Oriented Programming in Java I called this program power of a number. It will ask the user to give base and exponent value and then our program will compute its power value. The code is written in object oriented programming format and easy to understand. Thank you.


My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

package demo;

import java.util.Scanner;


class check_power {
public double val_base,val_exponent;
public check_power(double base, double exponent)
{
val_base = base;
val_exponent = exponent;
}
public void set_power(double base, double exponent) {
val_base = base;
val_exponent = exponent;
}
public double get_base(double base) {
return(val_base);
}
public double get_exponent(double exponent) {
return(val_exponent);
}
public void displayResult()
{
 
            double results = Math.pow(val_base,val_exponent);
   System.out.println();
System.out.print("The Power value is " + results + ".");
   System.out.println("\n\n");
   System.out.print("===== END OF PROGRAM ======");
   System.out.println();
}
}


public class power_number {

public static void main(String[] args) {
   
int a=0,b=0;
 Scanner input = new Scanner(System.in);
 System.out.println();
     System.out.println("Power Number Solver in JAVA OOP");
     System.out.println();
     System.out.print("Give Base Value : ");
     a = input.nextInt();
     System.out.print("Give Exponent Value : ");
     b = input.nextInt();
   
     check_power solve = new check_power(a,b);
     
     solve.displayResult();
     input.close();

}

}