fajarbaskoro80

NoteAppInteractive.java

Sep 15th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. // File: NoteAppInteractive.java
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. public class NoteAppInteractive {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. ArrayList<Note> notes = new ArrayList<>();
  9.  
  10. int pilihan;
  11. do {
  12. System.out.println("\n=== Aplikasi Catatan Pribadi ===");
  13. System.out.println("1. Tambah Catatan");
  14. System.out.println("2. Lihat Semua Catatan");
  15. System.out.println("3. Keluar");
  16. System.out.print("Pilih menu: ");
  17. pilihan = scanner.nextInt();
  18. scanner.nextLine(); // membersihkan buffer enter
  19.  
  20. switch (pilihan) {
  21. case 1:
  22. System.out.print("Masukkan judul catatan: ");
  23. String title = scanner.nextLine();
  24. System.out.print("Masukkan isi catatan: ");
  25. String content = scanner.nextLine();
  26.  
  27. notes.add(new Note(title, content));
  28. System.out.println("✅ Catatan berhasil ditambahkan!");
  29. break;
  30.  
  31. case 2:
  32. System.out.println("\n=== Daftar Catatan ===");
  33. if (notes.isEmpty()) {
  34. System.out.println("Belum ada catatan.");
  35. } else {
  36. for (int i = 0; i < notes.size(); i++) {
  37. System.out.println((i + 1) + ". ");
  38. notes.get(i).displayNote();
  39. }
  40. }
  41. break;
  42.  
  43. case 3:
  44. System.out.println("Terima kasih telah menggunakan aplikasi catatan!");
  45. break;
  46.  
  47. default:
  48. System.out.println("Pilihan tidak valid.");
  49. }
  50.  
  51. } while (pilihan != 3);
  52.  
  53. scanner.close();
  54. }
  55. }
  56.  
  57. // Class Note dengan atribut title dan content
  58. class Note {
  59. private String title;
  60. private String content;
  61.  
  62. // Constructor
  63. public Note(String title, String content) {
  64. this.title = title;
  65. this.content = content;
  66. }
  67.  
  68. // Method untuk menampilkan catatan
  69. public void displayNote() {
  70. System.out.println("Judul : " + title);
  71. System.out.println("Isi : " + content);
  72. System.out.println("-----------------------------");
  73. }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment