Implementation Array Of Java

10:31 PM | , , ,


Hemm... :-) Do you want to know the java program that i made on the first time. I wrote them when I was in the first semester at STMIK Akakom Yogyakarta. They was a simple problem. The problem is save the phone number with an array on java. The program can add the number, edit phone data and remove data from array. 

I am so sorry if I wrote the program with Indonesian language. But I will translate to you one by one. So don't worry about it.

Source code java phonebook

package responsialgo; // this is the package name
import java.util.Scanner;  // importing java.util.Scanner to use the object scanner that can read input from a keyboard
class PhoneBook{ // the class name was PhoneBook


// the block of attribut class have nama (name) , nomor (phone number) , jml (counter how many number stored


public String nama[]=new String [50];
public String nomor[]=new String [50];
public int jml=0; 



//end of block


//this block is method for adding number into array data


public void tambahNomor(){
        Scanner masuk=new Scanner(System.in);
        if(jml<50){ // if  array number is least than 50 then we can add the phone number

        
           //this block read input from keyboard (Name and Phone Number)

            System.out.println("Silahkan masukkan :");
            System.out.print("Nama =");
            nama[jml]=masuk.nextLine();
            System.out.print("Nomor =");
            nomor[jml]=masuk.nextLine();


            //increment the counter

            jml++;


        }else{ //if number of array is not least then 50 then show the message that Phonebook was full

            System.out.println("Phone book sudah penuh!!!");
        }
    }
 //end of block


  //this block is method for show phonebook list . I use looping with For Statement to get array elemen

    public void tampilDaftar(){
        System.out.println("No. Nama  ( Nomor )");
        for(int i=0;i<jml;i++){
            System.out.println( (i+1) + " " + nama[i] + " (" + nomor[i] + ")");
        }
    }
  //end of block


 //this block is method for removing number from array data
    public void hapusDaftar(){
        Scanner masuk=new Scanner(System.in);


 //input index of data which will be removed

        System.out.print("Masukkan indeks phonebook yang akan dihapus = ");
        int indeks=masuk.nextInt()-1;


//searching for data which will deleted with comparing index of data, after that change index of data sliding data before that.

        if(jml>0){
            for(int i=indeks;i<jml;i++){
                nama[i]=nama[i+1];
                nomor[i]=nomor[i+1];
            }
            nama[jml-1]="";
            nomor[jml-1]="";
            jml--;
        }else{
            System.out.println("Tidak ada data yang dihapus!!!");
        }
    }
//end of block


 //this block is method for updating number from array data
    public void gantiNomor(){
          Scanner masuk=new Scanner(System.in); 


//input index of data which will be updated
          System.out.print("Masukkan indeks phonebook yang akan diubah = ");
          int indeks=masuk.nextInt()-1; 


//replace data with a new phone number

          System.out.print("Masukkan nomor baru = ");
          nomor[indeks]=masuk.next();
      }
 } 
//end of block


//The main class to run program
public class DaftarPhoneBook {
         public static void main(String[] args) {
                int pil=0; 
               
               //Create an object HP from class PhoneBook
                PhoneBook HP=new PhoneBook();
                Scanner masuk=new Scanner(System.in);
                System.out.println("PHONEBOOK");
                System.out.println("by Alir Retno");
                System.out.println("====================");
             
                 //Creating a menu to acces program
                System.out.println("Menu :");
                System.out.println("1. Tambah Nomor");  //1. Add Number
                System.out.println("2. Tampilkan Daftar"); //2. Show List
                System.out.println("3. Ganti Nomor"); //3. Update Number
                System.out.println("4. Hapus Nomor"); //4. Delete Number
                System.out.println("5. Keluar"); //5. Exit


               //This is a block try & catch , for handling an exception if user give an error input
                try { 


                      //While user does'nt choose to exit do this looping
                      do {
                            System.out.print("Pilih :");
                            pil=masuk.nextInt(); //input the choice

                            if(pil==1){
                                 HP.tambahNomor();//if user chose 1, please add number

                            }else if(pil==2){
                                 HP.tampilDaftar(); //if user chose 2, please show the list

                           }else if(pil==3){
                                HP.gantiNomor(); //if user chose 3, please update number
                          }else if(pil==4){
                               HP.hapusDaftar(); //if user chose 4, please delete number
                          }
                     }while(pil<5);


                    System.out.println("Anda keluar dari program.");
                    System.out.println("Terima Kasih");



           }catch(Exception err){  //handling if the input is not valid
                   System.out.println("Masukan error!!!");
          }
    }
}





Do you think it's so simple program? . Yeah... If you want to solve problem, familiarize to keep it simple appropriate motto "Keep It Simple and Stupidest" . Do something with a simple and find begin a stupidest method that it's works. After that you can repair the method gradually.


If you want to get my source code please open my Free Download Pages.

Oke guys, I think I  just a little man, so if you have any critics or suggestion for me. Please comment this article.

Read More

How To Get Number As Word In Java

12:59 AM | , , , ,

         Huft... this week is very busy guys. So I'm really sorry , if you waiting for me for a long. :-) Okay guys, for this time i will share you about my little experiment on java programming. I will show you about how to get a number as a words like a picture below.







           Are you curious? . Let's do it.  Okay for the first we will make a class to define a conversion of a number to ordinal number. You can see the source code below
===================================================

public class OrdinalNum {
public String getNumberInWords(int num){
String defaultNum="I'm so sorry, this program only show number between 0 - 1000";
if(num==1) return "One";
else if(num==2) return "Two";
else if(num==3) return "Three";
else if(num==4) return "Four";
else if(num==5) return "Five";
else if(num==6) return "Six";
else if(num==7) return "Seven";
else if(num==8) return "Eight";
else if(num==9) return "Nine";
else if(num==10) return "Ten";
else if(num==11) return "Eleven";
else if(num==12) return "Twelve";
else if(num==13) return "Thihrteen";
else if(num==13) return "Fourteen";
else if(num==15) return "Fifteen";
else if((num>=16)&&(num<=19)) return (getNumberInWords(num%10)+ "teen");
else if(num==20) return ("Twenty");
else if(num==30) return ("Thirty");
else if(num==50) return ("Fifty");
else if((num>=21)&&(num<=29))
return ("Twenty " +getNumberInWords(num%((num/10)*10)));
else if((num>=31)&&(num<=39))
return ("Thirty " +getNumberInWords(num%((num/10)*10)));
else if((num>=51)&&(num<=59))
return ("Fifty " +getNumberInWords(num%((num/10)*10)));
else if((num>=40)&&(num<=90)&&(num%10==0)) return (getNumberInWords(num/10) + "ty");
else if(((num>=41)&&(num<=49))||((num>=61)&&(num<=99)))
return (getNumberInWords(num/10) + "ty " +getNumberInWords(num%((num/10)*10)));
else if(num==100) return "One Hundred";
else if((num>=101)&&(num<=199)) return ( "One Hundred " + getNumberInWords(num%100));
else if((num>=200)&&(num<=900)&& (num%100==0)) return (getNumberInWords(num/100) + " Hundred");
else if((num>=201)&&(num<=999)) return (getNumberInWords(num/100) + " Hundred " + getNumberInWords(num%100));
else if(num==1000) return "One Thousand";
else if(num==0) return "Nol";
else return defaultNum;
}
public String getNumberInWordsDouble(String number){
number=number.replace(".", " ");
String [] a = number.split(" ");
if(a.length==1)
return getNumberInWords(Integer.parseInt(a[0]));
else
return getNumberInWords(Integer.parseInt(a[0])) + " Point " + getNumberInWords(Integer.parseInt(a[1]));
}
}
==================================================
       Okay guys, let's learning the code one by one. As you see , the OrdinalNumber class have two method. They are getNumberInWords() and getNumberInwordsDouble().The first method has return an integer number to ordinal number and the second one return a double number to ordinal number.
        I use the recursive function to get a value of number, example for get the value of 123. We define the number 1 as a hundred block, then we call the recursive function of getNumberInWords() for number 23 then we get twenty. After that we call the recursive function again for number 3. So we will get "One Hundred Twenty Three" for the value of 123.
       Okay, what about the floating point number?. In principle the same as the search integer value above. But we need to split the number before point (,) and the number after point. After that we call getNumberInWords function for the first segment and the second one like the code above.

       After that you can use the source code below to enter the number that you want to get the value.
 ==================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GetNumAsWord extends JFrame {
    private JTextField Text;
    private JLabel lbl;
    public GetNumAsWord(){
        super("Get Number As Words");
        Container container=getContentPane();
        container.setLayout(new FlowLayout());
        lbl=new JLabel("Enter number between 0 - 1000");
        Text=new JTextField(10);
        container.add(lbl);
        container.add(Text);
        TextFieldHandler handler=new TextFieldHandler();
        Text.addActionListener(handler);
        setLocationRelativeTo(null);
        setSize(400,200);
        setVisible(true);
    }
    public static void main(String[] args) {
        GetNumAsWord Aplikasi=new GetNumAsWord() ;
        Aplikasi.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    private class TextFieldHandler implements ActionListener {
        public void actionPerformed(ActionEvent event){
            String string="";
            double angka;
            int icon = 0,nomor;
            if(event.getSource()==Text){
                try{
                    OrdinalNum on=new OrdinalNum();
                    if(Text.getText().replace(",", ".").contains(".")){
                        angka=Double.parseDouble(Text.getText().replace(",", "."));
                        string=on.getNumberInWordsDouble(String.valueOf(angka));
                    }else{
                        nomor=Integer.parseInt(Text.getText().replace(",", "."));
                        string=on.getNumberInWords(nomor);
                    }
                    icon=1;
                }catch(Exception e){
                    string="Enter number between 0 - 1000";
                    icon=2;
                }finally{
                    JOptionPane.showMessageDialog(null, string, "Information", icon);
                }
            }
        }
    }
}
==================================================

Okay guys, let's try it. Yupz, i am very sorry that i just make this program to show the number between 0 until 1000, but you can modify this code to show more number. I think it's easy for you.... :)

Don't forget to comment this page , coz I just a newbie programmer... :)
I'm realy happy if  you want to be my friend. Add me on FB @ Alieer or my tweet @etno_indonesia.

Read More

Bluetooth vs. WiFi which is the superior?

6:28 AM | , , , ,


Nowadays we often hear about the wireless data transmission technology. But what is meaning of  wireless network. Let us review together about the advantages and disadvantages of them.

Emerging wireless technologies today that Bluetooth and Wifi (Wireless Fidelity) are both devices that can connect the device via the wireless network. Here's an explanation of Bluetooth and Wifi.

Bluetooth

Bluetooth is a wireless communication technology that operates in the 2.4 GHz ISM radio frequency to connect a separate handheld devices (mobile phones, PDAs, computers, printers, etc.) with a relatively short range.

Bluetooth operates in the 2.4 GHz frequency band using a frequency hopping traceiver capable of providing voice and data communication services in real time between bluetooth's hosts with limited distance. The downside of this technology is a short range and low data transfer capabilities.


The History of Bluetooth

Beginning of Bluetooth is a wireless communication technology (without cable) that operate in the frequency band 2.4 GHz unlicensed ISM (Industrial, Scientific and Medical) by using a frequency hopping transceiver is capable of providing voice and data communication services in real-time between bluetooth host-host with limited service reach distance (around 10 meters). Bluetooth card that uses radio frequency IEEE 802.11 standard with a limited range of services and lower ability to transfer data from card to Wireless Local Area Network (WLAN).

Bluetooth formation promoted by five major companies Ericsson, IBM, Intel, Nokia and Toshiba formed a Special Interest Group (SIG). In July 1999 ,
Bluetooth's  document specification version 1.0 was launched. In December 1999 Bluetooth's development document with  specification version 2.0 begins again  with the addition of four new promoter namely 3Com, Lucent Technologies, Microsoft and Motorola. Currently, more than 1800 companies in various fields to join in a consortium as bluetooth technology adopter. Although the standard Bluetooth SIG is currently 'owned' by the promoter group, but he is expected to become an IEEE standard (802.15)


Bluetooth was derived by the name of the king at the end of ten centuries, Harald Blatand which in England is also called Harald Bluetooth was probably due to dark-colored teeth. He was the king of Denmark who has managed to unite the tribes that previously fought, including the tribes of the region now called by Norway and Sweden. Even the Scania region in Sweden, where Bluetooth technology is found also include territories. King's ability as a unifier is also similar to bluetooth technology now that can connect various devices such as personal computers and mobile phones.

Bluetooth's logo comes from the unification of Germany which is analogous to the two letters with the letter H and B (short for Harald Bluetooth), namely 
H-rune.gif (Hagall) dan Runic letter berkanan.png (Blatand) combined.
The Characteristic of Bluetooth
  •   Work on the Physical Layer using Frequency Hopping Spread Spectrum (FHSS).
  •   Frequency data width from 2.4 to 2.4835 GHz (ISM band).
  •   Frequency hops 1600 hop / sec .
  •   Data transmission speed of 1 Mbps (raw).
  •   The maximum range can reach about 10 meters or 30 feet.
  •   Provides communications services or communications point to point point to multipoint.
  •   The existence of data encryption.
  •   User's authentication.
  •   Output power control

Bluetooth prefer a method FHSS (Frequency Hopping Spread Spectrum) compared with DSSS (Direct Sequence Spread Spectrum). This is the reason of it :
  1. FHSS requires power consumption and lower complexity compared to DSSS this is because the   DSSS uses a chip rate (chip rate) compared to the symbol rate (symbol rate) used by the FHSS, so the cost required to use the DSSS will be higher. 
  2. FHSS uses FSK where the resistance to noise is relatively good compared with that typically uses DSSS OPSK (for IEEE 802.11 2 Mbps) or CCK (11 Mbps IEEE 802.11b).
Although FHSS has a distance range and data transfer that is lower than the DSSS but for the services below 2 Mbps FHSS can provide cost-effective solutions are better.

The  Advantages of  Bluetooth system are:
  • Bluetooth can penetrate walls, boxes, and various other obstacles, although the distance of transmission is only about 30 feet or 10 meters. 
  • Bluetooth does not require a cable or wire. 
  • Bluetooth can synchronize the databases of cell phone to a computer. 
  • Can be used as an intermediate modem
The Disadvantages of Bluetooth system are:
  • This system uses the same frequency with the wave of the standard LAN. 
  • If in a room is too many Bluetooth connections are used, it would be difficult for users to find the expected recipients. 
  • Many Bluetooth security mechanisms that must be observed to prevent the failure of transmission or reception of information. 
  • Been circulating viruses spread via bluetooth from your mobile phone

 WiFi 

Wi-Fi is short for Wireless Fidelity, which has the sense of a set of standards used for of  Wireless Local Area Networks (WLAN) based on IEEE 802.11 specification. The latest standards of specification 802.11a or b, such as 802.11 g, is currently in preparation, the latest specification offers many improvements ranging from broad coverage even further up to speed transfer

Wi-Fi was originally intended for the use of wireless devices and Local Area Network (LAN), but now more widely used for accessing the internet. This allows anyone with a computer with a wireless card (wireless card) or personal digital assistant (PDA) to connect to the internet using access point (otherwise known as hotspots) nearby.


Wi-Fi was designed based on the IEEE 802.11 specification. Today there are four variations of the 802.11, namely:
  • 802.11a
  • 802.11b
  • 802.11g
  • 802.11n
802.11b is the first product specification Wi-Fi. 802.11g and 802.11 product that have the most sales in 2005.
Wi-Fi Specification
Specification Speed Freq
Band
802.11b 11 Mb/s ~2.4 GHz
802.11a 54 Mb/s ~5 GHz
802.11g 54 Mb/s ~2.4 GHz
802.11n 100 Mb/s ~2.4 GHz

Connection Mode of WiFi

Ad-Hoc

This connection mode is a mode where multiple computers are connected directly, or better known as Peer-to-Peer. The advantage, cheaper and more practical when connected only 2 or 3 computers, without having to buy an access point.

Infrastructure

Using the Access Point that serves as a regulator of the data traffic, allowing many clients can connect to each other through the network.

WiFI Security
There are several types of security settings for the Wi-Fi, among others:
  1. WPA Pre-Shared Key
  2. WPA RADIUS
  3. WPA2 Pre-Shared Key Mixed
  4. WPA2 RADIUS Mixed
  5. RADIUS
  6. WEP

The Conclusion of Bluetooth vs. WiFi which is the superior?

In principle either Bluetooth or WiFi has advantages and disadvantages of each.

     Bluetooth uses FHSS transmission system that enables the data transmission process so that the battery energy savings would be more efficient when embedded in mobile phones and PDA systems in comparison with WiFi.
     But in terms of scope and magnitude of the maximum data capacity that can be sent WiFi with DSSS transmission method further favored because it is capable of transmitting large amounts of data and relatively greater range than Bluetooth
     Bluetooth works within the scope of the PAN (Private Area Network) so that the level of data security is more secure than WiFi which by default are in a public environment. So in a WiFi network security breaches are more common than Bluetooth
     Bluetooth signals can penetrate the wall so it will not reduce the unobstructed meskipin speed data transmission, while the WiFi transmission speed will be reduced if the signal is obstructed by other objects because the object hit the incoming signal will be reflected back so that the signal received in an enclosed space less than in the open.

From the above we can conclude in a condition likely Blutooth is superior, but in other conditions that WiFi was the more trustworthy.


 Posted by : Alir Retno , Informatics Engineering of STMIK Akakom Yogyakarta
Source : Wikipedia , http://ourn0tes.wordpress.com
Read More

Decision and Looping On PHP

6:04 AM | , , , , , ,

This is a simple php script about decision and looping. This script is showing some series number with differrent form and a blok of multiplication table.

<?php
            //This for the title
            echo"<h1>Tugas Pemrograman Web</br></h1>
                         <h2> NIM  : 095410170 </br>
                 Nama  : Alir Retno </br> </h2>
                 1. a)&nbsp;&nbsp;&nbsp;";

            //Ini utk deret ke-1
            $bil=4;
            for($i=2;$i<=7;$i++){
                        echo " $bil , ";
                        $bil+=$i;
            }
            echo "$bil</br>";
            echo "&nbsp;&nbsp;&nbsp; b)&nbsp;&nbsp;&nbsp;";
           
            //Ini utk deret ke-2
            $i=2;
            while($i<=4){
                        echo " ".$i." , ".$i++." , ";
            }
            echo "$i</br>";        
            echo "&nbsp;&nbsp;&nbsp; c)&nbsp;&nbsp;&nbsp;";
           
            //Ini utk deret ke-3
            $bil=1;
            $i=1;
            do{
                        echo " $bil , ";
                        if($i++%2==0) $bil-=7;
                        else $bil+=8;
            }while($i<=6);
            echo "$bil</br></br>           
2. Tabel Perkalian 1 s.d 10</br>";
           
            //ini utk tabel perkalian
            //Bikin tabelnya
            echo "<table border='1'>";
                        for($x=0;$x<=10;$x++){
                                    echo "<tr>";
                                    for($y=0;$y<=10;$y++){
                                                if($x==0 and $y==0){
                                                            echo "<td bgcolor='yellow' align='center'>X</td>";
                                                }else if($x==0 and $y>0){
                                                            echo "<td bgcolor='orange' align='right'> $y </td>";
                                                }else if($x>0 and $y==0){
                                                            echo "<td bgcolor='orange' align='right'> $x </td>";
                                                }else if($x%2==0){
                                                            echo "<td bgcolor='cyan' align='right'> ".$x*$y." </td>";
                                                }else{
                                                            echo "<td bgcolor='pink' align='right'> ".$x*$y." </td>";
                                                }                                             
                                    }         
                                    echo "</tr>";               
                        }
            echo "</table>"; 
?>



 Okay, lets me to tell you about the script one by one. For the first series of number number 4,6,9,13,18,24,31. It's a series number with (i+1) deviation every an iteration. The difference between the first number and the second is two. And then the second and next number difference is three, and so on. So we need a loop with this code
            $bil=4;
            for($i=2;$i<=7;$i++){
                        echo " $bil , ";
                        $bil+=$i;
            }
            echo "$bil</br>";
$i is iteration that you will run and $bil is the number which you will show .


For the second series of number are 2,2,3,3,4,4,5. It's a series number that the number is repeated twice,
so if you wan to show them you can use this code
            $i=2;
            while($i<=4){
                        echo " ".$i." , ".$i++." , ";
            }
            echo "$i</br>";        
 it's so simple guys.... :)


And the last series of number are 1,9,2,10,3,11,4. For this series, the difference between the first number and the second one is plus eight, but  the difference between the second and the third is minus seven. so let's us to do with this code
            $bil=1;
            $i=1;
            do{
                        echo " $bil , ";
                        if($i++%2==0) $bil-=7;

                        else $bil+=8;
            }while($i<=6);
            echo "$bil</br></br>            

The line with red color is the key of code. If an iteration is even then the number minus seven, and if it's an odd iteration then the number minus seven.

If you want to try this code you can search on My Free Download Pages with this title. Good job guys, we will see again soon :)
Read More