Showing posts with label POSITIVE AND NEGATIVE NUMBER CHECKER IN JAVA OOP. Show all posts
Showing posts with label POSITIVE AND NEGATIVE NUMBER CHECKER IN JAVA OOP. Show all posts

Saturday, May 13, 2017

Positive and Negative Number Checker in Java OOP Using Setter's and Getter's

I very simple program in Java that will ask the user to give a number and then our program will check and determine if the the given number is a positive or negative number using getters and setters in Java. The code is very short 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_value {
public int val_number;
public check_value(int a)
{
val_number = a;
}
public void setCheck_value(int a) {
val_number = a;
}
public int getCheck_value() {
return(val_number);
}
public void displayResult()
{
if (val_number >=0) {
   System.out.println();
System.out.print("The given number " + val_number + " is a Positive Number.");
   System.out.println("\n\n");
   System.out.print("===== END OF PROGRAM ======");
   System.out.println();
}
else {
System.out.println();
    System.out.print("The given number " + val_number + " is a Negative Number.");
System.out.println("\n\n");
System.out.print("===== END OF PROGRAM ======");
System.out.println();
}
}
}

public class Positive_Negative_Numbers {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int b=0;
 System.out.println();
     System.out.println("POSITIVE AND NEGATIVE NUMBER CHECKER IN JAVA OOP");
     System.out.println();
     System.out.print("Give a Number : ");
     b = input.nextInt();
   
    check_value num_values = new check_value(b);
 num_values.displayResult();
    
    
     input.close();
}

}