├── AttendanceManagementSystem.java ├── Book.java ├── README.md └── Task3.java /AttendanceManagementSystem.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class AttendanceManagementSystem { 3 | 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | System.out.println("Attendance Management System"); 7 | System.out.println("Name:"); 8 | String name = scanner.nextLine(); 9 | 10 | // Get the student's ID number 11 | System.out.println("ID number:"); 12 | int id = scanner.nextInt(); 13 | 14 | // Get the student's attendance record 15 | System.out.println("Enter attendance record (1 for present, 0 for absent):"); 16 | int[] attendanceRecord = new int[10]; 17 | for (int i = 0; i < attendanceRecord.length; i++) { 18 | attendanceRecord[i] = scanner.nextInt(); 19 | } 20 | 21 | // Calculate the student's attendance percentage 22 | int totalAttendance = 0; 23 | for (int i = 0; i < attendanceRecord.length; i++) { 24 | totalAttendance += attendanceRecord[i]; 25 | } 26 | float attendancePercentage = (float) totalAttendance / attendanceRecord.length * 100; 27 | 28 | // Display the student's attendance record 29 | System.out.println("Here is your attendance record:"); 30 | for (int i = 0; i < attendanceRecord.length; i++) { 31 | System.out.println("Week " + (i + 1) + ": " + attendanceRecord[i]); 32 | } 33 | 34 | // Display the student's attendance percentage 35 | System.out.println("Your attendance percentage is " + attendancePercentage + "%."); 36 | 37 | // Determine the student's attendance status 38 | if (attendancePercentage >= 75) { 39 | System.out.println("You are in good standing."); 40 | } else { 41 | System.out.println("You are in danger of failing."); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Book.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | 5 | class Book { 6 | private int id; 7 | private String title; 8 | private String author; 9 | private double price; 10 | 11 | public Book(int id, String title, String author, double price) { 12 | this.id = id; 13 | this.title = title; 14 | this.author = author; 15 | this.price = price; 16 | } 17 | 18 | public int getId() { 19 | return id; 20 | } 21 | 22 | public String getTitle() { 23 | return title; 24 | } 25 | 26 | public double getPrice() { 27 | return price; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return id + ": " + title + " by " + author + " - $" + price; 33 | } 34 | } 35 | 36 | class ShoppingCart { 37 | private List items; 38 | 39 | public ShoppingCart() { 40 | items = new ArrayList<>(); 41 | } 42 | 43 | public void addItem(Book book) { 44 | items.add(book); 45 | } 46 | 47 | public void removeItem(Book book) { 48 | items.remove(book); 49 | } 50 | 51 | public void displayCart() { 52 | if (items.isEmpty()) { 53 | System.out.println("Your cart is empty."); 54 | } else { 55 | System.out.println("Shopping Cart:"); 56 | for (Book book : items) { 57 | System.out.println(book); 58 | } 59 | } 60 | } 61 | 62 | public double calculateTotalPrice() { 63 | double total = 0; 64 | for (Book book : items) { 65 | total += book.getPrice(); 66 | } 67 | return total; 68 | } 69 | } 70 | 71 | public class Task2 { 72 | private List catalog; 73 | private ShoppingCart cart; 74 | 75 | public Task2() { 76 | catalog = new ArrayList<>(); 77 | cart = new ShoppingCart(); 78 | } 79 | 80 | public void addBook(Book book) { 81 | catalog.add(book); 82 | } 83 | 84 | public void removeBook(int bookId) { 85 | catalog.removeIf(book -> book.getId() == bookId); 86 | cart.removeItem(findBookById(bookId)); 87 | } 88 | 89 | public Book findBookById(int bookId) { 90 | for (Book book : catalog) { 91 | if (book.getId() == bookId) { 92 | return book; 93 | } 94 | } 95 | return null; 96 | } 97 | 98 | public void displayCatalog() { 99 | System.out.println("Available Books:"); 100 | for (Book book : catalog) { 101 | System.out.println(book); 102 | } 103 | } 104 | 105 | public void addToCart(int bookId) { 106 | Book book = findBookById(bookId); 107 | if (book != null) { 108 | cart.addItem(book); 109 | System.out.println("Added to cart: " + book.getTitle()); 110 | } else { 111 | System.out.println("Book not found."); 112 | } 113 | } 114 | 115 | public void removeFromCart(int bookId) { 116 | Book book = findBookById(bookId); 117 | if (book != null) { 118 | cart.removeItem(book); 119 | System.out.println("Removed from cart: " + book.getTitle()); 120 | } else { 121 | System.out.println("Book not found in cart."); 122 | } 123 | } 124 | 125 | public void displayCart() { 126 | cart.displayCart(); 127 | System.out.println("Total Price: $" + cart.calculateTotalPrice()); 128 | } 129 | 130 | public static void main(String[] args) { 131 | Task2 bookstore = new Task2(); 132 | 133 | bookstore.addBook(new Book(1, "Book 1", "Author 1", 19.99)); 134 | bookstore.addBook(new Book(2, "Book 2", "Author 2", 14.99)); 135 | bookstore.addBook(new Book(3, "Book 3", "Author 3", 29.99)); 136 | 137 | Scanner scanner = new Scanner(System.in); 138 | 139 | while (true) { 140 | System.out.println("1. Display Book Catalog"); 141 | System.out.println("2. Add to Cart"); 142 | System.out.println("3. Remove from Cart"); 143 | System.out.println("4. Display Cart"); 144 | System.out.println("5. Exit"); 145 | System.out.print("Enter your choice: "); 146 | int choice = scanner.nextInt(); 147 | 148 | switch (choice) { 149 | case 1: 150 | bookstore.displayCatalog(); 151 | break; 152 | case 2: 153 | System.out.print("Enter the Book ID to add to cart: "); 154 | int addToCartId = scanner.nextInt(); 155 | bookstore.addToCart(addToCartId); 156 | break; 157 | case 3: 158 | System.out.print("Enter the Book ID to remove from cart: "); 159 | int removeFromCartId = scanner.nextInt(); 160 | bookstore.removeFromCart(removeFromCartId); 161 | break; 162 | case 4: 163 | bookstore.displayCart(); 164 | break; 165 | case 5: 166 | System.out.println("Thank you for shopping!!!"); 167 | System.exit(0); 168 | break; 169 | default: 170 | System.out.println("Invalid choice."); 171 | } 172 | } 173 | } 174 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeAlpha-JavaDevelopment -------------------------------------------------------------------------------- /Task3.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | 5 | enum BugStatus { 6 | OPEN, 7 | IN_PROGRESS, 8 | FIXED, 9 | CLOSED 10 | } 11 | 12 | class Bug { 13 | private static int nextId = 1; 14 | 15 | private int id; 16 | private String title; 17 | private String description; 18 | private BugStatus status; 19 | 20 | public Bug(String title, String description) { 21 | this.id = nextId++; 22 | this.title = title; 23 | this.description = description; 24 | this.status = BugStatus.OPEN; 25 | } 26 | 27 | public int getId() { 28 | return id; 29 | } 30 | 31 | public String getTitle() { 32 | return title; 33 | } 34 | 35 | public String getDescription() { 36 | return description; 37 | } 38 | 39 | public BugStatus getStatus() { 40 | return status; 41 | } 42 | 43 | public void setStatus(BugStatus status) { 44 | this.status = status; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "Bug #" + id + ": " + title + " (" + status + ")"; 50 | } 51 | } 52 | 53 | class User { 54 | private String username; 55 | private String role; 56 | 57 | public User(String username, String role) { 58 | this.username = username; 59 | this.role = role; 60 | } 61 | 62 | public String getUsername() { 63 | return username; 64 | } 65 | 66 | public String getRole() { 67 | return role; 68 | } 69 | } 70 | 71 | class Developer extends User { 72 | public Developer(String username) { 73 | super(username, "Developer"); 74 | } 75 | 76 | public void fixBug(Bug bug) { 77 | bug.setStatus(BugStatus.FIXED); 78 | } 79 | } 80 | 81 | class Admin extends User { 82 | public Admin(String username) { 83 | super(username, "Admin"); 84 | } 85 | 86 | public void assignBug(Bug bug, Developer developer) { 87 | bug.setStatus(BugStatus.IN_PROGRESS); 88 | System.out.println("Bug #" + bug.getId() + " assigned to " + developer.getUsername()); 89 | } 90 | } 91 | 92 | class Management extends User { 93 | public Management(String username) { 94 | super(username, "Management"); 95 | } 96 | 97 | public void closeBug(Bug bug) { 98 | bug.setStatus(BugStatus.CLOSED); 99 | } 100 | } 101 | 102 | public class Task3 { 103 | private List bugs; 104 | private List developers; 105 | private List admins; 106 | private List managers; 107 | private int nextBugId; 108 | 109 | public Task3() { 110 | bugs = new ArrayList<>(); 111 | developers = new ArrayList<>(); 112 | admins = new ArrayList<>(); 113 | managers = new ArrayList<>(); 114 | nextBugId = 1; 115 | } 116 | 117 | public void addBug(String title, String description) { 118 | Bug bug = new Bug(title, description); 119 | bugs.add(bug); 120 | } 121 | 122 | public void registerDeveloper(Developer developer) { 123 | developers.add(developer); 124 | } 125 | 126 | public void registerAdmin(Admin admin) { 127 | admins.add(admin); 128 | } 129 | 130 | public void registerManagement(Management management) { 131 | managers.add(management); 132 | } 133 | 134 | public void showBugList() { 135 | System.out.println("Bug List:"); 136 | for (Bug bug : bugs) { 137 | System.out.println(bug); 138 | } 139 | System.out.println(); 140 | } 141 | 142 | public static void main(String[] args) { 143 | Task3 bugTrackingSystem = new Task3(); 144 | Developer developer = new Developer("dev1"); 145 | Admin admin = new Admin("admin"); 146 | Management manager = new Management("manager"); 147 | 148 | bugTrackingSystem.registerDeveloper(developer); 149 | bugTrackingSystem.registerAdmin(admin); 150 | bugTrackingSystem.registerManagement(manager); 151 | 152 | Scanner scanner = new Scanner(System.in); 153 | 154 | while (true) { 155 | System.out.println("Bug Tracking System"); 156 | System.out.println("1. Report Bug"); 157 | System.out.println("2. Assign Bug"); 158 | System.out.println("3. Fix Bug"); 159 | System.out.println("4. Close Bug"); 160 | System.out.println("5. View Bugs"); 161 | System.out.println("6. Exit"); 162 | System.out.print("Select an option: "); 163 | int option = scanner.nextInt(); 164 | scanner.nextLine(); // Consume newline 165 | 166 | switch (option) { 167 | case 1: 168 | System.out.print("Bug Title: "); 169 | String title = scanner.nextLine(); 170 | System.out.print("Bug Description: "); 171 | String description = scanner.nextLine(); 172 | bugTrackingSystem.addBug(title, description); 173 | System.out.println("Bug reported.\n"); 174 | break; 175 | 176 | case 2: 177 | bugTrackingSystem.showBugList(); 178 | System.out.print("Bug ID: "); 179 | int bugId = scanner.nextInt(); 180 | Bug assignBug = bugTrackingSystem.bugs.stream() 181 | .filter(bug -> bug.getId() == bugId) 182 | .findFirst() 183 | .orElse(null); 184 | 185 | if (assignBug != null) { 186 | System.out.println("Available Developers:"); 187 | for (Developer dev : bugTrackingSystem.developers) { 188 | System.out.println(dev.getUsername()); 189 | } 190 | System.out.print("Select a developer: "); 191 | String devUsername = scanner.next(); 192 | Developer selectedDeveloper = bugTrackingSystem.developers.stream() 193 | .filter(dev -> dev.getUsername().equals(devUsername)) 194 | .findFirst() 195 | .orElse(null); 196 | 197 | if (selectedDeveloper != null) { 198 | admin.assignBug(assignBug, selectedDeveloper); 199 | System.out.println("Bug assigned.\n"); 200 | } else { 201 | System.out.println("Developer not found.\n"); 202 | } 203 | } else { 204 | System.out.println("Bug not found.\n"); 205 | } 206 | break; 207 | 208 | case 3: 209 | bugTrackingSystem.showBugList(); 210 | System.out.print("Bug ID: "); 211 | int fixBugId = scanner.nextInt(); 212 | Bug fixBug = bugTrackingSystem.bugs.stream() 213 | .filter(bug -> bug.getId() == fixBugId) 214 | .findFirst() 215 | .orElse(null); 216 | 217 | if (fixBug != null) { 218 | developer.fixBug(fixBug); 219 | System.out.println("Bug fixed.\n"); 220 | } else { 221 | System.out.println("Bug not found.\n"); 222 | } 223 | break; 224 | 225 | case 4: 226 | bugTrackingSystem.showBugList(); 227 | System.out.print("Bug ID: "); 228 | int closeBugId = scanner.nextInt(); 229 | Bug closeBug = bugTrackingSystem.bugs.stream() 230 | .filter(bug -> bug.getId() == closeBugId) 231 | .findFirst() 232 | .orElse(null); 233 | 234 | if (closeBug != null) { 235 | manager.closeBug(closeBug); 236 | System.out.println("Bug closed.\n"); 237 | } else { 238 | System.out.println("Bug not found.\n"); 239 | } 240 | break; 241 | 242 | case 5: 243 | bugTrackingSystem.showBugList(); 244 | break; 245 | 246 | case 6: 247 | System.out.println("Exiting Bug Tracking System."); 248 | System.exit(0); 249 | break; 250 | 251 | default: 252 | System.out.println("Invalid option.\n"); 253 | } 254 | } 255 | } 256 | } --------------------------------------------------------------------------------