Education Game

5:42 AM | , , , , ,

Hi.. friend. I just wanna share you an education game about music theory. If you're an Indonesian, i'm sure that you can understand it. But, I promise that I will make an English version soon. This is the game. Let's play ... :D


Read More

My Geometric Part 1

6:04 AM | , , , ,

Hey guys... :) for this time I want to share my project. I call it MyGeometric. I will show you how to build a concept about OOP in java. Okay guys, those are the code.
(Rectangle.java)
package Geo1;
public class Rectangle {
    protected double Long,Width;
    public void setSize(double l,double w){
        Long=l;
        Width=w;
    }
    public double getWideArea(){
        return Long*Width;
    }
    public double getSurroundArea(){
        return 2*(Long+Width);
    }
    public void printObject(){
        System.out.println("Long\t: "+Long);
        System.out.println("Width\t: "+Width);
        System.out.println("Wide\t: "+getWideArea());
        System.out.println("Surround\t: "+getSurroundArea());
    }


(Square.java)
 package Geo1;
public class Square extends Rectangle {
    protected double Side;
    public void setSize(double s){
        super.setSize(s, s);
        Side=s;
    }
    @Override
    public void printObject(){
        System.out.println("Side\t: "+Side);
        System.out.println("Wide\t: "+getWideArea());
        System.out.println("Surround\t: "+getSurroundArea());
    }
}


(MyGeometric.java)

 package mygeometric;
import Geo1.*;
import java.util.Scanner;
class Quadrangle extends Square{
    private String ObjName;
    private int ObjType;
    Scanner s=new Scanner(System.in);
    public void setObject(String name,int t){
        ObjType=t;
        switch (ObjType){
            case 1:
                double l,w;
                System.out.print("Long : ");
                l=s.nextDouble();
                System.out.print("Width : ");
                w=s.nextDouble();
                setSize(l, w);
                ObjName="Rectangle " + name;
                break;
            case 2:
                double sd;
                System.out.print("Side : ");
                sd=s.nextDouble();
                setSize(sd);
                ObjName="Square " + name;
                break;
        }       
    }
    @Override
    public void printObject(){
        System.out.println("Data of " + ObjName );
        if(ObjType==1){
            System.out.println("Long\t: "+Long);
            System.out.println("Width\t: "+Width);
            System.out.println("Wide\t: "+getWideArea());
            System.out.println("Surround: "+getSurroundArea());
        }else if(ObjType==2){
            System.out.println("Side\t: "+Side);
            System.out.println("Wide\t: "+getWideArea());
            System.out.println("Surround: "+getSurroundArea());
        }
        System.out.println();
    }
}
public class MyGeometric {   
    int Choice=0;
    Quadrangle Obj[]=new Quadrangle[10];
    String alfabet="ABCDEFGHIJ";
    int n;
    void Menu(){
        System.out.println("============= Menu =============");
        System.out.println("Press 1 to Create a Rectangle");
        System.out.println("Press 2 to Create a Square");
        System.out.println("Press 3 to Print All Object");       
        System.out.println("Press 4 to Quit");
        System.out.println("================================");       
        System.out.println("nb. You may only create maximum 10 Objects");       
        System.out.println();
        System.out.print("Your Choice : ");
    }
    public static void main(String[] args) {
        MyGeometric mg=new MyGeometric();
        Scanner s=new Scanner(System.in);
        String nm;
        do{
            mg.Menu();
            try{
                mg.Choice=s.nextInt();
                switch(mg.Choice){
                    case 1:
                        mg.Obj[mg.n]=new Quadrangle();
                        mg.Obj[mg.n].setObject(String.valueOf(mg.alfabet.charAt(mg.n)), mg.Choice);
                        mg.n++;
                        break;
                    case 2:
                        mg.Obj[mg.n]=new Quadrangle();
                        mg.Obj[mg.n].setObject(String.valueOf(mg.alfabet.charAt(mg.n)), mg.Choice);
                        mg.n++;
                        break; 
                    case 3:
                        for (int i = 0; i < mg.n; i++) {
                            mg.Obj[i].printObject();
                        }
                        break;
                }
            }catch(Exception e){
                System.out.println(e.toString());
                System.out.println("Your choice is wrong, please try again");
                mg.Choice=0;
            }
            System.out.println();
        }while(mg.Choice!=4);
        System.out.println("Thank You");
    }
}

      Okay guys I will tell more about my project. As like as you know that the Square object is a Rectangle object that has the same side. So we can identify the Square as a child of Rectangle. This concept was called by Inheritance. So we can get the wide area of a square by using the method getWideArea() in Rectangle class.As well the surround area too.
       May be we can find a wide area of square by square of side length. But in OOP concept we can reuse attribut and method of a class which we have previously made.
You can copy paste the source code free and if you will to download full source code you can go to link below and please give me a comment  if you are a  good reader.
Read More

Perceptron Algorithm

12:04 PM | , ,

Hi… guys :) For this time I want to tell you about Perceptron Algorithms to solve an Artificial Neural Network (ANN) problem. For example we will make an ANN model to know the XOR statement target as below.
Input
Target
X1
X2
t
1
1
-1
1
0
1
0
1
1
0
0
-1

We need to finish it with α=0.6 , b=0.2 , w1 (weight of x1) = 0.3 , w2= - 0.2 , and θ=0.7
The formula of Perceptron Algorithms as follows:
·         θ is a threshold of activation function to calculating the output of Perceptron Algorithms.
·         Xi is input of ANN
·         t  is the target of ANN
·         wi (w1,w2,…,wn) is weight of input Xi
·         b is bias of input an ANN
·         net = S xiwi + b
·         α is learning rate of Perceptron
·         Activation Function   y=f(net)  =  1 , if  net > θ ;  0 , if  - θ ≤ net ≤ θ ;  -1 , if  net ≤ - θ
·         Dwi = α t xi
·         Db = α t
·         wi (new) = wi (old) + Dwi
·         b (new) = b (old) + Db

Okay , then we try to calculate the Perceptron Algorithms as follows  :

The 1st  Iteration
Input
Target
net
Output
f(net)
Change of weight
weight
X1
X2
t
Dw1
Dw2
Db
w1
w2
b
1
1
-1
-0.3
-1
0
0
0
0.3
-0.2
0.2
1
0
1
0.5
0
0.6
0
0.6
0.9
-0.2
0.8
0
1
1
0.6
0
0
0.6
0.6
0.9
0.4
1.4
0
0
-1
-1.4
-1
0
0
0
0.9
0.4
1.4

Note : if  t = y then fill the value of  Dwi and Db  by Nol

The 2nd   Iteration
Input
Target
net
Output
f(net)
Change of weight
weight
X1
X2
t
Dw1
Dw2
Db
w1
w2
b
1
1
-1
-2.7
-1
0
0
0
0.9
0.4
1.4
1
0
1
2.3
1
0
0
0
0.9
0.4
1.4
0
1
1
1.8
1
0
0
0
0.9
0.4
1.4
0
0
-1
-1.4
-1
0
0
0
0.9
0.4
1.4

so the conclusion is the Perceptron algorithm can solve ANN Problem (XOR Statement) with  α=0.6 , b=0.2 , w1 (weight of x1) = 0.3 , w2= - 0.2 , and θ=0.7 on the 2nd   Iteration.
Read More