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();
}

}

Tuesday, May 9, 2017

Student Information Using Inheritance in Java

Here is a very simple program that I wrote using Java as my programming language that demonstrate how to use inheritance. The program will display student information on the screen. I hope you will learn something out of it.  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;


class Student {
String name="Mario Chua";
String course="Bachelor of Science in Business Management";
int age=17;
}

public class inheritance extends Student {
String school="Manila State University";
double tuition= 45600.51;

public static void main(String[] args) {
inheritance studs = new inheritance();
System.out.println();
        System.out.println("Student Information Using Inheritance in Java");
        System.out.println();
System.out.println("Student Name : " + studs.name);
System.out.println("Course       : " + studs.course);
System.out.println("Age          : " + studs.age);
System.out.println("School       : " + studs.school);
System.out.println("Tuition Fee  : Php " + studs.tuition);
}

}






Monday, May 8, 2017

Payroll Program in Java Using Getters and Setters


In this article I would like to share with you a simple payroll program that I wrote using Java it is an object oriented programming style with the use of getters and setters a concept of encapsulation and the creation of object. The code is very simple and easy to understand. I hope you will find my work useful. 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;

public class Payroll {
int rate_per_day=0, no_of_days=0,emp_id=0;
String employees_name;
private int getRate_per_day() {
return rate_per_day;
}

private int getNo_of_days() {
return no_of_days;
}

private int getEmp_id() {
return emp_id;
}

private String getEmployees_name() {
return employees_name;
}

private void setRate_per_day(int rate_per_day) {
this.rate_per_day = rate_per_day;
}

private void setNo_of_days(int no_of_days) {
this.no_of_days = no_of_days;
}

private void setEmp_id(int emp_id) {
this.emp_id = emp_id;
}

private void setEmployees_name(String employees_name) {
this.employees_name = employees_name;
}

public int process_Salary() {
return(no_of_days * rate_per_day);
}
public void display_Records(){
   System.out.println();
         System.out.println("===== DISPLAY RESULTS =====");
   System.out.println();
    System.out.println("Employee's ID         : "  + getEmp_id());
    System.out.println("Employee's Name       : "  + getEmployees_name());
    System.out.println("Number of Day's Work  : "  + getNo_of_days());
    System.out.println("Rate Per Day          :  " + getRate_per_day());
       System.out.println();
       System.out.println("Gross Salary          : Php " + process_Salary());
       System.out.println();
       System.out.print("\t END OF PROGRAM");
}

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
 
  Payroll emp = new Payroll();
  
      System.out.println();
      System.out.println("Payroll Program in Java Using Getters and Setters");
      System.out.println();
      System.out.print(" Employee's ID Number : ");
      emp.emp_id = input.nextInt();
      input.nextLine();
      System.out.print(" Employee's Name : ");
      emp.employees_name = input.nextLine();
       System.out.print(" Employee's Daily Rate : ");
      emp.rate_per_day = input.nextInt();
       System.out.print(" Number of Day's Work : ");
      emp.no_of_days = input.nextInt();
  
      emp.setEmp_id(emp.emp_id);
      emp.setEmployees_name(emp.employees_name);
      emp.setNo_of_days(emp.no_of_days);
      emp.setRate_per_day(emp.rate_per_day);
      
      emp.getEmp_id();
      emp.getEmployees_name();
      emp.getNo_of_days();
      emp.getRate_per_day();
      
       emp.display_Records();
  
input.close();

}

}



Sunday, May 7, 2017

Constructor in Java

Here is a very simple implementation of constructor in Java. Constructor is very important in creating an object in object oriented programming 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;

class Car {
 void Model_Car() {
System.out.println();
System.out.println("Constructor Demo in Java");
System.out.println();
System.out.println("I am driving a Toyota Corolla Model 2017.");
  }
}

public class Constructor {

public static void main(String[] args) {
    
    Car Toyota = new Car();
       
    Toyota.Model_Car();

}

}

Addition of Five Numbers in Java Using Getters and Setters

Here is a sample program that I wrote using Java to ask the user to give five numbers and then our program will compute for the total sum of the five numbers given by our user. I'm using object oriented approach and using getters and setters in Java. I hope you will find my work useful. I am using Eclipse Neon as my text editor and Jave 8 as my version of Java. 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

Addition.java

package demo;

import java.util.Scanner;

public class Addition {

public int a=0,b=0,c=0,d=0,e=0;
private int getA() {
return a;
}
private void setA(int a) {
this.a = a;
}
private int getB() {
return b;
}
private void setB(int b) {
this.b = b;
}
private int getC() {
return c;
}
private void setC(int c) {
this.c = c;
}
private int getD() {
return d;
}
private void setD(int d) {
this.d = d;
}
private int getE() {
return e;
}
private void setE(int e) {
this.e = e;
}
public int getResults(){
return(a+b+c+d+e);
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Addition val = new Addition(); 
  
       System.out.println();
       System.out.println("Addition of Five Numbers in Java Using Getters and Setters");
       System.out.println();
       System.out.print("Enter first value : ");
       val.a = input.nextInt();
       System.out.print("Enter second value : ");
       val.b = input.nextInt();
       System.out.print("Enter third value : ");
       val.c = input.nextInt();
       System.out.print("Enter fourth value : ");
       val.d = input.nextInt();
       System.out.print("Enter fifth value : ");
       val.e = input.nextInt();
   val.setA(val.a);
   val.setB(val.b);
   val.setC(val.c);
   val.setD(val.d);
   val.setE(val.e);
     
   val.getA();
   val.getB();
   val.getC();
   val.getD();
   val.getE();
   
   val.getResults();
   
 System.out.println();
        System.out.print("The total sum is " + val.getResults() + ".");
        System.out.println("\n");
        System.out.print("\t END OF PROGRAM");
        input.close();
}

}



Saturday, May 6, 2017

Odd and Even Number Checker in Object Oriented Programming

In this article I would like to share with you a sample program that will ask the user a number and then our program will check and determine if the given number is an even or odd number using object oriented programming approach. The code is very simple 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

odd_even.java

package demo;

import java.util.Scanner;


class odd_even_value {
int val_1=0;
}

   class odd_even {

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 odd_even_value a = new odd_even_value();
 
 System.out.println();
     System.out.println("ODD AND EVEN NUMBER CHECKER IN JAVA OOP");
     System.out.println();
     System.out.print("Enter a Number : ");
     a.val_1 = input.nextInt();
     
    if ( a.val_1 % 2 == 0 ) {
     System.out.println();
         System.out.println("You entered an EVEN number.");
     }
      else {
     System.out.println();
         System.out.println("You entered an ODD number.");
      }
    input.close();
}

}

Product of Two Numbers in Java Using Object Oriented Programming

In this article I would like to share with you a program that I wrote in Java to accept two numbers and then our program will compute the product of the two given numbers using object oriented programming approach in Java. The code is very short and easy to understand.

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


product.java


package demo;

import java.util.Scanner;


class product_value {
int val_1=0,val_2=0;
}

public class product {

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 int product=0;
 
 product_value a = new product_value();
 product_value b = new product_value();
 
 System.out.println();
     System.out.println("PRODUCT OF TWO NUMBERS IN JAVA OOP");
     System.out.println();
     System.out.print("Enter First Value : ");
     a.val_1 = input.nextInt();
     
     System.out.print("Enter Second Value : ");
     b.val_2 = input.nextInt();
     
     product = (a.val_1 * b.val_2);
      
     System.out.println();
     System.out.print("The product of " + a.val_1 + " and " + b.val_2 + " is " + product + ".");
     input.close();
}

}