diff --git a/src/main/java/ip/syssrc/array/CountEach.java b/src/main/java/ip/syssrc/array/CountEach.java new file mode 100644 index 00000000..c66b5f5c --- /dev/null +++ b/src/main/java/ip/syssrc/array/CountEach.java @@ -0,0 +1,17 @@ +package ip.syssrc.array; + +/** + * CountEach + * + * Assignment 3.1 + * + * @author H071171512 - Fitrah Muhammad + * + */ + +public class CountEach { + + public static void main(String[] args) { + + } +} diff --git a/src/main/java/ip/syssrc/array/RadixConverter.java b/src/main/java/ip/syssrc/array/RadixConverter.java new file mode 100644 index 00000000..aa0f9ea8 --- /dev/null +++ b/src/main/java/ip/syssrc/array/RadixConverter.java @@ -0,0 +1,16 @@ +package ip.syssrc.array; + +/** + * RadixConverter + * + * Assignment 3.2 + * + * @author H071171512 - Fitrah Muhammad + * + */ +public class RadixConverter { + + public static void main(String[] args) { + + } +} diff --git a/src/main/java/ip/syssrc/array/SumOneThird.java b/src/main/java/ip/syssrc/array/SumOneThird.java new file mode 100644 index 00000000..ddbed9b6 --- /dev/null +++ b/src/main/java/ip/syssrc/array/SumOneThird.java @@ -0,0 +1,20 @@ +package ip.syssrc.array; + +/** + * SumOneThird + * + * Assignment 3.3 + * + * @author H071171512 - Fitrah Muhammad + * + */ +public class SumOneThird { + + public static void main(String[] args) { + int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + + for (int index = 0; index < (arr.length / 3); index++) { + // Your magic is here + } + } +} diff --git a/src/main/java/ip/syssrc/conditional/Cashier.java b/src/main/java/ip/syssrc/conditional/Cashier.java index 26cecf63..e32aca68 100644 --- a/src/main/java/ip/syssrc/conditional/Cashier.java +++ b/src/main/java/ip/syssrc/conditional/Cashier.java @@ -1,5 +1,7 @@ package ip.syssrc.conditional; +import java.util.Scanner; + /** * Cashier * @@ -11,6 +13,8 @@ public class Cashier { public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + scan.close(); } } diff --git a/src/main/java/ip/syssrc/conditional/CashierSolution.java b/src/main/java/ip/syssrc/conditional/CashierSolution.java new file mode 100644 index 00000000..14b5eef3 --- /dev/null +++ b/src/main/java/ip/syssrc/conditional/CashierSolution.java @@ -0,0 +1,97 @@ +package ip.syssrc.conditional; + +import java.util.InputMismatchException; +import java.util.Scanner; + +/** + * Cashier + * + * Assignment 1.1 + * + * @author H071171512 - Fitrah Muhammad + * + */ +public class CashierSolution { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + int price = 0; + int payment = 0; + + try { + System.out.print("Berapa total harga belanja anda ? "); + price = scan.nextInt(); + System.out.print("Berapa total uang yang anda bayarkan ? "); + payment = scan.nextInt(); + } catch (InputMismatchException e) { + System.out.println("Maaf, pastikan inputan anda adalah angka"); + scan.close(); + return; + } finally { + scan.close(); + } + + if (payment < price) { + System.out.println("Maaf, pembayaran anda belum mencukupi\n"); + return; + } + + if (payment == price) { + System.out.println("Terima kasih telah membayar dengan uang pas\n"); + return; + } + + int change = payment - price; + + System.out.printf("\nTotal kembalian anda: Rp %d\n", change); + System.out.println("Dengan rincian sebagai berikut:\n"); + + if (change >= 100_000) { + System.out.printf("%d lembar uang Rp. 100.000\n", change / 100_000); + change %= 100_000; + } + if (change >= 50_000) { + System.out.printf("%d lembar uang Rp. 50.000\n", change / 50_000); + change %= 50_000; + } + if (change >= 20_000) { + System.out.printf("%d lembar uang Rp. 20.000\n", change / 20_000); + change %= 20_000; + } + if (change >= 10_000) { + System.out.printf("%d lembar uang Rp. 10.000\n", change / 10_000); + change %= 10_000; + } + if (change >= 5_000) { + System.out.printf("%d lembar uang Rp. 5.000\n", change / 5_000); + change %= 5_000; + } + if (change >= 2_000) { + System.out.printf("%d lembar uang Rp. 2.000\n", change / 2_000); + change %= 2_000; + } + if (change >= 1_000) { + System.out.printf("%d lembar uang Rp. 1.000\n", change / 1_000); + change %= 1_000; + } + if (change >= 500) { + System.out.printf("%d buah uang Rp. 500\n", change / 500); + change %= 500; + } + if (change >= 200) { + System.out.printf("%d buah uang Rp. 200\n", change / 200); + change %= 200; + } + if (change >= 100) { + System.out.printf("%d buah uang Rp. 100\n", change / 100); + change %= 100; + } + + if (change > 0) { + System.out.printf("Dan sebanyak Rp. %d didonasikan\n", change); + } + + System.out.println(); + } +} diff --git a/src/main/java/ip/syssrc/conditional/RoleAccessSolution.java b/src/main/java/ip/syssrc/conditional/RoleAccessSolution.java new file mode 100644 index 00000000..66acb748 --- /dev/null +++ b/src/main/java/ip/syssrc/conditional/RoleAccessSolution.java @@ -0,0 +1,64 @@ +package ip.syssrc.conditional; + +/** + * RoleAccess + * + * Assignment 1.2 + * + * @author H071171512 - Fitrah Muhammad + * + */ +public class RoleAccessSolution { + + public static void main(String[] args) { + + int menuIndex = 0; + int subMenuIndex = 0; + boolean isValidRole = false; + + if (args.length == 0) { + System.out.println("What role you want to see ?"); + System.out.println("For example, try 'Admin'."); + return; + } + + if (args.length > 1) { + System.out.println("Too many argument"); + return; + } + + switch (args[0]) { + case "Super Admin": + case "Admin": + case "User": + isValidRole = !isValidRole; + break; + } + + if (!isValidRole) { + System.out.println("Invalid Role"); + System.out.println("Valid Role : Super Admin, Admin, User"); + return; + } + + switch (args[0]) { + case "Super Admin": + System.out.printf("%d. Super Admin\n", ++menuIndex); + System.out.printf("%2d.%d. CRUD Super Admin\n", menuIndex, ++subMenuIndex); + System.out.printf("%2d.%d. CRUD Admin\n", menuIndex, ++subMenuIndex); + System.out.printf("%2d.%d. CRUD User\n\n", menuIndex, ++subMenuIndex); + subMenuIndex = 0; + case "Admin": + System.out.printf("%d. Admin\n", ++menuIndex); + System.out.printf("%2d.%d. CRUD Admin\n", menuIndex, ++subMenuIndex); + System.out.printf("%2d.%d. CRUD User\n\n", menuIndex, ++subMenuIndex); + subMenuIndex = 0; + default: + System.out.printf("%d. User\n", ++menuIndex); + System.out.printf("%2d.%d. View\n", menuIndex, ++subMenuIndex); + System.out.printf("%2d.%d. Edit\n", menuIndex, ++subMenuIndex); + subMenuIndex = 0; + } + + } +}