Vous êtes sur la page 1sur 18

MAKALAH

INTEROPERABILITAS

PEMROGRAMAN KALKULATOR SEDERHANA

MAKALAH INTEROPERABILITAS “ PEMROGRAMAN KALKULATOR SEDERHANA ” Ditulis oleh: Nama : Marwan Firmansyah Nrp : 15-2012-071

Ditulis oleh:

Nama

: Marwan Firmansyah

Nrp

: 15-2012-071

JURUSAN TEKNIK INFORMATIKA FAKULTAS TEKNOLOGI INDUSTRI

INSTITUT TEKNOLOGI NASIONAL JANUARI - BANDUNG

2015

1.

Create New Project

1. Create New Project

2.

Set Name Project

2. Set Name Project 3. Create Java Main Class 4. Create Name MainServer
  • 3. Create Java Main Class

  • 4. Create Name MainServer

5. Create Object Server Socket and Add Import for java.net.ServerSocket 6. Soround try-catch, exception Socket
  • 5. Create Object Server Socket and Add Import for java.net.ServerSocket

5. Create Object Server Socket and Add Import for java.net.ServerSocket 6. Soround try-catch, exception Socket
7. Create Socket For Client by server socket and impor java.net.socket 8. Create pipe communication to
  • 7. Create Socket For Client by server socket and impor java.net.socket

7. Create Socket For Client by server socket and impor java.net.socket 8. Create pipe communication to
  • - Next Import java.io.DataInputStream and mport java.io.DataOutputStream

- Next Import java.io.DataInputStream and mport java.io.DataOutputStream 9. Add Coding In Server to Send Massage to
- Next Import java.io.DataInputStream and mport java.io.DataOutputStream 9. Add Coding In Server to Send Massage to
  • 9. Add Coding In Server to Send Massage to Client

10. Add Coding In Server to Process Calculation Input client

10. Add Coding In Server to Process Calculation Input client

10. Add Coding In Server to Process Calculation Input client

11. Create New Java Main Class and Create Name Main Client

11. Create New Java Main Class and Create Name Main Client
12. Create Socket Client and impor java.net.socket

12. Create Socket Client and impor java.net.socket

12. Create Socket Client and impor java.net.socket

13.

Soround try-catch, exception Socket

13. Soround try-catch, exception Socket 14. Create pipe communication to Input and Output from client -
  • 14. Create pipe communication to Input and Output from client

    • - Next Import java.io.DataInputStream and mport java.io.DataOutputStream

13. Soround try-catch, exception Socket 14. Create pipe communication to Input and Output from client -
15. Get info for Client from Server

15. Get info for Client from Server

15. Get info for Client from Server

16.

Import java.until.Scanner

16. Import java.until.Scanner 17. Response Client for Server and Input number for calculation from two number
  • 17. Response Client for Server and Input number for calculation from two number

16. Import java.until.Scanner 17. Response Client for Server and Input number for calculation from two number

18. Run MainServer

18. Run MainServer 19. Run MainClient

19. Run MainClient

18. Run MainServer 19. Run MainClient

20.

Proses Input number from Client for Server and answers for calculation 1

20. Proses Input number from Client for Server and answers for calculation 1 21. Proses Input
  • 21. Proses Input number from Client for Server and answers for calculation 2

20. Proses Input number from Client for Server and answers for calculation 1 21. Proses Input

22.

Proses Input number from Client for Server and answers for calculation 3

22. Proses Input number from Client for Server and answers for calculation 3 23. Proses Input
  • 23. Proses Input number from Client for Server and answers for calculation 4

22. Proses Input number from Client for Server and answers for calculation 3 23. Proses Input

MainServer package proseskalkulator;

import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.logging.Level; import java.util.logging.Logger;

* @author Marwan public class MainServer { public static int PORT=2609;

* @param args the command line arguments public static void main(String[] args) { try { // TODO code application logic here ServerSocket ss = new ServerSocket(PORT); System.out.println("Server Sedang Menunggu Client

......

");

while (true){ Socket sock = ss.accept(); DataInputStream dis = new DataInputStream((sock.getInputStream())); DataOutputStream dos = new DataOutputStream(sock.getOutputStream()); dos.writeUTF("Selamat Datang Di Aplikasi Proses Kalkulator Sederhana"); dos.writeUTF("1. Operasi Pertambah"); dos.writeUTF("2. Operasi Perkurang"); dos.writeUTF("3. Operasi Perkalian"); dos.writeUTF("4. Operasi Pembagian"); String pilihan= dis.readUTF(); System.out.println("Pilihan Operasi:"+pilihan); dos.writeUTF("Masukan Angka Pertama"); String x1 = dis.readUTF(); dos.writeUTF("Masukan Angka Kedua"); String x2 = dis.readUTF(); int angka1 = Integer.parseInt(x1); int angka2 = Integer.parseInt(x2); int hasil = 0; int pilihan1 = Integer.parseInt(pilihan); if (pilihan1==1){ hasil = angka1+angka2; } else if (pilihan1==2){ hasil = angka1-angka2; } else if (pilihan1==3){ hasil = angka1*angka2; } else if (pilihan1==4){ hasil = angka1/angka2; } else System.out.println("client salah masukin"); dos.writeUTF("Maka hasilnya adalah: "+ hasil);

dis.close();dos.close();sock.close();

} } catch (IOException ex) { Logger.getLogger(MainServer.class.getName()).log(Level.SEVERE, null, ex);

}

}

}

MainClient

package proseskalkulator;

import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger;

/** * * @author Marwan */ public class MainClient { private static String HOST="localhost"; private static int PORT=2609; /** * @param args the command line arguments */ public static void main(String[] args) { try { // TODO code application logic here Socket sock = new Socket(HOST, PORT); DataInputStream dis = new DataInputStream(sock.getInputStream()); DataOutputStream dos = new DataOutputStream(sock.getOutputStream()); System.out.println("Info server: "+dis.readUTF()); System.out.println(dis.readUTF()); System.out.println(dis.readUTF()); System.out.println(dis.readUTF()); System.out.println(dis.readUTF()); Scanner scan = new Scanner(System.in); String angka = scan.nextLine(); dos.writeUTF(angka); System.out.println(dis.readUTF()); String angka1 = scan.nextLine();

dos.writeUTF(angka1);

System.out.println(dis.readUTF()); String angka2 = scan.nextLine();

dos.writeUTF(angka2);

System.out.println(dis.readUTF());

dis.close();dos.close();sock.close();

} catch (IOException ex) { Logger.getLogger(MainClient.class.getName()).log(Level.SEVERE, null, ex); } }

}