diff --git a/H071201074/PRATIKUM 3/Tp3Nomor1.java b/H071201074/PRATIKUM 3/Tp3Nomor1.java new file mode 100644 index 0000000..bb8ca23 --- /dev/null +++ b/H071201074/PRATIKUM 3/Tp3Nomor1.java @@ -0,0 +1,41 @@ +import java.util.Scanner; +class Tp3Nomor1 { + public static void main(String[] arg){ + Scanner a = new Scanner(System.in); + int x = a.nextInt(); + int y = a.nextInt(); + if ( x < y){ + for ( int i = x; i <= y; i++){ + if( i%2 == 0 && i < 0) { + System.out.println( i + " genap negatif"); + } else if ( i%2 != 0 && i < 0){ + System.out.println( i + " ganjil negatif"); + } else if (i == 0){ + System.out.println(i + " nol"); + } else if ( i%2 == 0 && i >0){ + System.out.println( i + " genap positif"); + } else if ( i%2 != 0 && i > 0){ + System.out.println( i + " ganjil positif"); + } + }a.close(); + } else { + for ( int i = y ; i <= x; i++){ + if( i%2 == 0 && i < 0) { + System.out.println( i + " genap negatif"); + } else if ( i%2 != 0 && i < 0){ + System.out.println( i + " ganjil negatif"); + } else if (i == 0){ + System.out.println(i +" nol"); + } else if ( i%2 == 0 && i >0){ + System.out.println( i + " genap positif"); + } else if ( i%2 != 0 && i > 0){ + System.out.println( i + " ganjil positif"); + + } + a.close(); + } + } +} +} + + diff --git a/H071201074/PRATIKUM 3/Tp3Nomor2.java b/H071201074/PRATIKUM 3/Tp3Nomor2.java new file mode 100644 index 0000000..f184da6 --- /dev/null +++ b/H071201074/PRATIKUM 3/Tp3Nomor2.java @@ -0,0 +1,25 @@ +import java.util.Scanner; +class Tp3Nomor2{ + public static void main(String[] arg){ + Scanner a = new Scanner(System.in); + int x = a.nextInt(); + int y = a.nextInt(); + + int num = 1; + + if ( x <= y){ + while ( num <= y){ + for ( int i = 0; i< x; i++){ + System.out.print(num+" "); + num++; + if ( num > y){ + break; + } + } + System.out.println(); + } + } else{ + System.out.println("Tabe ganti ki inputan ta' sesuai syarat"); + } + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 3/Tp3Nomor3.java b/H071201074/PRATIKUM 3/Tp3Nomor3.java new file mode 100644 index 0000000..48bb060 --- /dev/null +++ b/H071201074/PRATIKUM 3/Tp3Nomor3.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +class Tp3Nomor3{ + public static void main(String[] arg) { + Scanner x = new Scanner(System.in); + int n = x.nextInt(); + + int a = 0; + int b = 1; + int next; + + System.out.print(a + " "); + System.out.print(b); + + for (int i = 2; i < n; i++){ + next = a + b; + a = b; + b = next; + System.out.print(" "+ next); + } + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 3/Tp3Nomor4V2.java b/H071201074/PRATIKUM 3/Tp3Nomor4V2.java new file mode 100644 index 0000000..13bb947 --- /dev/null +++ b/H071201074/PRATIKUM 3/Tp3Nomor4V2.java @@ -0,0 +1,43 @@ +import java.util.Scanner; +class Tp3Nomor4V2{ + public static void main(String[] arg) { + Scanner ex = new Scanner(System.in); + int barang = ex.nextInt(); + int uang = ex.nextInt(); + + int kembalian = uang - barang; + int sisa = kembalian; + + for ( int i = 1 ; i <= 7; i++){ + if ( i == 1){ + int jumlah = sisa / 100000; + sisa = sisa - ( jumlah * 100000); + System.out.println( jumlah + " uang Rp. 100000" ); + } else if ( i == 2){ + int jumlah = sisa / 50000; + sisa = sisa - ( jumlah * 50000); + System.out.println( jumlah + " uang Rp. 50000"); + } else if ( i == 3){ + int jumlah = sisa / 20000; + sisa = sisa - ( jumlah * 20000); + System.out.println( jumlah + " uang Rp. 20000"); + } else if ( i == 4){ + int jumlah = sisa / 10000; + sisa = sisa - ( jumlah * 10000); + System.out.println( jumlah + " uang Rp. 10000"); + } else if ( i == 5){ + int jumlah = sisa / 5000; + sisa = sisa - ( jumlah * 5000); + System.out.println( jumlah + " uang Rp. 5000"); + } else if ( i == 6){ + int jumlah = sisa / 2000; + sisa = sisa - ( jumlah * 2000); + System.out.println( jumlah + " uang Rp. 2000"); + } else{ + int jumlah = sisa / 1000; + sisa = sisa - ( jumlah * 1000); + System.out.println( jumlah + " uang Rp. 1000"); + } + } + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 3/Tp3Nomor5.java b/H071201074/PRATIKUM 3/Tp3Nomor5.java new file mode 100644 index 0000000..15d32bb --- /dev/null +++ b/H071201074/PRATIKUM 3/Tp3Nomor5.java @@ -0,0 +1,36 @@ +import java.util.Scanner; +class Tp3Nomor5{ + public static void main(String[] arg) { + Scanner ex = new Scanner(System.in); + int sec, mm,hh ,ss ; + try{ + while(ex.hasNext()){ + float m = ex.nextFloat(); + if (0 <= m && m < 360){ + sec = (int)(m*86400)/360; + hh = (sec/3600)+6; + mm = (sec%3600)/60; + ss = (sec%3600)%60; + if (m >= 0 && m < 90){ + System.out.println("Selamat Pagi"); + } else if (m >= 90 && m < 150){ + System.out.println("Selamat Siang"); + } else if (m >= 150 && m < 195){ + System.out.println("Selamat Sore"); + } else if (m >= 195 && m < 270){ + System.out.println("Selamat Malam"); + } else if (m >= 270 && m < 360){ + System.out.println("Dini hari"); + } + System.out.printf("%02d:%02d:%02d", hh,mm,ss); + }else{ + System.out.println("Inputan harus lebih dari 0 dan kurang dari"); + ex.close(); + } + } + }catch(Exception e){ + System.out.println("end of file"); + } + + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 4/Tp4Nomor1.java b/H071201074/PRATIKUM 4/Tp4Nomor1.java new file mode 100644 index 0000000..24ee63f --- /dev/null +++ b/H071201074/PRATIKUM 4/Tp4Nomor1.java @@ -0,0 +1,28 @@ +import java.util.Scanner; +class Tp4Nomor1{ + public static void main(String[] arg){ + Scanner scan = new Scanner(System.in); + int num = scan.nextInt(); + int[] x = new int[num]; + int faktor = 0; + + for (int i = 0; i < num; i++){ + x[i] = scan.nextInt(); + } + + for (int i = 0; i < num; i++){ + for (int j = i + 1; j < num; j++){ + int min = Math.min(x[i], x[j]); + for (int k = 1; k <= min; k++){ + if ((x[i] % k == 0) && (x[j] % k == 0)){ + faktor = k; + } + } + + if (faktor == 1){ + System.out.println(x[i]+ " " + x[j]); + } + } + } + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 4/Tp4Nomor2.java b/H071201074/PRATIKUM 4/Tp4Nomor2.java new file mode 100644 index 0000000..b4c332d --- /dev/null +++ b/H071201074/PRATIKUM 4/Tp4Nomor2.java @@ -0,0 +1,42 @@ +import java.util.Scanner; +class Tp4Nomor2{ + public static void main(String[] arg){ + Scanner scan = new Scanner(System.in); + int a, b, c; + + a = scan.nextInt(); + b = scan.nextInt(); + c = scan.nextInt(); + + int[][] matrixA = new int[a][b]; + int[][] matrixB = new int[b][c]; + int[][] multi = new int[a][c]; + + System.out.println(); + for (int i = 0; i < a; i++){ + for (int j = 0; j < b; j++){ + matrixA[i][j] = scan.nextInt(); + } + } + System.out.println(); + for (int i = 0; i < b; i++){ + for (int j = 0; j < c; j++){ + matrixB[i][j] = scan.nextInt(); + } + } + for (int i = 0; i < multi.length; i++){ + for (int j = 0; j < matrixA.length + 1; j++){ + for (int k = 0; k < matrixA.length; k++){ + multi[i][j] += (matrixA[i][k] * matrixB[k][j]); + } + } + } + System.out.println(); + for (int i = 0; i < a; i++){ + for (int j = 0; j < c; j++){ + System.out.printf("%d\t", multi[i][j]); + } + System.out.println(); + } + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 5/Tp5Nomor1.java b/H071201074/PRATIKUM 5/Tp5Nomor1.java new file mode 100644 index 0000000..7f2db23 --- /dev/null +++ b/H071201074/PRATIKUM 5/Tp5Nomor1.java @@ -0,0 +1,27 @@ +import java.util.Scanner; +public class Tp5Nomor1{ + public static void main(String[] arg){ + Scanner scan = new Scanner(System.in); + int x = scan.nextInt(); + int y = scan.nextInt(); + int FPB = cariFPB(x,y); + System.out.printf("FPB dari %d dan %d = %d", x, y, FPB); + + } + static int cariFPB(int n, int m){ + int kecil = n; + int besar = m; + int FPB = 0; + if ( n > m){ + kecil = m; + besar = n; + } + for ( int i = kecil ; i > 0; i--){ + if (kecil % i == 0 && besar % i == 0){ + FPB = i; + break; + } + } + return FPB; + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 5/Tp5Nomor2.java b/H071201074/PRATIKUM 5/Tp5Nomor2.java new file mode 100644 index 0000000..4326324 --- /dev/null +++ b/H071201074/PRATIKUM 5/Tp5Nomor2.java @@ -0,0 +1,27 @@ +import java.util.Scanner; +import java.util.Random; + +public class Tp5Nomor2{ + public static void main(String[] arg){ + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); + int m = scan.nextInt(); + String serialNumber = generateSerial(n,m); + System.out.println(serialNumber); + } + + static String generateSerial (int n, int m){ + Random ran = new Random(); + String str = new String(); + for (int i = 1; i <= n; i++){ + for (int j = 1; j <= m ; j++){ + str += ran.nextInt(10); + } + if ( i < n){ + str += "-"; + } + } + return str; + } + +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 5/Tp5Nomor3.java b/H071201074/PRATIKUM 5/Tp5Nomor3.java new file mode 100644 index 0000000..ce0eff9 --- /dev/null +++ b/H071201074/PRATIKUM 5/Tp5Nomor3.java @@ -0,0 +1,31 @@ +import java.util.Scanner; +public class Tp5Nomor3{ + public static void main(String[] arg){ + Scanner scan = new Scanner(System.in); + int umur = scan.nextInt(); + int tahun = year(umur); + int bulan = month(umur); + int hari = day(umur); + System.out.println(tahun+" tahun"); + System.out.println(bulan+" bulan"); + System.out.println(hari+" hari"); + } + static int year(int n){ + int tahun = n / 365; + //System.out.println(tahun); + return tahun; + } + static int month(int n){ + int tahun = n / 365; + int bulan = (n % 356) / 30; + //System.out.println(bulan); + return bulan; + } + static int day(int n){ + int tahun = n / 365; + int bulan = (n % 365) / 30; + int hari = (n % 365) % 30; + //System.out.println(hari); + return hari; + } +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 6/Tp6Nomor1.java b/H071201074/PRATIKUM 6/Tp6Nomor1.java new file mode 100644 index 0000000..c601ef5 --- /dev/null +++ b/H071201074/PRATIKUM 6/Tp6Nomor1.java @@ -0,0 +1,46 @@ +import java.util.Scanner; +public class Tp6Nomor1{ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + String x = scan.nextLine(); + + + int hexa = x.length()*x.length(); + String hexadecimal = String.format("%x",hexa); + int oct = x.length(); + String octal = String.format("%o",oct); + + String pal=""; + String pal2=""; + String kata2=""; + + int kata = x.length()/2; + + String cerah = x.substring(0, (x.length()/2)-1);{ + pal = cerah.toUpperCase(); + + for (int i=kata-1; i>=0; i--){ + kata2=kata2 + x.charAt(i); + pal2= kata2.toUpperCase(); + + } + + char simbol='!'; + if(hexadecimal.codePointAt(0)>57){ + simbol ='?'; + } + + System.out.printf("#"+hexadecimal+pal.replaceAll("\\s","")+pal2.replaceAll("\\s","")+octal+simbol); + + + } + } +} + + + + + + + + diff --git a/H071201074/PRATIKUM 6/Tp6Nomor2.java b/H071201074/PRATIKUM 6/Tp6Nomor2.java new file mode 100644 index 0000000..9aaa23a --- /dev/null +++ b/H071201074/PRATIKUM 6/Tp6Nomor2.java @@ -0,0 +1,39 @@ +import java.util.Scanner; +public class Tp6Nomor2{ + public static void main (String[] args) { + Scanner input = new Scanner(System.in); + String kalimat_awal = input.nextLine(); + String kalimat = new String(); + for (int i=0; i judul = new HashMap<>(); + public static HashMap rilis = new HashMap<>(); + public static HashMap durasi = new HashMap<>(); + public static HashMap genre = new HashMap<>(); + public static HashMap cast = new HashMap<>(); + public static HashMap sinopsis = new HashMap<>(); + public static void main(String[] args) { + Scanner read = new Scanner(System.in); + String a = ""; + //avenger + judul.put(1, "Avenger : Endgame"); + rilis.put(1, "24 April 2019"); + durasi.put(1, "3 jam 2 menit"); + genre.put(1, "Fantasy, Sci-Fi"); + cast.put(1, "Robert Downey Jr., Chris Evans, Chris Hemsworth"); + sinopsis.put(1, "Melanjutkan Avengers Infinity War, dimana kejadian setelah Thanos berhasil mendapatkan semua infinity stones dan memusnahkan 50% semua mahluk hidup di alam semesta. Akankah para Avengers berhasil mengalahkan Thanos?"); + //spiderman + judul.put(2, "Spiderman : Far From Home"); + rilis.put(2, "3 juli 2019"); + durasi.put(2, "2 jam 9 menit"); + genre.put(2, "Fantasy ,Sci-Fi"); + cast.put(2, "Tom Holland, Zendaya, Samuel L. Jackson"); + sinopsis.put(2, "Peter Parker (Tom Holland) tengah mengunjungi Eropa untuk liburan panjang bersama temaan-temanya. Sayangnya , Parker tidak bisa dengan tenang menikmati liburannya, karena Nick Fury datang secara tiba-tiba di kamar hotelnya. Selama di Eropa pun Peter harus menghadapi banyak musuh mulai dari Hydro Man, Sandman dan Molten Man."); + //venom + judul.put(3, "Venom"); + rilis.put(3, "3 Oktober 2018"); + durasi.put(3, "2 jam 20 menit"); + genre.put(3, "Thriller ,Sci-Fi"); + cast.put(3, "Tom Hardy, Michelle Williams, Woody Harrelson"); + sinopsis.put(3, "Seorang jurnalis, Eddie Brock (Tom Hardy) ingin melakukan sebuah investasi kasus terhadap penemuan yang dipimpin oleh Dr. Carlton Drake (Riz Ahmed). Karena investigasinya, Eddie mengunjungi lab milik Dr. Calrlton Drake. Semuanya ditujukan untuk membuktikan bahwa Dr. Carlton Drake sedang sedang melakukan tindakan jahat menggunakan Symbiote."); + //thor + judul.put(4, "Thor : Ragnarok"); + rilis.put(4, "25 Oktober 2017"); + durasi.put(4, "2 jam 10 menit"); + genre.put(4, "Fantasy, Sci-Fi"); + cast.put(4, "Chris Hemsworth, Taika Waititi, Tessa Thompson"); + sinopsis.put(4, "Dipenjara, Thor yang hebat menemukan dirinya dalam sebuah kontes gladiator yang mematikan melawan Hulk, mantan sekutunya. Thor harus berjuang untuk bertahan hidup dan berpacu melawan waktu untuk mencegah Hela yang sangat kuat menghancurkan rumah dan peradaban Asgardian.?"); + + boolean movie = true; + while(movie){ + cetak(a); + System.out.println("(d)Detail \t(s)Search \t(a)Add \t(r)Remove \t" ); + String choice = read.next(); + if (choice.equals("a")) { + add(judul.size()+1); + } else if (choice.equals("d")) { + int n = read.nextInt(); + System.out.println(); + detail(n); + } else if (choice.equals("r")){ + int n = read.nextInt(); + System.out.println(); + remove(n); + } else if (choice.equals("s")){ + String search = read.next(); + System.out.println("Hasil Pencarian Dari " +search+ " : "); + for (int i = 1; i < judul.size(); i++) { + if (judul.get(i).toLowerCase().contains(search.toLowerCase())){ + System.out.print(judul.keySet().toArray()[i]+"."+" "); + System.out.println(judul.get(judul.keySet().toArray()[i-1])); + } + } + System.out.println(); + } + } + } + + //detail + public static void detail(int a){ + if(a>judul.size()){ + System.out.println("film hanya ada "+ judul.size()); + }else{ + System.out.println("Detail Film : "); + System.out.println("Judul\t\t: " + judul.get(a)); + System.out.println("Rilis\t\t: "+ rilis.get(a)); + System.out.println("Durasi\t\t: " + durasi.get(a)); + System.out.println("Genre\t\t: " + genre.get(a)); + System.out.println("Cast\t\t: " + cast.get(a)); + System.out.println("Sinopsis\t: " + sinopsis.get(a)); + System.out.println();} + } + public static void cetak(String a) { + System.out.println("Favourite Movie"); + for (int i = 0; i < judul.size(); i++) { + System.out.print(judul.keySet().toArray()[i]+"."+" "); + System.out.println(judul.get(judul.keySet().toArray()[i])); + + } + } + public static void remove(int a) { + judul.remove(a); + rilis.remove(a); + durasi.remove(a); + genre.remove(a); + cast.remove(a); + sinopsis.remove(a); + if(a max ? read.length() : max ; + } + + fr = new FileReader(source + ".txt"); + br = new BufferedReader(fr); + + String check; + while ((check = br.readLine()) != null) { + pWriter.write(String.format("%" +max+ "s\n", check)); + } + + } catch (IOException ioe) { + System.out.println("Gagal"); + } finally { + try { + if (fWriter != null) { + fWriter.close(); + } + if (pWriter != null) { + pWriter.close(); + } + if (br != null) { + System.out.println("Berhasil"); + br.close(); + } + if (fr != null) { + fr.close(); + } + } catch (IOException ioe) { + System.out.println(ioe.getMessage()); + } + } + + } + +} \ No newline at end of file diff --git a/H071201074/PRATIKUM 8/Tp8Nomor3.java b/H071201074/PRATIKUM 8/Tp8Nomor3.java new file mode 100644 index 0000000..de32fac --- /dev/null +++ b/H071201074/PRATIKUM 8/Tp8Nomor3.java @@ -0,0 +1,65 @@ +import java.io.*; +import java.util.Scanner; +class Tp8Nomor3 { + public static void main(String[] args) { + Scanner sc = new Scanner (System.in); + FileReader fileReader = null; + BufferedReader bufferedReader = null; + FileWriter fileWriter = null; + PrintWriter printWriter = null; + + try { + String destination = sc.nextLine(); + int data = sc.nextInt(); + sc.nextLine(); + String[] nama = new String [data]; + String[] nim = new String [data]; + String[] angkatan = new String [data]; + for (int i = 0; i < data; i++) { + nama[i] = sc.nextLine(); + nim[i] = sc.nextLine(); + angkatan[i] = sc.nextLine(); + if (nama[i].length()>20){ + System.out.println("gagal"); + System.out.println("nama tidak boleh lebih dari 20 karakter"); + return; + } + if(nama[i].contains(" ")){ + System.out.println("gagal"); + System.out.println("nama tidak boleh menggunakan spasi, jika terdapat spasi gunakan underscore '_' "); + return; + } + + } + sc.close(); + fileWriter = new FileWriter(destination + ".txt"); + printWriter = new PrintWriter(fileWriter); + + printWriter.println("+--------------------+-----------+---------+"); + printWriter.println("|Nama |NIM |Angkatan |"); + printWriter.println("+--------------------+-----------+---------+"); + for (int i = 0; i < data; i++) { + printWriter.printf("|%-20s|%-11s|%-9s|\n", nama[i], nim[i], angkatan[i]); + } + printWriter.println("+--------------------+-----------+---------+"); + System.out.println("Berhasil"); + + } catch (IOException ioe) { + System.out.println("Gagal"); + } finally { + try { + if (bufferedReader != null) { + bufferedReader.close(); + } + if (fileReader != null) { + fileReader.close(); + } + if ( printWriter != null) { + printWriter.close(); + } + } catch (IOException ioe) { + System.out.println(ioe.getMessage()); + } + } + } +} \ No newline at end of file