Evaluasi Akhir Semester

Nama = Alif Nurrohman

NRP = 5025231057

Kelas = PBO G


EAS : Project Perpustakaan


Soal  Evaluasi Akhir Semester

1. Apa yang dimaksud dengan Inheritance dalam Java. Bagaimana implementasi inheritance dalam Final Project yang sedang dikerjakan.
2. Jelaskan fitur Aplikasi yang ada dalam Final Project
3. Buatlah desain Diagram Kelas dari aplikasi Final Project

Soal : 4,5,6 Diluar blog
4. Implementasikan Aplikasi yang telah didesain dengan menggunakan Pemrograman Berbasis Obyek Java
5. Buat PPT presentasi yang menunjang Demo Aplikasi
6. Demokan aplikasi dengan membuat video dan diupload di Youtube.

Jawaban Evaluasi Akhir Semester

1. Apa yang dimaksud dengan Inheritance dalam Java

Inheritance dalam Java adalah salah satu konsep utama dalam Pemrograman Berorientasi Objek (OOP). Inheritance memungkinkan sebuah kelas (class) untuk mewarisi properti (fields) dan metode (methods) dari kelas lain.

Dengan inheritance, Anda dapat menciptakan hubungan "is-a" antara kelas. Kelas yang mewariskan properti disebut superclass atau parent class, sementara kelas yang menerima pewarisan disebut subclass atau child class.

Bagaimana implementasi inheritance dalam Final Project yang sedang dikerjakan?

Implementasi inhertance dalam FP yang kelompok kami kerjakan menggunakan library JFrame untuk menampilkan tampilkan pada java


Jadi, BookDetailsPage adalah subclass dari JFrame Sebagai super/ parent class

 class BookDetailsPage extends JFrame {
        public BookDetailsPage(Book book) {
            setTitle("Book Details - " + book.getTitle());
            setSize(600, 400);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setLayout(new BorderLayout(10, 10));
   
            // Panel Gambar Cover
            JLabel coverLabel = new JLabel(createImageIcon(book.getImagePath()));
            coverLabel.setHorizontalAlignment(SwingConstants.CENTER);
            add(coverLabel, BorderLayout.NORTH);
           
            String description = book.getDescription();
            String formattedDescription = description.replace("\n", "<br>");
            // Panel Informasi Buku
            JEditorPane bookInfoPane = new JEditorPane("text/html",
    "<html>" +
    "<b>Title:</b> " + book.getTitle() + "<br>" +
    "<b>Author:</b> " + book.getAuthor() + "<br>" +
    "<b>Year:</b> " + book.getYear() + "<br>" +
    "<b>Genres:</b> " + String.join(", ", book.getGenres()) + "<br><br>" +
    "<b>Description:</b><br>" + formattedDescription +
    "</html>"
);

Extends JFrame

BookDetailsPage adalah kelas yang mewarisi JFrame.

JFrame adalah sebuah kelas dalam pustaka Java Swing yang menyediakan jendela utama untuk aplikasi grafis berbasis GUI. Kelas ini digunakan untuk membuat antarmuka pengguna berbasis jendela yang dapat menampilkan komponen grafis seperti tombol, label, dan lainnya.

Dengan mewarisi JFrame, kelas BookDetailsPage dapat memiliki seluruh fungsionalitas yang disediakan oleh JFrame, seperti pengaturan ukuran jendela, penutupan jendela, pengaturan layout, dan menambahkan komponen UI.


2. Jelaskan fitur Aplikasi yang ada dalam Final Project

a. Searching Data
Pengguna dapat mencari buku yang diinginkan sesuai inputan dengan title

searchButton.addActionListener(e -> {
            String query = searchField.getText().toLowerCase();
            gridPanel.removeAll();
            for (Book book : books) {
                if (book.getTitle().toLowerCase().contains(query) || book.getAuthor().
                    toLowerCase().contains(query)) {
                    gridPanel.add(createBookPanel(book));
                }
            }
            gridPanel.revalidate();
            gridPanel.repaint();
        });


bSorting by Genre and A-Z
pengguna dapat mengurutkan sesuai genrenya

private JPanel createGenrePanel() {
        JPanel genrePanel = new JPanel(new BorderLayout());
        JPanel genreOptionsPanel = new JPanel(new GridLayout(0, 5, 10, 10));
        String[] genres = {
            "Action",
            "Adventure",
            "Comedy",
            "Demons",
            "Drama",
            "Ecchi",
            "Fantasy",
            "Game",
            "Harem",
            "Historical",
            "Horror",
            "Josei",
            "Magic",
            "Martial Arts",
            "Mecha",
            "Military",
            "Music",
            "Mystery",
            "Psychological",
            "Parody",
            "Police",
            "Romance",
            "Samurai",
            "School",
            "Sci-Fi",
            "Seinen",
            "Shoujo",
            "Shoujo Ai",
            "Shounen",
            "Slice of Life",
            "Sports",
            "Space",
            "Super Power",
            "Supernatural",
            "Thriller",
            "Vampire"
        };
       
        JPanel genreBooksPanel = new JPanel(new GridLayout(0, 4, 10, 10));

        for (String genre : genres) {
            JLabel genreLabel = new JLabel(genre);
            genreLabel.setForeground(Color.BLUE);
            genreLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            genreLabel.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    genreBooksPanel.removeAll();
                    for (Book book : books) {
                        if (book.getGenres().contains(genre)) {
                            genreBooksPanel.add(createBookPanel(book));
                        }
                    }
                    genreBooksPanel.revalidate();
                    genreBooksPanel.repaint();
                }
            });
            genreOptionsPanel.add(genreLabel);
        }

        genrePanel.add(genreOptionsPanel, BorderLayout.NORTH);
        genrePanel.add(new JScrollPane(genreBooksPanel), BorderLayout.CENTER);
        return genrePanel;
    }


3. CRUD (Create, Read, Update, and Delete)
pengguna dapat crud buku

class AddBookListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            JTextField titleField = new JTextField();
            JTextField authorField = new JTextField();
            JTextField yearField = new JTextField();
            JTextField genreField = new JTextField();
            JTextField imagePathField = new JTextField();
            JTextArea description = new JTextArea(5, 20);
            description.setLineWrap(true);  // Agar teks terbungkus jika panjang
            description.setWrapStyleWord(true);  // Agar teks terbungkus di kata,
            bukan di tengah
            JScrollPane descriptionScroll = new JScrollPane(description);

            Object[] inputFields = {
                "Title:", titleField, "Author:", authorField, "Year:", yearField,
                "Genres (comma-separated):", genreField, "Image Path:",
                imagePathField, "Descripton:", description
            };

            if (JOptionPane.showConfirmDialog(frame, inputFields, "Add Book",
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                List<String> genres = Arrays.asList(genreField.getText().split(","));
                books.add(new Book(titleField.getText(), authorField.getText(),
                yearField.getText(), genres, imagePathField.getText(),
                description.getText()));
                updateGridPanel();
            }
        }
    }
 class EditBookListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            String title = JOptionPane.showInputDialog(frame,
            "Enter the title of the book to edit:");
            if (title == null || title.isEmpty()) return;
            for (Book book : books) {
                if (book.getTitle().equalsIgnoreCase(title)) {
                    JTextField titleField = new JTextField(book.getTitle());
                    JTextField authorField = new JTextField(book.getAuthor());
                    JTextField yearField = new JTextField(book.getYear());
                    JTextField genreField = new JTextField(String.join(",",
                    book.getGenres()));
                    JTextField imagePathField = new JTextField(book.getImagePath());
                    JTextArea description = new JTextArea(book.getDescription());
                    description.setPreferredSize(new Dimension(200, 100));

                    Object[] inputFields = {
                        "Title:", titleField, "Author:", authorField, "Year:",
                        yearField,
                        "Genres (comma-separated):", genreField, "Image Path:",
                        imagePathField,
                        "Descriptoion:",  new JScrollPane(description)
                    };

                    if (JOptionPane.showConfirmDialog(frame, inputFields,
                        "Edit Book", JOptionPane.OK_CANCEL_OPTION) ==
                        JOptionPane.OK_OPTION) {
                        book.genres = Arrays.asList(genreField.getText().split(","));
                        // books.set(books.indexOf(book),
                        new Book(titleField.getText(), authorField.getText(),
                        yearField.getText(), book.genres, imagePathField.getText()));
                        book.setTitle(titleField.getText());
                        book.setAuthor(authorField.getText());
                        book.setYear(yearField.getText());
                        book.setGenres(Arrays.asList(genreField.getText().
                        split(",")));
                        book.setImagePath(imagePathField.getText());
                        book.setDescription(description.getText());

                        updateGridPanel();
                    }
                    return;
                }
            }
            JOptionPane.showMessageDialog(frame, "Book not found!");
        }
    }

    class DeleteBookListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            String title = JOptionPane.showInputDialog(frame, "Enter
            the title of the book to delete:");
            if (title == null || title.isEmpty()) return;
            books.removeIf(book -> book.getTitle().equalsIgnoreCase(title));
            updateGridPanel();
        }
    }



3. Diagram Class 



class LibraryManagerr {
    - JFrame frame
    - JTabbedPane tabbedPane
    - JPanel gridPanel
    - ArrayList<Book> books
    + LibraryManagerr()
    - JPanel createHomePanel()
    - JPanel createGenrePanel()
    - JPanel createAllBooksPanel()
    - void updateGridPanel()
    - JPanel createBookPanel(Book book)
    - void showBookDetails(Book book)
    - void updateBookListModel(DefaultListModel<String> bookListModel)
}

class Book {
    - String title
    - String author
    - String year
    - List<String> genres
    - String imagePath
    - String description
    + Book(String title, String author, String year, List<String> genres, String imagePath, String description)
    + String getTitle()
    + String getAuthor()
    + String getYear()
    + List<String> getGenres()
    + String getImagePath()
    + String getDescription()
    + void setTitle(String title)
    + void setAuthor(String author)
    + void setYear(String year)
    + void setGenres(List<String> genres)
    + void setImagePath(String imagePath)
    + void setDescription(String description)
}

class AddBookListener {
    + void actionPerformed(ActionEvent e)
}

class EditBookListener {
    + void actionPerformed(ActionEvent e)
}

class DeleteBookListener {
    + void actionPerformed(ActionEvent e)
}

class BookDetailsPage {
    + BookDetailsPage(Book book)
}

// Relationships
LibraryManagerr --> "1..*" Book
LibraryManagerr --> "1" AddBookListener
LibraryManagerr --> "1" EditBookListener
LibraryManagerr --> "1" DeleteBookListener
LibraryManagerr --> "1" BookDetailsPage






Komentar

Postingan populer dari blog ini

Evaluasi Tengah Semester

Tugas 14 - Pemrogramman GUI

Tugas 15 Final Project