CSC103 - Semester Project
CSC103 - Semester Project
CSC103 - Semester Project
Semester Project
Title:
Submitted By:
Submitted to:
Mr. Muzaffar Iqbal
Table of Contents
Clothes Donation System.......................................................................................................................3
1. Description......................................................................................................................................3
1.1. Overview.................................................................................................................................3
1.4. Functionality............................................................................................................................4
2. Code................................................................................................................................................4
BSE-2-A 2
Semester Project Programming Fundamentals CSC103
1. Description
1.1. Overview
The Clothing Donation System is a Java-based console application designed to facilitate the donation
and management of clothing items. The system serves as a simple yet effective tool for users to
donate clothes, keep track of their contributions, and search for donated items based on various
criteria.
User Registration: Users can register and create an account by providing their username.
Clothing Donation: Users can donate clothing items by specifying details such as category (upper or
lower), size, quality, and gender. The system generates a random price for each donated item within
predefined ranges.
Data Persistence: All clothing donations are stored in a text file (clothesList.txt).
Search Functionality: Users can search for donated items based on gender, size, and quality. The
search results display relevant details about the items.
Previous Donations Display: Users can view a list of their previous donations, including item
details and the total estimated worth of their contributions.
Random Price Generation: The system employs a random price generation mechanism for each
donated item based on the mentioned quality.
Error Handling: The system includes error handling at various stages to prevent unexpected issues.
Registration:
Donation:
BSE-2-A 3
Semester Project Programming Fundamentals CSC103
The system calculates and displays the estimated worth of the donated item.
Search:
Users can search for donated items based on gender, size, and quality.
Previous Donations:
Users can view a list of their previous donations, including item details and total estimated
worth.
Exit:
1.4. Functionality
The program contains only one class, and that class implements the Clothes Donation System.
2. Code
import java.io.*;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Random;
import java.awt.Desktop;
import java.net.URI;
/**
* This class implements the Clothes Donation System.
* It allows users to donate clothes and view donated clothes and donation
organizations.
* <p>
BSE-2-A 4
Semester Project Programming Fundamentals CSC103
private ClothesDonationSystem() {
// Initialize ArrayLists
usersList = new ArrayList<>();
clothesList = new ArrayList<>();
donationCompaniesList = new ArrayList<>();
BSE-2-A 5
Semester Project Programming Fundamentals CSC103
}
}
BSE-2-A 6
Semester Project Programming Fundamentals CSC103
return username;
}
int choice;
try {
System.out.print("Enter your choice (1-5): ");
choice = scanner.nextInt();
switch (choice) {
case 1 -> donateClothes();
case 2 -> displayPreviousDonations(username);
case 3 -> viewDonationOrganizations();
case 4 -> searchItems();
case 5 -> {
System.out.println("Exiting the application. Goodbye!");
System.exit(0);
}
default -> System.out.println("Invalid choice. Please enter a
number between 1 and 5.");
}
} catch (Exception e) {
System.out.println("Invalid input. Please enter a valid number.");
scanner.nextLine(); // Consume the invalid input to prevent an
BSE-2-A 7
Semester Project Programming Fundamentals CSC103
infinite loop
}
System.out.println("Donation Menu:");
System.out.println("1. Uppers");
System.out.println("2. Lowers");
int choice;
try {
System.out.print("Pick a type (1 or 2): ");
choice = scanner.nextInt();
switch (choice) {
case 1 -> donateUppers();
case 2 -> donateLowers();
default -> System.out.println("Invalid choice. Please enter 1 or
2.");
}
} catch (Exception e) {
System.out.println("Invalid input. Please enter a valid number.");
scanner.nextLine(); // Consume the invalid input to prevent an
infinite loop
}
System.out.println("Uppers Menu:");
System.out.println("1. Shirts");
System.out.println("2. Hoodies");
System.out.println("3. Jackets");
int choice;
try {
System.out.print("Pick a category (1, 2, or 3): ");
choice = scanner.nextInt();
BSE-2-A 8
Semester Project Programming Fundamentals CSC103
System.out.println("Lowers Menu:");
System.out.println("1. Pants");
System.out.println("2. Trousers");
int choice;
try {
System.out.print("Pick a category (1 or 2): ");
choice = scanner.nextInt();
if (choice == 1 || choice == 2) {
String category = (choice == 1) ? "Pant" : "Trouser";
BSE-2-A 9
Semester Project Programming Fundamentals CSC103
saveClothesData();
do {
System.out.print("Enter size (XS, S, M, L, XL): ");
size = scanner.next().trim().toUpperCase();
} while (!size.matches("XS|S|M|L|XL"));
return size;
}
do {
System.out.print("Enter quality (L for Low, M for Medium, H for
High): ");
quality = scanner.next().trim().toUpperCase();
} while (!quality.matches("L|M|H"));
BSE-2-A 10
Semester Project Programming Fundamentals CSC103
do {
System.out.print("Enter gender (M for Male, F for Female, U for
Unisex): ");
gender = scanner.next().trim().toUpperCase();
} while (!gender.matches("M|F|U"));
// Generate a random value within the specified range with two decimal
places
double randomValue = basePrice + (random.nextDouble() * 10.0);
return Math.round(randomValue * 100.0) / 100.0;
}
if ("yes".equals(choice)) {
// Continue donating items
donateClothes();
} else if ("no".equals(choice)) {
// Go back to the main menu
displayMainMenu();
} else {
System.out.println("Invalid choice. Please enter 'yes' or 'no'.");
// Recursive call to ask for more donations again
askForMoreDonations();
}
}
BSE-2-A 11
Semester Project Programming Fundamentals CSC103
int itemCount = 0;
double totalEstimatedWorth = 0;
boolean found = false;
for (String item : clothesList) {
String[] itemDetails = item.split(", ");
String donorUsername = itemDetails[0].trim();
if (donorUsername.equals(username)) {
if (!found) {
System.out.printf("%-5s %-15s %-15s %-15s %-15s %-15s\n",
"Sr.", "Category", "Size", "Quality", "Gender",
"Estimated Price");
found = true;
}
System.out.println();
}
}
if (found) {
System.out.printf("Total estimated worth of all donations: $%.2f\
n", totalEstimatedWorth);
} else {
BSE-2-A 12
Semester Project Programming Fundamentals CSC103
int choice;
try {
System.out.print("Enter your choice (1-4): ");
choice = scanner.nextInt();
switch (choice) {
case 1 -> searchByGender(username);
case 2 -> searchBySize(username);
case 3 -> searchByQuality(username);
case 4 -> {
displayMainMenu();
return;
}
default -> System.out.println("Invalid choice. Please enter a
number between 1 and 4.");
}
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter a valid number.");
scanner.nextLine(); // Consume the invalid input to prevent an
infinite loop
}
if (!gender.matches("M|F|U")) {
System.out.println("Invalid gender. Please enter M, F, or
U.");
}
} while (!gender.matches("M|F|U"));
BSE-2-A 13
Semester Project Programming Fundamentals CSC103
gender);
};
int itemCount = 0;
boolean found = false;
System.out.println("Search results based on gender for '" + username
+ "':");
if (!found) {
System.out.println("No items found.");
}
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter a valid gender.");
}
if (!size.matches("XS|S|M|L|XL")) {
System.out.println("Invalid size. Please enter XS, S, M, L,
or XL.");
}
} while (!size.matches("XS|S|M|L|XL"));
int itemCount = 0;
boolean found = false;
System.out.println("Search results based on size for '" + username +
"':");
BSE-2-A 14
Semester Project Programming Fundamentals CSC103
if (!found) {
System.out.println("No items found.");
}
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter a valid size.");
}
try {
do {
System.out.print("Enter quality (L for Low, M for Medium, H for
High): ");
quality = scanner.next().toUpperCase();
if (!quality.matches("L|M|H")) {
System.out.println("Invalid quality. Please enter L, M, or
H.");
}
} while (!quality.matches("L|M|H"));
int itemCount = 0;
BSE-2-A 15
Semester Project Programming Fundamentals CSC103
if (!found) {
System.out.println("No items found.");
}
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter a valid quality.");
}
if ("yes".equals(choice)) {
// Continue searching items
searchItems();
} else if ("no".equals(choice)) {
// Go back to the main menu
displayMainMenu();
} else {
System.out.println("Invalid choice. Please enter 'yes' or 'no'.");
// Recursive call to ask for search again
askForSearchAgain();
}
}
BSE-2-A 16
Semester Project Programming Fundamentals CSC103
int choice;
String url;
try {
System.out.print("Enter your choice (1-5): ");
choice = scanner.nextInt();
switch (choice) {
case 1 -> {
url = donationCompaniesList.get(0);
openUrlForDonationOrganization(url);
}
case 2 -> {
url = donationCompaniesList.get(1);
openUrlForDonationOrganization(url);
}
case 3 -> {
url = donationCompaniesList.get(2);
openUrlForDonationOrganization(url);
}
case 4 -> {
url = donationCompaniesList.get(3);
openUrlForDonationOrganization(url);
}
case 5 -> displayMainMenu();
default -> System.out.println("Invalid choice. Please enter a
number between 1 and 5.");
}
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter a valid number.");
scanner.nextLine(); // Consume the invalid input to prevent an
infinite loop
}
https://github.com/Septic-H/Clothes-Donation-System
BSE-2-A 17