diff --git a/H071201091/PRAKTIKUM3/Nomor05.java b/H071201091/PRAKTIKUM3/Nomor05.java new file mode 100644 index 0000000..2e04df2 --- /dev/null +++ b/H071201091/PRAKTIKUM3/Nomor05.java @@ -0,0 +1,63 @@ +import java.util.Scanner; + +public class Nomor05 { + static Scanner ara = new Scanner(System.in); + public static void main(String[] args) { + System.out.println("\n*TUGAS PRAKTIKUM 3*\nNOMOR 3"); + System.out.println("\nNama: Ufairah Damara Bashir \nNIM: H07120191 \njurusan: ILMU KOMPUTER B"); + + System.out.println("\nPesan:"); + System.out.println("- 1 hari = 360 derajat"); + System.out.println("- Mencetak nilain n (derajat) ke bentuk satuan jam HH:MM:SS"); + System.out.println("- Nilai 0 derajat = 6:00:00"); + System.out.println("Input: \n- 1 bilangan float n (0<=n<=360) yang menunjukkan posisi matahari atau bulan.\n imputan akan berhenti dengan end of life"); + System.out.println("Output: \n- Mencetak selamat pagi, siang, sore atau malam berdasarkan waktu yang diikuti waktu aslinya"); + System.out.println("\nSilahkan input. \ninputan tak berakhir. \ninputan langsung menghasilkan output\n\n"); + try { + while (ara.hasNext()) { + + + float sudut = ara.nextFloat(); + int jam = 0, menit = 0, detik = 0; + int a = (int) (sudut * 240); + + if (sudut >= 0 && sudut < 360) { + while (a > 0) { + if (a - 3600 >= 0) { + a -= 3600; + jam++; + } else if (a - 60 >= 0) { + a -= 60; + menit++; + } else { + a -= 1; + detik++; + } + } + jam += 6; + + if (jam >= 24) + jam -= 24; + + if (jam <= 10) { + System.out.println("selamat pagi"); + System.out.printf("%02d:%02d:%02d\n\n", jam, menit, detik); + } else if (jam <= 14) { + System.out.println("selamat siang"); + System.out.printf("%02d:%02d:%02d\n\n", jam, menit, detik); + } else if (jam <= 18) { + System.out.println("selamat sore"); + System.out.printf("%02d:%02d:%02d\n\n", jam, menit, detik); + } else { + System.out.println("selamat malam"); + System.out.printf("%02d:%02d:%02d\n\n", jam, menit, detik); + } + } else + System.out.println("harap masukkan 0<=nilai<360"); + } + } catch (Exception e) { + System.out.println("inputan hanya angka bernilai 0 sampai 360"); + } + + } +} diff --git a/H071201091/PRAKTIKUM3/nomor1.java b/H071201091/PRAKTIKUM3/nomor1.java new file mode 100644 index 0000000..ee2b8b0 --- /dev/null +++ b/H071201091/PRAKTIKUM3/nomor1.java @@ -0,0 +1,49 @@ +import java.util.*; + +/** + * nomor1 + */ +public class nomor1 { + static Scanner ara = new Scanner (System.in); + public static void main(String[] args) { + System.out.println("*TUGAS PRAKTIKUM 3*\nNOMOR 1"); + System.out.println("\nNama: Ufairah Damara Bashir \nNIM: H07120191 \njurusan: ILMU KOMPUTER B"); + + System.out.println("\nPesan:"); + System.out.println("- Inputan X dan Y adalah integer"); + System.out.println("- X adalah nilai awal"); + System.out.println("- Y adalah nilai akhir"); + + System.out.println("- Output:"); + System.out.println(" - Mencetak keterangan negatif atau positif pada rentang X sampai Y"); + System.out.println(" - Mencetak keterangan ganjil atau genap pada rentang X sampai Y"); + + System.out.println("\nInput Nilai X:"); + int a = ara.nextInt(); + System.out.println("Input Nilai X:"); + int b = ara.nextInt(); + + System.out.println("\nOutput nilai X sampai Y beserta keterangan:"); + + for (;a<=b;a++){ + if (a<0){ + if (a%2==0){ + System.out.println(a + " genap negatif"); + } + if (a%1==0 && a%2!=0){ + System.out.println(a + " ganjil negatif"); + } + }else if (a==0){ + System.out.println(a + " nol"); + }else{ + if (a%2==0){ + System.out.println(a + " genap positif"); + } + if (a%2==1){ + System.out.println(a + " ganjil positif"); + } + } + } + System.out.println(); + } +} \ No newline at end of file diff --git a/H071201091/PRAKTIKUM3/nomor2.java b/H071201091/PRAKTIKUM3/nomor2.java new file mode 100644 index 0000000..1329f5d --- /dev/null +++ b/H071201091/PRAKTIKUM3/nomor2.java @@ -0,0 +1,32 @@ +import java.util.Scanner; + +public class nomor2 { + static Scanner ara = new Scanner (System.in); + public static void main(String[] args) { + System.out.println("\n*TUGAS PRAKTIKUM 3*\nNOMOR 2"); + System.out.println("\nNama: Ufairah Damara Bashir \nNIM: H07120191 \njurusan: ILMU KOMPUTER B"); + + System.out.println("\nPesan:"); + System.out.println("Nilai X dan Y adalah integer."); + System.out.println("- Output akan tercetak secara horizontal sebanyak X."); + System.out.println("- Output akan mencetak secara vertikal semua nilai dari 1 sampai Y."); + + System.out.println("\nMasukkan nilai X :"); + int X = ara.nextInt(); + System.out.println("Masukkan nilai Y :"); + int Y = ara.nextInt(); + System.out.println("\nOutput:"); + + if (Xa){ + while (c>=100000){ + c-=100000; + k100++; + } + while (c>=50000){ + c-=50000; + k50++; + } + while (c>=20000){ + c-=20000; + k20++; + } + while (c>=10000){ + c-=10000; + k10++; + } + while (c>=5000){ + c-=5000; + k5++; + } + while (c>=2000){ + c-=2000; + k2++; + } + while (c>=1000){ + c-=1000; + k1++; + } + } + System.out.println(k100 + " Uang Rp100.000"); + System.out.println(k50 + " Uang Rp50.000"); + System.out.println(k20 + " Uang Rp20.000"); + System.out.println(k10 + "Uang Rp10.000"); + System.out.println(k5 + " Uang Rp5.000"); + System.out.println(k2 + " Uang Rp2.000"); + System.out.println(k1 + " Uang Rp1.000"); + System.out.println(); + } +} \ No newline at end of file diff --git a/H071201091/PRAKTIKUM4/nomorDua.java b/H071201091/PRAKTIKUM4/nomorDua.java new file mode 100644 index 0000000..2b8fe0b --- /dev/null +++ b/H071201091/PRAKTIKUM4/nomorDua.java @@ -0,0 +1,51 @@ +import java.util.*; + + // Compiler version JDK 11.0.2 + + class nomorDua{ + static Scanner ara = new Scanner (System.in); + public static void main(String args[]){ + System.out.println("pesan:"); + System.out.println("- Array A dua dimensi terdiri dari inputan i dan j"); + System.out.println("- Array B dua dimensi terdiri dari inputan j dan k"); + + System.out.println("\ninput i, j , k : "); + int i = ara.nextInt(); + int j = ara.nextInt(); + int k = ara.nextInt(); + + int total = 0; + + int A[][] = new int [i][j]; + int B[][] = new int [j][k]; + int C[][] = new int [i][k]; + + System.out.println("\ninput elemen A :"); + for (int a = 0; a=0;i--){ + haha+=var[i]; + } + String hexa = String.format("#%x", jumlah); + + System.out.printf(hexa); + System.out.print(set); + System.out.print(haha); + System.out.printf("%o",kata.length()); + + char [] a = hexa.toCharArray(); + + int huruf = 0; + for (int i = 0; i='A'&& a[i] <= 'z'){ + huruf++; + break; + } + } + System.out.printf("%c", huruf==1? '?':'!'); + } +} \ No newline at end of file diff --git a/H071201091/PRAKTIKUM6/nomor2.java b/H071201091/PRAKTIKUM6/nomor2.java new file mode 100644 index 0000000..bf13ac9 --- /dev/null +++ b/H071201091/PRAKTIKUM6/nomor2.java @@ -0,0 +1,27 @@ +import java.util.*; + +/** + * nomor2 + */ +public class nomor2 { + static Scanner scan = new Scanner (System.in); + public static void main(String[] args) { + String input = scan.nextLine(); + char [] ver = input.toCharArray(); + int kode = 0; + for (int i = 0; i()); + filmfav.put("Rilis", new ArrayList<>()); + filmfav.put("Durasi", new ArrayList<>()); + filmfav.put("Genre", new ArrayList<>()); + filmfav.put("Sinopsis", new ArrayList<>()); + filmfav.put("Cast", new ArrayList<>()); + String lala = "Y"; + while(lala.equalsIgnoreCase("Y")){ + daftfilm(filmfav); + System.out.println("(d) detail (s) search (a) add (r) remove"); + String input = scan.next(); + if(input.equalsIgnoreCase("d")){ + int noFilm = scan.nextInt() - 1; + detailFilm(noFilm,filmfav); + System.out.println("Y/N untuk melanjutkan daftar Film"); + lala = scan.next(); + } + else if(input.equalsIgnoreCase("a")){ + addFilm(filmfav,scan); + daftfilm(filmfav); + System.out.println("Y/N untuk melanjutkan daftar Film"); + lala = scan.next(); + } + else if(input.equalsIgnoreCase("r")){ + int deleteNumberOfFilm = scan.nextInt() - 1; + removeFilm(deleteNumberOfFilm,filmfav); + daftfilm(filmfav); + System.out.println("Y/N untuk melanjutkan daftar Film"); + lala = scan.next(); + } + else if(input.equalsIgnoreCase("s")){ + String input2 = scan.next(); + System.out.printf(search(input2,filmfav)); + System.out.println("stop? (Y/N) "); + lala = scan.next(); + + } + else{ + System.out.println("Berhenti? (Y/N)"); + lala = scan.next(); + } + } + } + public static void daftfilm(HashMap> movieFavourite){ + ArrayList judulFilm = movieFavourite.get("Judul"); + System.out.println("Favourite Movie"); + if(judulFilm.isEmpty()){ + System.out.println("Daftar Kosong"); + } + for(int i = 0; i < judulFilm.size(); i++){ + System.out.println(i + 1 +". "+ judulFilm.get(i)); + } + } + public static void detailFilm(int nomorFilm, HashMap> movieFavourite){ + System.out.println("Judul: " + movieFavourite.get("Judul").get(nomorFilm)); + System.out.println("Rilis: " + movieFavourite.get("Rilis").get(nomorFilm)); + System.out.println("Durasi: " + movieFavourite.get("Durasi").get(nomorFilm)); + System.out.println("Genre: " + movieFavourite.get("Genre").get(nomorFilm)); + System.out.println("Sinopsis: " + movieFavourite.get("Sinopsis").get(nomorFilm)); + System.out.println("Cast: " + movieFavourite.get("Cast").get(nomorFilm)); + + } + public static void addFilm(HashMap> movieFavourite, Scanner yuu2){ + yuu2.nextLine(); + String judul; String rilis; String durasi; + String genre; String sinopsis; String cast; + + System.out.println("Judul:"); judul = yuu2.nextLine(); + System.out.println("Rilis:"); rilis = yuu2.nextLine(); + System.out.println("Durasi:"); durasi = yuu2.nextLine(); + System.out.println("Genre:"); genre = yuu2.nextLine(); + System.out.println("Sinopsis:"); sinopsis = yuu2.nextLine(); + System.out.println("Cast:"); cast = yuu2.nextLine(); + + movieFavourite.get("Judul").add(judul); + movieFavourite.get("Rilis").add(rilis); + movieFavourite.get("Durasi").add(durasi); + movieFavourite.get("Genre").add(genre); + movieFavourite.get("Sinopsis").add(sinopsis); + movieFavourite.get("Cast").add(cast); + } + public static void removeFilm(int deleteNumberOfFilm, HashMap> movieFavourite){ + movieFavourite.get("Judul").remove(deleteNumberOfFilm); + movieFavourite.get("Rilis").remove(deleteNumberOfFilm); + movieFavourite.get("Durasi").remove(deleteNumberOfFilm); + movieFavourite.get("Genre").remove(deleteNumberOfFilm); + movieFavourite.get("Sinopsis").remove(deleteNumberOfFilm); + movieFavourite.get("Cast").remove(deleteNumberOfFilm); + } + public static String search(String input2, HashMap> movieFavourite){ + ArrayList judul = movieFavourite.get("Judul"); + String out = "hasil("+ input2 +")\n"; + for (int i = 0; i < judul.size(); i++) { + String movie = judul.get(i); + for (int j = 0; j < movie.length(); j++) { + if(j+input2.length() <= movie.length()){ + if(input2.equalsIgnoreCase(movie.substring(j,j+input2.length()))){ + out += String.format(i+1 + "." +movie + "\n"); + break; + } + + } + else{ + continue; + } + } + } + return out; + + } +} \ No newline at end of file diff --git a/H071201091/PRAKTIKUM8/Soal1.java b/H071201091/PRAKTIKUM8/Soal1.java new file mode 100644 index 0000000..b238192 --- /dev/null +++ b/H071201091/PRAKTIKUM8/Soal1.java @@ -0,0 +1,36 @@ +import java.io.*; +import java.util.*; +public class Soal1 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + + FileInputStream input = null; + FileOutputStream output = null; + try{ + input = new FileInputStream(scan.next() + ".txt"); + output = new FileOutputStream(scan.next() + ".txt"); + int i; + while((i = input.read()) != -1){ + output.write(i); + } + } + catch(IOException ioe){ + System.out.println("gagal"); + } + finally{ + try{ + if(input != null){ + System.out.println("Berhasil"); + input.close(); + } + if(output != null){ + output.close(); + } + } + catch(IOException ioe){ + System.out.println("Gagal"); + } + } + } +} \ No newline at end of file diff --git a/H071201091/PRAKTIKUM8/Soal2.java b/H071201091/PRAKTIKUM8/Soal2.java new file mode 100644 index 0000000..92ce957 --- /dev/null +++ b/H071201091/PRAKTIKUM8/Soal2.java @@ -0,0 +1,53 @@ +import java.util.*; +import java.io.*; + +public class Soal2 { + public static void main(String[] args) throws FileNotFoundException { + Scanner scan = new Scanner (System.in); + FileWriter fileWrite = null; + PrintWriter printWrite = null; + FileReader fileRead = null; + BufferedReader buffRead = null; + + try { + String firstFile = scan.next(); + String secondFile = scan.next(); + scan.close(); + fileRead = new FileReader(String.format("%s.txt",firstFile)); + buffRead = new BufferedReader(fileRead); + fileWrite = new FileWriter(String.format("%s.txt", secondFile)); + printWrite = new PrintWriter(fileWrite); + + String test; + + int max = 0; + while ((test = buffRead.readLine()) != null){ + max = test.length() > max ? test.length() : max; + } + fileRead = new FileReader(String.format("%s.txt",firstFile)); + buffRead = new BufferedReader(fileRead); + + + String test1; + + while ((test1 = buffRead.readLine()) != null) { + printWrite.write(String.format("%"+max+"s\n", test1)); + } + + } catch (IOException ioe){ + System.out.println("Gagal"); + } finally { + try { + if (fileWrite != null){ + System.out.println("Berhasil"); + fileWrite.close(); + } + if (fileRead != null){ + fileRead.close(); + } + } catch (IOException ioe){ + System.out.println(ioe.getMessage()); + } + } + } +} \ No newline at end of file diff --git a/H071201091/PRAKTIKUM8/Soal3.java b/H071201091/PRAKTIKUM8/Soal3.java new file mode 100644 index 0000000..3ca5435 --- /dev/null +++ b/H071201091/PRAKTIKUM8/Soal3.java @@ -0,0 +1,64 @@ +import java.io.*; +import java.util.Scanner; +import java.util.ArrayList; + +class Soal3 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + FileWriter fileWrite = null; + PrintWriter printWrite = null; + + try{ + System.out.print("Masukkan Nama File = "); + String fileName = scan.nextLine() + ".txt"; + ArrayList nameList = new ArrayList<>(); + ArrayList nimList = new ArrayList<>(); + ArrayList angkatanList = new ArrayList<>(); + + System.out.print("Berapa Jumlah Assisten yang ingin diinput ="); + int numberAssistance = scan.nextInt(); + scan.nextLine(); + + for (int i = 0; i < numberAssistance; i++) { + System.out.print("Nama = "); + String nama = scan.nextLine(); + if (nama.length()<=20){ + nameList.add(nama); + } + else { + System.out.println("nama tidak boleh lebih dari dua puluh karakter"); + nameList.add(scan.next()); + } + System.out.print("Nim = "); + nimList.add(scan.next()); + System.out.print("Angkatan = "); + angkatanList.add(scan.next()); + } + + fileWrite = new FileWriter(fileName); + printWrite = new PrintWriter(fileWrite); + printWrite.printf("+----------------------+------------+-----------+\n"); + printWrite.printf("|NAMA |NIM |ANGKATAN |\n"); + printWrite.printf("+----------------------+------------+-----------+\n"); + for (int j = 0; j < numberAssistance; j++) { + printWrite.printf("| %-20s | %-10s | %-8s |\n", nameList.get(j), nimList.get(j), angkatanList.get(j)); + } + printWrite.printf("+----------------------+------------+-----------+\n"); + + } catch (IOException ioe){ + System.out.println("Gagal"); + } finally { + try { + if (printWrite != null) { + System.out.println("Berhasil"); + printWrite.close(); + } + if (fileWrite != null) { + fileWrite.close(); + } + } catch (IOException ioe) { + System.out.println(ioe.getMessage()); + } + } + } +} \ No newline at end of file