Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tugas.akhir;
- import java.util.Scanner;
- public class TugasAkhir {
- public static String nama[];
- public static int[] golongan, jamKerja, jamLembur;
- //fungsi inputan
- static void inputan() {
- Scanner input = new Scanner(System.in);
- System.out.print("Masukkan jumlah data : ");
- int data = input.nextInt();
- nama = new String[data];
- golongan = new int[data];
- jamKerja = new int[data];
- for (int i = 0; i <nama.length; i++) {
- System.out.println("Memasukkan data karyawan ke " + i+1);
- Scanner in = new Scanner(System.in);
- System.out.print("Masukkan nama karyawan : ");
- nama[i] = in.nextLine();
- System.out.print("Masukkan golongan karyawan : ");
- golongan[i] = in.nextInt();
- System.out.print("Masukkan jam kerja karyawan : ");
- jamKerja[i] = in.nextInt();
- }
- }
- //fungsi untuk menghapus data
- static void hapusData() {
- Scanner del = new Scanner(System.in);
- System.out.print("Masukkan nama karyawan yang ingin dihapus : ");
- String dataNama = del.next();
- for (int j = 0; j < nama.length; j++) {
- if (nama[j].equalsIgnoreCase(dataNama)) {
- if (j == nama.length - 1) {
- nama[j] = "";
- golongan[j] = 0;
- System.out.println("=====DATA KARYAWAN BERHASIL DIHAPUS=====");
- break;
- } else {
- while (j == nama.length - 1) {
- nama[j] = nama[j + 1];
- nama[j + 1] = "";
- golongan[j] = golongan[j + 1];
- golongan[j + 1] = 0;
- jamKerja[j] = jamKerja[j + 1];
- jamKerja[j + 1] = 0;
- j++;
- break;
- }
- }
- }
- if (j == nama.length) {
- System.out.println("DATA TIDAK DITEMUKAN");
- }
- }
- }
- //fungsi untuk mencari data karyawan yang ingin dicari
- static void cariData() {
- Scanner masuk = new Scanner(System.in);
- System.out.print("Masukkan keyword nama karyawan : ");
- String dataKaryawan = masuk.nextLine();
- for (int k = 0; k < nama.length; k++) {
- if (nama[k].equals(dataKaryawan)) {
- System.out.println("=====DATA KARYAWAN DITEMUKAN=====");
- tampilkanData(k);
- break;
- }
- if (k == nama.length) {
- System.out.println("=============================");
- System.out.println("DATA KARYAWAN TIDAK DITEMUKAN");
- System.out.println("=============================");
- }
- }
- }
- //fungsi untuk menampilkan data
- static void tampilkanData(int x) {
- System.out.println("Nama Karyawan : " + nama[x] + "\nGolongan : " + golongan[x] + "\nJam Kerja : " + jamKerja[x]);
- System.out.println("===============");
- }
- static void datakaryawan() {
- System.out.println("==============RINCIAN GAJI KARYAWAN===============");
- System.out.println("");
- System.out.println("No.| Nama Karyawan | Golongan | Jam Kerja");
- System.out.println("=========================================");
- for (int l = 0; l < nama.length; l++) {
- System.out.println((l + 1) + " " + (nama[l] + " |" + golongan[l] + " |" + jamKerja[l] + " |"));
- }
- }
- //main
- public static void main(String[] args) {
- int menu;
- System.out.println("=======================================");
- System.out.println("SELAMAT DATANG DI PT.TEKNIK INFORMATIKA");
- System.out.println("=======================================");
- do {
- System.out.println("-----MENU GAJI KARYAWAN PT.TEKNIK INFORMATIKA-----");
- System.out.println("1. Memasukkan Data");
- System.out.println("2. Mencari Data");
- System.out.println("3. Melihat Data");
- System.out.println("4. Menghapus Data");
- System.out.println("5. EXIT");
- System.out.println("");
- System.out.println("===============");
- System.out.println("");
- Scanner pilih = new Scanner(System.in);
- System.out.print("Masukkan Pilihan Menu (1/2/3/4/5) : ");
- menu = pilih.nextInt();
- System.out.println("");
- switch (menu) {
- case 1: {
- System.out.println("Menu - 1. Memasukkan Data");
- inputan();
- }
- break;
- case 2: {
- System.out.println("Menu - 2. Mencari Data");
- cariData();
- }
- break;
- case 3: {
- System.out.println("Menu - 3. Melihat Data");
- datakaryawan();
- }
- break;
- case 4: {
- System.out.println("Menu - 4. Menghapus data");
- hapusData();
- }
- break;
- }
- } while (menu > 0 && menu < 5);
- System.out.println("TERIMA KASIH:D");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement