commit 1f2a330e69c4f7c2c62b32055b405fda9640b8c4 Author: Syahdan Date: Wed Aug 20 01:17:32 2025 +0700 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8780e86 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4a350e3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/remedial_syahdan.iml b/remedial_syahdan.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/remedial_syahdan.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Soal1_Calculator_SYAHDAN.java b/src/Soal1_Calculator_SYAHDAN.java new file mode 100644 index 0000000..dfb641b --- /dev/null +++ b/src/Soal1_Calculator_SYAHDAN.java @@ -0,0 +1,100 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class Soal1_Calculator_SYAHDAN extends JFrame implements ActionListener { + private JTextField bilangan1Field, bilangan2Field, hasilField; + private JButton tambahBtn, kurangBtn, kaliBtn, bagiBtn; + + public Soal1_Calculator_SYAHDAN() { + setTitle("CALCULATOR"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(400, 200); + setLocationRelativeTo(null); + + initComponents(); + layoutComponents(); + } + + private void initComponents() { + bilangan1Field = new JTextField(15); + bilangan2Field = new JTextField(15); + hasilField = new JTextField(15); + hasilField.setEditable(false); + + tambahBtn = new JButton("+"); + kurangBtn = new JButton("-"); + kaliBtn = new JButton("x"); + bagiBtn = new JButton(":"); + + tambahBtn.addActionListener(this); + kurangBtn.addActionListener(this); + kaliBtn.addActionListener(this); + bagiBtn.addActionListener(this); + } + + private void layoutComponents() { + setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(5, 5, 5, 5); + + gbc.gridx = 0; gbc.gridy = 0; + add(new JLabel("Bilangan1"), gbc); + gbc.gridx = 1; gbc.gridwidth = 3; + add(bilangan1Field, gbc); + + gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 1; + add(new JLabel("Bilangan2"), gbc); + gbc.gridx = 1; gbc.gridwidth = 3; + add(bilangan2Field, gbc); + + gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 1; + add(tambahBtn, gbc); + gbc.gridx = 1; + add(kurangBtn, gbc); + gbc.gridx = 2; + add(kaliBtn, gbc); + gbc.gridx = 3; + add(bagiBtn, gbc); + + gbc.gridx = 0; gbc.gridy = 3; + add(new JLabel("Hasil"), gbc); + gbc.gridx = 1; gbc.gridwidth = 3; + add(hasilField, gbc); + } + + @Override + public void actionPerformed(ActionEvent e) { + try { + double bil1 = Double.parseDouble(bilangan1Field.getText()); + double bil2 = Double.parseDouble(bilangan2Field.getText()); + double hasil = 0; + + if (e.getSource() == tambahBtn) { + hasil = bil1 + bil2; + } else if (e.getSource() == kurangBtn) { + hasil = bil1 - bil2; + } else if (e.getSource() == kaliBtn) { + hasil = bil1 * bil2; + } else if (e.getSource() == bagiBtn) { + if (bil2 != 0) { + hasil = bil1 / bil2; + } else { + hasilField.setText("Error: Division by zero"); + return; + } + } + + hasilField.setText(String.valueOf(hasil)); + } catch (NumberFormatException ex) { + hasilField.setText("Error: Invalid input"); + } + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + new Soal1_Calculator_SYAHDAN().setVisible(true); + }); + } +} \ No newline at end of file diff --git a/src/Soal2_Biodata_SYAHDAN.java b/src/Soal2_Biodata_SYAHDAN.java new file mode 100644 index 0000000..9c2b4c1 --- /dev/null +++ b/src/Soal2_Biodata_SYAHDAN.java @@ -0,0 +1,151 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class Soal2_Biodata_SYAHDAN extends JFrame implements ActionListener { + private JTextField namaField, alamatField; + private JRadioButton lakiRadio, perempuanRadio; + private ButtonGroup genderGroup; + private JComboBox agamaCombo; + private JTextArea outputArea; + private JButton simpanBtn, resetBtn; + private JLabel titleLabel; // Added title label + + public Soal2_Biodata_SYAHDAN() { + setTitle("BIODATA"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(400, 500); + setLocationRelativeTo(null); + + initComponents(); + layoutComponents(); + } + + private void initComponents() { + // Initialize title label + titleLabel = new JLabel("BIODATA", JLabel.CENTER); + titleLabel.setFont(new Font("Arial", Font.BOLD, 28)); + titleLabel.setForeground(new Color(0, 100, 200)); + + namaField = new JTextField(20); + alamatField = new JTextField(20); + + lakiRadio = new JRadioButton("Laki-laki"); + perempuanRadio = new JRadioButton("Perempuan"); + genderGroup = new ButtonGroup(); + genderGroup.add(lakiRadio); + genderGroup.add(perempuanRadio); + + String[] agamaList = {"Islam", "Kristen", "Katolik", "Hindu", "Buddha", "Konghucu"}; + agamaCombo = new JComboBox<>(agamaList); + + outputArea = new JTextArea(8, 30); + outputArea.setEditable(false); + outputArea.setBorder(BorderFactory.createLoweredBevelBorder()); + + simpanBtn = new JButton("Simpan"); + resetBtn = new JButton("Reset"); + + simpanBtn.addActionListener(this); + resetBtn.addActionListener(this); + } + + private void layoutComponents() { + setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(5, 5, 5, 5); + gbc.anchor = GridBagConstraints.WEST; + + // Title Label + gbc.gridx = 0; gbc.gridy = 0; + gbc.gridwidth = 2; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.CENTER; + add(titleLabel, gbc); + + // Reset for other components + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + gbc.anchor = GridBagConstraints.WEST; + + // Nama + gbc.gridx = 0; gbc.gridy = 1; + add(new JLabel("Nama"), gbc); + gbc.gridx = 1; + add(namaField, gbc); + + // Alamat + gbc.gridx = 0; gbc.gridy = 2; + add(new JLabel("Alamat"), gbc); + gbc.gridx = 1; + add(alamatField, gbc); + + // Gender + gbc.gridx = 0; gbc.gridy = 3; + add(new JLabel("Gender"), gbc); + gbc.gridx = 1; + JPanel genderPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + genderPanel.add(lakiRadio); + genderPanel.add(perempuanRadio); + add(genderPanel, gbc); + + // Agama + gbc.gridx = 0; gbc.gridy = 4; + add(new JLabel("Agama"), gbc); + gbc.gridx = 1; + add(agamaCombo, gbc); + + // Output Area + gbc.gridx = 0; gbc.gridy = 5; + gbc.gridwidth = 2; + gbc.fill = GridBagConstraints.BOTH; + add(new JScrollPane(outputArea), gbc); + + // Buttons + gbc.gridx = 0; gbc.gridy = 6; + gbc.gridwidth = 2; + gbc.fill = GridBagConstraints.NONE; + JPanel buttonPanel = new JPanel(new FlowLayout()); + buttonPanel.add(simpanBtn); + buttonPanel.add(resetBtn); + add(buttonPanel, gbc); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == simpanBtn) { + String nama = namaField.getText(); + String alamat = alamatField.getText(); + String gender = ""; + + if (lakiRadio.isSelected()) { + gender = "Laki-laki"; + } else if (perempuanRadio.isSelected()) { + gender = "Perempuan"; + } + + String agama = (String) agamaCombo.getSelectedItem(); + + String output = "Nama\t\t:" + nama + "\n" + + "Alamat\t\t:" + alamat + "\n" + + "Gender\t\t:" + gender + "\n" + + "Agama\t\t:" + agama; + + outputArea.setText(output); + + } else if (e.getSource() == resetBtn) { + namaField.setText(""); + alamatField.setText(""); + genderGroup.clearSelection(); + agamaCombo.setSelectedIndex(0); + outputArea.setText(""); + } + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + new Soal2_Biodata_SYAHDAN().setVisible(true); + }); + } +} \ No newline at end of file