Last active
December 1, 2023 03:55
-
-
Save rafirh/31529d7d89ccd018047c05b4ee2ed2b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Solution { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int jumlahOrang = scanner.nextInt(); | |
scanner.nextLine(); | |
String[][] jadwalTV = new String[3][3]; | |
initializeJadwal(jadwalTV); | |
for (int i = 0; i < jumlahOrang; i++) { | |
String[] dataPemesan = scanner.nextLine().split(" "); | |
String nomorIdentitas = dataPemesan[0]; | |
String tv = dataPemesan[1]; | |
String jadwal = dataPemesan[2]; | |
bookJadwal(jadwalTV, nomorIdentitas, tv, jadwal); | |
} | |
printJadwalTable(jadwalTV); | |
} | |
private static void initializeJadwal(String[][] jadwalTV) { | |
for (int i = 0; i < 3; i++) { | |
for (int j = 0; j < 3; j++) { | |
jadwalTV[i][j] = ""; | |
} | |
} | |
} | |
private static void bookJadwal(String[][] jadwalTV, String nomorIdentitas, String tv, String jadwal) { | |
int row = -1; | |
int col = -1; | |
if (tv.equals("TV1")) { | |
col = 0; | |
} else if (tv.equals("TV2")) { | |
col = 1; | |
} else if (tv.equals("TV3")) { | |
col = 2; | |
} | |
if (jadwal.equals("07:00")) { | |
row = 0; | |
} else if (jadwal.equals("08:00")) { | |
row = 1; | |
} else if (jadwal.equals("09:00")) { | |
row = 2; | |
} | |
if (jadwalTV[row][col].equals("") || (isFILKOM(nomorIdentitas) && !isFILKOM(jadwalTV[row][col]))) { | |
jadwalTV[row][col] = nomorIdentitas; | |
} | |
} | |
private static boolean isFILKOM(String nomorIdentitas) { | |
if (nomorIdentitas.substring(2, 5).equals("515")) { | |
return true; | |
} | |
return false; | |
} | |
private static void printJadwalTable(String[][] jadwalTV) { | |
System.out.println("+--------+------------+------------+------------+"); | |
System.out.println("| Jadwal | TV1 | TV2 | TV3 |"); | |
System.out.println("+--------+------------+------------+------------+"); | |
for (int i = 0; i < 3; i++) { | |
System.out.printf("| %s |", "0" + (i + 7) + ":00"); | |
for (int j = 0; j < 3; j++) { | |
System.out.printf(" %-10s |", jadwalTV[i][j]); | |
} | |
System.out.println(); | |
} | |
System.out.println("+--------+------------+------------+------------+"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment