Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File: NoteAppInteractive.java
- import java.util.ArrayList;
- import java.util.Scanner;
- public class NoteAppInteractive {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayList<Note> notes = new ArrayList<>();
- int pilihan;
- do {
- System.out.println("\n=== Aplikasi Catatan Pribadi ===");
- System.out.println("1. Tambah Catatan");
- System.out.println("2. Lihat Semua Catatan");
- System.out.println("3. Keluar");
- System.out.print("Pilih menu: ");
- pilihan = scanner.nextInt();
- scanner.nextLine(); // membersihkan buffer enter
- switch (pilihan) {
- case 1:
- System.out.print("Masukkan judul catatan: ");
- String title = scanner.nextLine();
- System.out.print("Masukkan isi catatan: ");
- String content = scanner.nextLine();
- notes.add(new Note(title, content));
- System.out.println("✅ Catatan berhasil ditambahkan!");
- break;
- case 2:
- System.out.println("\n=== Daftar Catatan ===");
- if (notes.isEmpty()) {
- System.out.println("Belum ada catatan.");
- } else {
- for (int i = 0; i < notes.size(); i++) {
- System.out.println((i + 1) + ". ");
- notes.get(i).displayNote();
- }
- }
- break;
- case 3:
- System.out.println("Terima kasih telah menggunakan aplikasi catatan!");
- break;
- default:
- System.out.println("Pilihan tidak valid.");
- }
- } while (pilihan != 3);
- scanner.close();
- }
- }
- // Class Note dengan atribut title dan content
- class Note {
- private String title;
- private String content;
- // Constructor
- public Note(String title, String content) {
- this.title = title;
- this.content = content;
- }
- // Method untuk menampilkan catatan
- public void displayNote() {
- System.out.println("Judul : " + title);
- System.out.println("Isi : " + content);
- System.out.println("-----------------------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment