Advertisement
AldiDwik

Tugas Akhir

Dec 11th, 2020
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. package tugas.akhir;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TugasAkhir {
  6.  
  7. public static String nama[];
  8. public static int[] golongan, jamKerja, jamLembur;
  9.  
  10. //fungsi inputan
  11. static void inputan() {
  12. Scanner input = new Scanner(System.in);
  13. System.out.print("Masukkan jumlah data : ");
  14. int data = input.nextInt();
  15. nama = new String[data];
  16. golongan = new int[data];
  17. jamKerja = new int[data];
  18.  
  19. for (int i = 0; i <nama.length; i++) {
  20. System.out.println("Memasukkan data karyawan ke " + i+1);
  21. Scanner in = new Scanner(System.in);
  22. System.out.print("Masukkan nama karyawan : ");
  23. nama[i] = in.nextLine();
  24. System.out.print("Masukkan golongan karyawan : ");
  25. golongan[i] = in.nextInt();
  26. System.out.print("Masukkan jam kerja karyawan : ");
  27. jamKerja[i] = in.nextInt();
  28. }
  29. }
  30.  
  31. //fungsi untuk menghapus data
  32. static void hapusData() {
  33. Scanner del = new Scanner(System.in);
  34. System.out.print("Masukkan nama karyawan yang ingin dihapus : ");
  35. String dataNama = del.next();
  36.  
  37. for (int j = 0; j < nama.length; j++) {
  38. if (nama[j].equalsIgnoreCase(dataNama)) {
  39. if (j == nama.length - 1) {
  40. nama[j] = "";
  41. golongan[j] = 0;
  42. System.out.println("=====DATA KARYAWAN BERHASIL DIHAPUS=====");
  43. break;
  44. } else {
  45. while (j == nama.length - 1) {
  46. nama[j] = nama[j + 1];
  47. nama[j + 1] = "";
  48. golongan[j] = golongan[j + 1];
  49. golongan[j + 1] = 0;
  50. jamKerja[j] = jamKerja[j + 1];
  51. jamKerja[j + 1] = 0;
  52. j++;
  53. break;
  54. }
  55. }
  56. }
  57. if (j == nama.length) {
  58. System.out.println("DATA TIDAK DITEMUKAN");
  59. }
  60. }
  61. }
  62.  
  63. //fungsi untuk mencari data karyawan yang ingin dicari
  64. static void cariData() {
  65. Scanner masuk = new Scanner(System.in);
  66. System.out.print("Masukkan keyword nama karyawan : ");
  67. String dataKaryawan = masuk.nextLine();
  68.  
  69. for (int k = 0; k < nama.length; k++) {
  70. if (nama[k].equals(dataKaryawan)) {
  71. System.out.println("=====DATA KARYAWAN DITEMUKAN=====");
  72. tampilkanData(k);
  73. break;
  74. }
  75. if (k == nama.length) {
  76. System.out.println("=============================");
  77. System.out.println("DATA KARYAWAN TIDAK DITEMUKAN");
  78. System.out.println("=============================");
  79. }
  80. }
  81. }
  82.  
  83. //fungsi untuk menampilkan data
  84.  
  85. static void tampilkanData(int x) {
  86. System.out.println("Nama Karyawan : " + nama[x] + "\nGolongan : " + golongan[x] + "\nJam Kerja : " + jamKerja[x]);
  87. System.out.println("===============");
  88. }
  89.  
  90. static void datakaryawan() {
  91. System.out.println("==============RINCIAN GAJI KARYAWAN===============");
  92. System.out.println("");
  93. System.out.println("No.| Nama Karyawan | Golongan | Jam Kerja");
  94. System.out.println("=========================================");
  95. for (int l = 0; l < nama.length; l++) {
  96. System.out.println((l + 1) + " " + (nama[l] + " |" + golongan[l] + " |" + jamKerja[l] + " |"));
  97.  
  98. }
  99. }
  100.  
  101. //main
  102. public static void main(String[] args) {
  103. int menu;
  104. System.out.println("=======================================");
  105. System.out.println("SELAMAT DATANG DI PT.TEKNIK INFORMATIKA");
  106. System.out.println("=======================================");
  107. do {
  108. System.out.println("-----MENU GAJI KARYAWAN PT.TEKNIK INFORMATIKA-----");
  109. System.out.println("1. Memasukkan Data");
  110. System.out.println("2. Mencari Data");
  111. System.out.println("3. Melihat Data");
  112. System.out.println("4. Menghapus Data");
  113. System.out.println("5. EXIT");
  114. System.out.println("");
  115. System.out.println("===============");
  116. System.out.println("");
  117. Scanner pilih = new Scanner(System.in);
  118. System.out.print("Masukkan Pilihan Menu (1/2/3/4/5) : ");
  119. menu = pilih.nextInt();
  120. System.out.println("");
  121. switch (menu) {
  122. case 1: {
  123. System.out.println("Menu - 1. Memasukkan Data");
  124. inputan();
  125. }
  126. break;
  127. case 2: {
  128. System.out.println("Menu - 2. Mencari Data");
  129. cariData();
  130. }
  131. break;
  132. case 3: {
  133. System.out.println("Menu - 3. Melihat Data");
  134. datakaryawan();
  135. }
  136. break;
  137. case 4: {
  138. System.out.println("Menu - 4. Menghapus data");
  139. hapusData();
  140. }
  141. break;
  142. }
  143.  
  144. } while (menu > 0 && menu < 5);
  145. System.out.println("TERIMA KASIH:D");
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement