├── Address Book ├── AddressBook.java └── README.md ├── Calculator ├── Calculator.java └── README.md ├── Contact Book ├── Contact.java └── README.md ├── File Encryption&Decryption ├── FileEncryptionDecryption.java └── README.md ├── Guessing game ├── Guessgame.java └── README.md ├── Hangman Game ├── HangmanGame.java └── README.md ├── Library Management System ├── LibraryManagementSystem.java ├── README.md └── library.txt ├── Quiz Application ├── QuizApplication.java ├── README.md └── questions.txt ├── README.md ├── Simple Bank Account ├── BankAccountManagementSystem.java └── README.md ├── Student Grade Calculator ├── README.md └── StudentGradeCalculator.java ├── Temperature Converter ├── README.md └── TemperatureConverter.java ├── Tic Tac Toe ├── README.md └── TicTacToe.java ├── Todo List App ├── README.md └── TodoListApp.java └── menu.java /Address Book/AddressBook.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class AddressBook { 5 | static ArrayList contacts = new ArrayList(); 6 | static Scanner input = new Scanner(System.in); 7 | 8 | public static void RunAddressBook(String[] args) { 9 | int choice; 10 | do { 11 | System.out.println("ADDRESS BOOK"); 12 | System.out.println("1. Add Contact"); 13 | System.out.println("2. View Contacts"); 14 | System.out.println("3. Search Contact"); 15 | System.out.println("4. Delete Contact"); 16 | System.out.println("5. Exit"); 17 | System.out.print("Enter your choice: "); 18 | choice = input.nextInt(); 19 | 20 | switch(choice) { 21 | case 1: 22 | addContact(); 23 | break; 24 | case 2: 25 | viewContacts(); 26 | break; 27 | case 3: 28 | searchContact(); 29 | break; 30 | case 4: 31 | deleteContact(); 32 | break; 33 | case 5: 34 | System.out.println("Exiting Address Book..."); 35 | break; 36 | default: 37 | System.out.println("Invalid choice!"); 38 | } 39 | } while(choice != 5); 40 | } 41 | 42 | public static void addContact() { 43 | System.out.print("Enter name: "); 44 | String name = input.next(); 45 | System.out.print("Enter address: "); 46 | String address = input.next(); 47 | System.out.print("Enter phone number: "); 48 | String phone = input.next(); 49 | System.out.print("Enter email: "); 50 | String email = input.next(); 51 | ContactAddress c = new ContactAddress(name, address, phone, email); 52 | contacts.add(c); 53 | System.out.println("Contact added successfully!"); 54 | } 55 | 56 | public static void viewContacts() { 57 | if(contacts.size() == 0) { 58 | System.out.println("No contacts found!"); 59 | return; 60 | } 61 | for(int i=0; i contacts; 43 | 44 | public ContactBook() { 45 | this.contacts = new ArrayList<>(); 46 | } 47 | 48 | public void addContact(String name, String phoneNumber, String email) { 49 | Contact contact = new Contact(name, phoneNumber, email); 50 | contacts.add(contact); 51 | System.out.println("Contact added successfully."); 52 | } 53 | 54 | public void viewContacts() { 55 | if (contacts.isEmpty()) { 56 | System.out.println("Contact book is empty."); 57 | } else { 58 | System.out.println("Contact List:"); 59 | for (int i = 0; i < contacts.size(); i++) { 60 | Contact contact = contacts.get(i); 61 | System.out.println((i + 1) + ". Name: " + contact.getName() + 62 | ", Phone: " + contact.getPhoneNumber() + 63 | ", Email: " + contact.getEmail()); 64 | } 65 | } 66 | } 67 | 68 | public void editContact(int index, String name, String phoneNumber, String email) { 69 | if (index >= 0 && index < contacts.size()) { 70 | Contact contact = contacts.get(index); 71 | contact.setName(name); 72 | contact.setPhoneNumber(phoneNumber); 73 | contact.setEmail(email); 74 | System.out.println("Contact updated successfully."); 75 | } else { 76 | System.out.println("Invalid contact index."); 77 | } 78 | } 79 | 80 | public void deleteContact(int index) { 81 | if (index >= 0 && index < contacts.size()) { 82 | Contact contact = contacts.remove(index); 83 | System.out.println("Contact deleted: " + contact.getName()); 84 | } else { 85 | System.out.println("Invalid contact index."); 86 | } 87 | } 88 | } 89 | 90 | public class ContactBookProgram { 91 | public static void RunContactBook(String[] args) { 92 | ContactBook contactBook = new ContactBook(); 93 | Scanner scanner = new Scanner(System.in); 94 | int choice = -1; 95 | 96 | while (choice != 0) { 97 | System.out.println("----- Contact Book -----"); 98 | System.out.println("1. Add a contact"); 99 | System.out.println("2. View contacts"); 100 | System.out.println("3. Edit a contact"); 101 | System.out.println("4. Delete a contact"); 102 | System.out.println("5. Exit"); 103 | System.out.print("Enter your choice: "); 104 | 105 | if (scanner.hasNextInt()) { 106 | choice = scanner.nextInt(); 107 | scanner.nextLine(); // Consume newline character 108 | System.out.println(); 109 | 110 | switch (choice) { 111 | case 1: 112 | System.out.print("Enter the name: "); 113 | String name = scanner.nextLine(); 114 | System.out.print("Enter the phone number: "); 115 | String phoneNumber = scanner.nextLine(); 116 | System.out.print("Enter the email: "); 117 | String email = scanner.nextLine(); 118 | contactBook.addContact(name, phoneNumber, email); 119 | System.out.println(); 120 | break; 121 | case 2: 122 | contactBook.viewContacts(); 123 | System.out.println(); 124 | break; 125 | case 3: 126 | System.out.print("Enter the index of the contact to edit: "); 127 | int editIndex = scanner.nextInt(); 128 | scanner.nextLine(); // Consume newline character 129 | System.out.print("Enter the new name: "); 130 | String newName = scanner.nextLine(); 131 | System.out.print("Enter the new phone number: "); 132 | String newPhoneNumber = scanner.nextLine(); 133 | System.out.print("Enter the new email: "); 134 | String newEmail = scanner.nextLine(); 135 | contactBook.editContact(editIndex - 1, newName, newPhoneNumber, newEmail); 136 | System.out.println(); 137 | break; 138 | case 4: 139 | System.out.print("Enter the index of the contact to delete: "); 140 | int deleteIndex = scanner.nextInt(); 141 | scanner.nextLine(); // Consume newline character 142 | contactBook.deleteContact(deleteIndex - 1); 143 | System.out.println(); 144 | break; 145 | case 5: 146 | return; 147 | default: 148 | System.out.println("Invalid choice. Please try again.\n"); 149 | } 150 | } else { 151 | System.out.println("Invalid input. Please try again.\n"); 152 | //scanner.nextLine(); // Consume invalid input 153 | } 154 | } 155 | 156 | scanner.close(); 157 | } 158 | } 159 | 160 | -------------------------------------------------------------------------------- /Contact Book/README.md: -------------------------------------------------------------------------------- 1 | # Contact Book 2 | The Contact Book is a simple Java program that allows users to store and manage a list of contacts. Users can add contacts, view the list of contacts, edit existing contacts, and delete contacts. 3 | 4 | ## Features 5 | - Add a contact: Users can add a new contact by providing the name, phone number, and email. 6 | - View contacts: Users can view the list of contacts stored in the Contact Book. 7 | - Edit a contact: Users can edit the details of an existing contact, including the name, phone number, and email. 8 | - Delete a contact: Users can delete a contact from the Contact Book. 9 | 10 | ## Usage 11 | 1. Compile the Java source code: `javac ContactBookProgram.java` 12 | 2. Run the application: `java ContactBookProgram` 13 | 3. Follow the prompts in the command-line interface to interact with the Contact Book. 14 | 4. Enter `0` to exit the application. 15 | 16 | ## Note 17 | This implementation of the Contact Book is a basic version and does not include advanced features such as contact search or persistent data storage. It serves as a starting point that can be enhanced and customized as per specific requirements. 18 | 19 | Feel free to modify and extend the code to suit your needs. 20 | 21 | ## Contributing 22 | Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. 23 | 24 | ## Credits 25 | This project is created by Kalutu Daniel. 26 | -------------------------------------------------------------------------------- /File Encryption&Decryption/FileEncryptionDecryption.java: -------------------------------------------------------------------------------- 1 | import javax.crypto.Cipher; 2 | import javax.crypto.spec.SecretKeySpec; 3 | import java.io.*; 4 | import java.nio.file.Files; 5 | import java.nio.file.Paths; 6 | import java.security.Key; 7 | 8 | public class FileEncryptionDecryption { 9 | 10 | private static final String AES_ALGORITHM = "AES"; 11 | private static final String ENCRYPTED_FILE_EXTENSION = ".enc"; 12 | 13 | public static void RunFileEncryptionDecryption(String[] args) { 14 | try { 15 | // Read user input 16 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 17 | System.out.print("Enter file path: "); 18 | String filePath = reader.readLine(); 19 | 20 | System.out.print("Enter encryption key: "); 21 | String encryptionKey = reader.readLine(); 22 | 23 | System.out.print("Encrypt (E) or Decrypt (D): "); 24 | String mode = reader.readLine(); 25 | 26 | if (mode.equalsIgnoreCase("E")) { 27 | encryptFile(filePath, encryptionKey); 28 | System.out.println("File encrypted successfully!"); 29 | } else if (mode.equalsIgnoreCase("D")) { 30 | decryptFile(filePath, encryptionKey); 31 | System.out.println("File decrypted successfully!"); 32 | } else { 33 | System.out.println("Invalid mode selected."); 34 | } 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | private static void encryptFile(String filePath, String encryptionKey) throws Exception { 41 | byte[] fileContent = Files.readAllBytes(Paths.get(filePath)); 42 | 43 | Key key = generateKey(encryptionKey); 44 | Cipher cipher = Cipher.getInstance(AES_ALGORITHM); 45 | cipher.init(Cipher.ENCRYPT_MODE, key); 46 | 47 | byte[] encryptedContent = cipher.doFinal(fileContent); 48 | 49 | String encryptedFilePath = filePath + ENCRYPTED_FILE_EXTENSION; 50 | FileOutputStream outputStream = new FileOutputStream(encryptedFilePath); 51 | outputStream.write(encryptedContent); 52 | outputStream.close(); 53 | } 54 | 55 | private static void decryptFile(String filePath, String encryptionKey) throws Exception { 56 | byte[] encryptedContent = Files.readAllBytes(Paths.get(filePath)); 57 | 58 | Key key = generateKey(encryptionKey); 59 | Cipher cipher = Cipher.getInstance(AES_ALGORITHM); 60 | cipher.init(Cipher.DECRYPT_MODE, key); 61 | 62 | byte[] decryptedContent = cipher.doFinal(encryptedContent); 63 | 64 | String decryptedFilePath = filePath.replace(ENCRYPTED_FILE_EXTENSION, ""); 65 | FileOutputStream outputStream = new FileOutputStream(decryptedFilePath); 66 | outputStream.write(decryptedContent); 67 | outputStream.close(); 68 | } 69 | 70 | private static Key generateKey(String encryptionKey) throws Exception { 71 | byte[] keyBytes = encryptionKey.getBytes(); 72 | return new SecretKeySpec(keyBytes, AES_ALGORITHM); 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /File Encryption&Decryption/README.md: -------------------------------------------------------------------------------- 1 | # File Encryption/Decryption 2 | This Java project allows users to encrypt or decrypt files using the AES encryption algorithm. 3 | 4 | ## Features 5 | - Encrypt files using AES encryption 6 | - Decrypt files using AES decryption 7 | 8 | ## Installation 9 | 1. Clone the repository 10 | 2. Open the project in your preferred IDE. 11 | 3. Build the project. 12 | 13 | ## Usage 14 | 1. Launch the application. 15 | 2. Enter the file path of the file you want to encrypt or decrypt. 16 | 3. Enter the encryption key. 17 | 4. Specify the mode (Encrypt (E) or Decrypt (D)). 18 | 5. Press enter to start the encryption or decryption process. 19 | 6. The encrypted or decrypted file will be saved in the same directory as the original file. 20 | 21 | ## Contributing 22 | Contributions are welcome! Here are the steps to contribute to the project: 23 | 1. Fork the repository. 24 | 2. Create a new branch for your feature or bug fix. 25 | 3. Make the necessary changes and commit them. 26 | 4. Push your changes to your forked repository. 27 | 5. Submit a pull request to the main repository. 28 | 29 | ## Credits 30 | 31 | This project is created by Kalutu Daniel. 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Guessing game/Guessgame.java: -------------------------------------------------------------------------------- 1 | import java.util.InputMismatchException; // Import class for handling invalid input 2 | import java.util.Random; 3 | import java.util.Scanner; 4 | 5 | public class GuessGame { 6 | 7 | // Constants for the range of numbers 8 | private static final int MIN = 1; 9 | private static final int MAX = 100; 10 | 11 | public static void RunGuessGame(String[] args) { 12 | Scanner input = new Scanner(System.in); 13 | 14 | // let users select a difficulty level: 15 | try { 16 | System.out.println("Choose a difficulty level: "); 17 | System.out.println("1. Easy (1-50)"); 18 | System.out.println("2. Medium (1-100)"); 19 | System.out.println("3. Hard (1-200)"); 20 | int difficulty = input.nextInt(); 21 | 22 | switch (difficulty) { 23 | case 1: 24 | MAX = 50; break; 25 | case 2: 26 | MAX = 100; break; 27 | case 3: 28 | MAX = 200; break; 29 | default: 30 | System.out.println("Invalid choice. Defaulting to Medium."); 31 | MAX = 100; 32 | } 33 | 34 | // Main game loop allowing the user to play multiple times 35 | while (true) { 36 | playGame(input); 37 | if(!playAgain(input)) { 38 | //input.close(); // Close the scanner after use 39 | return; 40 | } 41 | } finally { 42 | input.close(); // Ensures scanner is closed 43 | } 44 | // Check if the user wants to play again 45 | 46 | } 47 | 48 | /** 49 | * Runs the game where the user has to guess the number. 50 | */ 51 | private static void playGame(Scanner input) { 52 | Random rand = new Random(); 53 | int randomNumber = rand.nextInt(MAX - MIN + 1) + MIN; // Generate a random number in the range [MIN, MAX] 54 | int guess; 55 | int numGuesses = 0; 56 | boolean correct = false; 57 | 58 | System.out.print("Guess a number between " + MIN + " and " + MAX + ": "); 59 | 60 | while (!correct) { 61 | try { 62 | guess = input.nextInt(); // Read user input 63 | numGuesses++; 64 | 65 | if (guess == randomNumber) { 66 | System.out.println("Congratulations! You guessed the number in " + numGuesses + " guesses."); 67 | correct = true; 68 | } else if (guess < randomNumber) { 69 | System.out.print("Too low, try again:"); // Hint if the guess is too low 70 | } else { 71 | System.out.print("Too high, try again:"); // Hint if the guess is too high 72 | } 73 | 74 | } catch (InputMismatchException e) { 75 | // Handle the case where the input is not a valid number 76 | System.out.print("Invalid input. Please enter a valid number between " + MIN + " and " + MAX + "."); 77 | input.next(); // Clear the invalid input 78 | } 79 | // The InputMismatchException already handles invalid inputs, so this general catch block is unnecessary: 80 | // catch (Exception e) {} 81 | 82 | } 83 | } 84 | 85 | /** 86 | * Asks the user if they want to play again. 87 | * @return true if the user wants to play again; false otherwise. 88 | */ 89 | private static boolean playAgain(Scanner input) { 90 | while (true) { 91 | System.out.print("Do you want to play again? (yes/no): "); 92 | String response = input.next().trim().toLowerCase(); 93 | if (response.equals("yes") || response.equals("y")) { 94 | return true; 95 | } else if (response.equals("no") || response.equals("n")) { 96 | return false; 97 | } else { 98 | System.out.println("Invalid response. Please type 'yes' or 'no'."); 99 | } 100 | } 101 | } 102 | 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /Guessing game/README.md: -------------------------------------------------------------------------------- 1 | # Guessing Game 2 | This is a simple guessing game implemented in Java. The computer generates a random number between 1 and 100, and the user has to guess the number. After each guess, the program tells the user whether their guess was too high or too low. Once the user guesses the correct number, the program tells them how many guesses it took and ends the game. 3 | 4 | ## How to Play 5 | To play the game, follow these steps: 6 | - Download or clone the repository to your local machine. 7 | - Open the project in your favorite Java IDE or editor. 8 | - Compile and run the GuessingGame.java file. 9 | - The program will ask you to choose a difficulty level: Easy (1-50) || Medium (1-100) || Hard (1-200). 10 | - Once you choose a difficulty level, the program will generate a random number within the chosen range. 11 | - Enter your guess and press Enter. 12 | - The program will tell you whether your guess was too high or too low. 13 | - Keep guessing until you guess the correct number. 14 | - Once you guess the correct number, the program will tell you how many guesses it took and end the game. 15 | 16 | ## Contributing 17 | Contributions to this project are welcome. If you find a bug or have a suggestion for improvement, please open an issue or submit a pull request. 18 | 19 | ## Credits 20 | This project was created by Kalutu Daniel. 21 | 22 | -------------------------------------------------------------------------------- /Hangman Game/HangmanGame.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Map; 3 | import java.util.HashMap; 4 | // Tells the code to use Map and HashMap 5 | 6 | public class HangmanGame { 7 | private static final String[] WORDS = {"love", "joy", "peace", "patience", "kindness", "faithfulness"}; 8 | //New words that are Fruits of the Spritit to prompt Bible verses 9 | 10 | private static final Map VERSES = new HashMap(); 11 | //Links all words to a specific Bible verse 12 | 13 | private static String word; 14 | private static StringBuilder guessedWord; 15 | private static int attemptsLeft; 16 | 17 | public static void main(String[] args) { 18 | initializeVerses(); 19 | //Loads Bible verses into the created HashMap so that there is something to pull from 20 | play(); 21 | } 22 | 23 | public static void play() { 24 | initializeGame(); 25 | 26 | while (attemptsLeft > 0 && guessedWord.indexOf("_") != -1) { 27 | System.out.println("\nAttempts left: " + attemptsLeft); 28 | System.out.println("Word: " + guessedWord.toString()); 29 | 30 | char guess = getGuessFromPlayer(); 31 | checkGuess(guess); 32 | } 33 | 34 | if (guessedWord.indexOf("_") == -1) { 35 | System.out.println("\nCongratulations! You guessed the word: " + word); 36 | printVerse(word); 37 | //Calls to also output a Bible verse in addition the word that was successfully guessed 38 | } else { 39 | System.out.println("\nGame over! You ran out of attempts. The word was: " + word); 40 | } 41 | } 42 | 43 | private static void initializeGame() { 44 | word = getRandomWord(); 45 | guessedWord = new StringBuilder(word.length()); 46 | 47 | for (int i = 0; i < word.length(); i++) { 48 | guessedWord.append("_"); 49 | } 50 | 51 | attemptsLeft = 6; 52 | } 53 | 54 | private static String getRandomWord() { 55 | int index = (int) (Math.random() * WORDS.length); 56 | return WORDS[index]; 57 | } 58 | 59 | private static char getGuessFromPlayer() { 60 | Scanner scanner = new Scanner(System.in); 61 | 62 | System.out.print("Enter your guess: "); 63 | String input = scanner.nextLine().toLowerCase(); 64 | 65 | while (input.length() != 1 || !Character.isLetter(input.charAt(0))) { 66 | System.out.println("Invalid guess. Please enter a single letter."); 67 | System.out.print("Enter your guess: "); 68 | input = scanner.nextLine().toLowerCase(); 69 | } 70 | 71 | return input.charAt(0); 72 | } 73 | 74 | private static void checkGuess(char guess) { 75 | boolean guessedCorrectly = false; 76 | 77 | for (int i = 0; i < word.length(); i++) { 78 | if (word.charAt(i) == guess) { 79 | guessedWord.setCharAt(i, guess); 80 | guessedCorrectly = true; 81 | } 82 | } 83 | 84 | if (guessedCorrectly) { 85 | System.out.println("Correct guess!"); 86 | } else { 87 | System.out.println("Incorrect guess!"); 88 | attemptsLeft--; 89 | } 90 | } 91 | 92 | private static void initializeVerses() { 93 | VERSES.put("love","John 3:16 - For God so loved the world that He gave his one and only Son, that whoever believes in Him shall not perish but have eternal life."); 94 | VERSES.put("joy","1 Thessalonians 5:16-18 - Rejoice always, pray continually, give thanks in all circumstances; for this is God's will for you in Christ Jesus."); 95 | VERSES.put("peace","Matthew 5:9 - Blessed are the peacemakers, for they will be called children of God."); 96 | VERSES.put("patience","Ephesians 4:2 - Be completely humble and gentle; be patient, bearing with one another in love."); 97 | VERSES.put("kindness","Ephesians 4:32 - Be kind to one another, tenderhearted, forgiving one another, as God in Christ forgave you."); 98 | VERSES.put("faithfulness","2 Corinthians 5:7 - For we live by faith, not by sight."); 99 | //Loads up the Bible verses and the Fruit of the Spirit into the HashMap so they are paired correctly 100 | 101 | } 102 | 103 | private static void printVerse(String word) { 104 | String verse = VERSES.get(word); 105 | if (verse != null) { 106 | System.out.println("Bible Reference: " + verse); 107 | //Searches for the verse matching with the word that was guessed in the HashMap and prints it 108 | } else { 109 | System.out.println("/nNo verse available"); 110 | //If no verse is found for a word, "No verse available" will be output 111 | 112 | } 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /Hangman Game/README.md: -------------------------------------------------------------------------------- 1 | # Hangman Game 2 | A text-based implementation of the classic Hangman game in Java. 3 | 4 | ## Introduction 5 | Hangman is a guessing game where the player must guess a word by suggesting letters within a certain number of attempts. This implementation allows you to play Hangman in the console. 6 | 7 | ## How to Play 8 | 1. The program selects a random word from a predefined list of words. 9 | 2. The player has to guess the letters in the word one by one. 10 | 3. For each incorrect guess, a part of the hangman is drawn. The player must guess the word before the hangman is completed. 11 | 4. The game continues until the player guesses the word correctly or runs out of attempts. 12 | 13 | ## Prerequisites 14 | - Java Development Kit (JDK) installed on your machine. 15 | 16 | ## How to Run 17 | 1. Clone this repository or download the source code files. 18 | 2. Open a command prompt or terminal and navigate to the project directory. 19 | 3. Compile the Java source file by running the following command: 20 | ``` 21 | javac HangmanGame.java 22 | ``` 23 | 4. Run the compiled program using the following command: 24 | ``` 25 | java HangmanGame 26 | ``` 27 | 28 | ## Contributing 29 | Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. 30 | 31 | ## Credits 32 | This project is created by Kalutu Daniel. 33 | 34 | -------------------------------------------------------------------------------- /Library Management System/LibraryManagementSystem.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | class Book { 5 | private String title; 6 | private String author; 7 | private boolean checkedOut; 8 | 9 | public Book(String title, String author) { 10 | this.title = title; 11 | this.author = author; 12 | this.checkedOut = false; 13 | } 14 | 15 | public String getTitle() { 16 | return title; 17 | } 18 | 19 | public String getAuthor() { 20 | return author; 21 | } 22 | 23 | public boolean isCheckedOut() { 24 | return checkedOut; 25 | } 26 | 27 | public void setCheckedOut(boolean checkedOut) { 28 | this.checkedOut = checkedOut; 29 | } 30 | } 31 | 32 | class Library { 33 | private List books; 34 | 35 | public Library() { 36 | this.books = new ArrayList<>(); 37 | } 38 | 39 | public void addBook(String title, String author) { 40 | Book book = new Book(title, author); 41 | books.add(book); 42 | } 43 | 44 | public void searchBook(String keyword) { 45 | List searchResults = new ArrayList<>(); 46 | 47 | for (Book book : books) { 48 | if (book.getTitle().contains(keyword) || book.getAuthor().contains(keyword)) { 49 | searchResults.add(book); 50 | } 51 | } 52 | 53 | if (searchResults.isEmpty()) { 54 | System.out.println("No books found matching the search keyword."); 55 | } else { 56 | System.out.println("Search results:"); 57 | for (Book book : searchResults) { 58 | System.out.println(book.getTitle() + " by " + book.getAuthor()); 59 | } 60 | } 61 | } 62 | 63 | public void checkoutBook(String title) { 64 | for (Book book : books) { 65 | if (book.getTitle().equals(title)) { 66 | if (!book.isCheckedOut()) { 67 | book.setCheckedOut(true); 68 | System.out.println("Book '" + title + "' checked out successfully."); 69 | } else { 70 | System.out.println("Book '" + title + "' is already checked out."); 71 | } 72 | return; 73 | } 74 | } 75 | 76 | System.out.println("Book '" + title + "' not found in the library."); 77 | } 78 | 79 | public void returnBook(String title) { 80 | for (Book book : books) { 81 | if (book.getTitle().equals(title)) { 82 | if (book.isCheckedOut()) { 83 | book.setCheckedOut(false); 84 | System.out.println("Book '" + title + "' returned successfully."); 85 | } else { 86 | System.out.println("Book '" + title + "' is not checked out."); 87 | } 88 | return; 89 | } 90 | } 91 | 92 | System.out.println("Book '" + title + "' not found in the library."); 93 | } 94 | 95 | public void saveBooksToFile(String filename) { 96 | try (PrintWriter writer = new PrintWriter(filename)) { 97 | for (Book book : books) { 98 | writer.println(book.getTitle() + "," + book.getAuthor() + "," + book.isCheckedOut()); 99 | } 100 | System.out.println("Books saved to file: " + filename); 101 | } catch (IOException e) { 102 | System.out.println("Error saving books to file: " + e.getMessage()); 103 | } 104 | } 105 | 106 | public void loadBooksFromFile(String filename) { 107 | try (Scanner scanner = new Scanner(new File(filename))) { 108 | books.clear(); 109 | while (scanner.hasNextLine()) { 110 | String line = scanner.nextLine(); 111 | String[] parts = line.split(","); 112 | String title = parts[0]; 113 | String author = parts[1]; 114 | boolean checkedOut = Boolean.parseBoolean(parts[2]); 115 | Book book = new Book(title, author); 116 | book.setCheckedOut(checkedOut); 117 | books.add(book); 118 | } 119 | System.out.println("Books loaded from file: " + filename); 120 | } catch (FileNotFoundException e) { 121 | System.out.println("File not found: " + filename); 122 | } 123 | } 124 | } 125 | 126 | public class LibraryManagementSystem { 127 | public static void RunLibraryManagementSystem(String[] args) { 128 | Library library = new Library(); 129 | 130 | // Loading books from a file (if available) 131 | library.loadBooksFromFile("library.txt"); 132 | 133 | Scanner scanner = new Scanner(System.in); 134 | int choice = -1; 135 | 136 | while (choice != 0) { 137 | System.out.println("----- Library Management System -----"); 138 | System.out.println("1. Add a book"); 139 | System.out.println("2. Search for books"); 140 | System.out.println("3. Check out a book"); 141 | System.out.println("4. Return a book"); 142 | System.out.println("0. Exit"); 143 | System.out.print("Enter your choice: "); 144 | 145 | if (scanner.hasNextInt()) { 146 | choice = scanner.nextInt(); 147 | scanner.nextLine(); // Consume newline character 148 | System.out.println(); 149 | 150 | switch (choice) { 151 | case 1: 152 | System.out.print("Enter the title of the book: "); 153 | String title = scanner.nextLine(); 154 | System.out.print("Enter the author of the book: "); 155 | String author = scanner.nextLine(); 156 | library.addBook(title, author); 157 | System.out.println("Book added successfully.\n"); 158 | break; 159 | case 2: 160 | System.out.print("Enter the search keyword: "); 161 | String keyword = scanner.nextLine(); 162 | library.searchBook(keyword); 163 | System.out.println(); 164 | break; 165 | case 3: 166 | System.out.print("Enter the title of the book to check out: "); 167 | String checkoutTitle = scanner.nextLine(); 168 | library.checkoutBook(checkoutTitle); 169 | System.out.println(); 170 | break; 171 | case 4: 172 | System.out.print("Enter the title of the book to return: "); 173 | String returnTitle = scanner.nextLine(); 174 | library.returnBook(returnTitle); 175 | System.out.println(); 176 | break; 177 | case 0: 178 | // Saving books to a file 179 | library.saveBooksToFile("library.txt"); 180 | break; 181 | default: 182 | System.out.println("Invalid choice. Please try again.\n"); 183 | } 184 | } else { 185 | System.out.println("Invalid input. Please try again.\n"); 186 | scanner.nextLine(); // Consume invalid input 187 | } 188 | } 189 | 190 | // scanner.close(); 191 | } 192 | } 193 | 194 | -------------------------------------------------------------------------------- /Library Management System/README.md: -------------------------------------------------------------------------------- 1 | # Library Management System 2 | The Library Management System is a basic Java application that allows users to manage a library by adding books, searching for books, checking out books, and returning books. The book details are stored in a file. 3 | 4 | ## Features 5 | - Add a book: Users can add a new book to the library by providing the title and author. 6 | - Search for books: Users can search for books by entering a keyword. The system will display a list of books matching the keyword. 7 | - Check out a book: Users can check out a book by specifying its title. If the book is available, it will be marked as checked out. 8 | - Return a book: Users can return a checked-out book by specifying its title. The book will be marked as available. 9 | 10 | ## Usage 11 | 1. Compile the Java source code: `javac LibraryManagementSystem.java` 12 | 2. Run the application: `java LibraryManagementSystem` 13 | 3. Follow the prompts in the command-line interface to interact with the Library Management System. 14 | 4. Enter `0` to exit the application. The book details will be automatically saved to the file. 15 | 16 | ## File Storage 17 | The book details are stored in a file named `library.txt`. The file follows a comma-separated format where each line represents a book and contains the title, author, and checkout status (true/false). 18 | 19 | To customize the file name or location, modify the code in `Library.java` where the `saveBooksToFile()` and `loadBooksFromFile()` methods are called. 20 | 21 | ## Note 22 | This implementation is a basic version of a library management system and does not include advanced features such as user authentication, database integration, or error handling. It serves as a starting point that can be enhanced and customized as per specific requirements. 23 | 24 | Feel free to modify and extend the code to suit your needs. 25 | 26 | ## Contributing 27 | Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. 28 | 29 | ## Credits 30 | This project is created by Kalutu Daniel. 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Library Management System/library.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Quiz Application/QuizApplication.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileNotFoundException; 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | class Question { 8 | private String questionText; 9 | private String optionA; 10 | private String optionB; 11 | private String optionC; 12 | private String optionD; 13 | private String correctAnswer; 14 | 15 | public Question(String questionText, String optionA, String optionB, String optionC, String optionD, String correctAnswer) { 16 | this.questionText = questionText; 17 | this.optionA = optionA; 18 | this.optionB = optionB; 19 | this.optionC = optionC; 20 | this.optionD = optionD; 21 | this.correctAnswer = correctAnswer; 22 | } 23 | 24 | public String getQuestionText() { 25 | return questionText; 26 | } 27 | 28 | public String getOptionA() { 29 | return optionA; 30 | } 31 | 32 | public String getOptionB() { 33 | return optionB; 34 | } 35 | 36 | public String getOptionC() { 37 | return optionC; 38 | } 39 | 40 | public String getOptionD() { 41 | return optionD; 42 | } 43 | 44 | public boolean isCorrectAnswer(String answer) { 45 | return correctAnswer.equalsIgnoreCase(answer); 46 | } 47 | } 48 | 49 | public class QuizApplication { 50 | private static final String QUESTIONS_FILE = "questions.txt"; 51 | private static final int SCORE_PER_QUESTION = 10; 52 | 53 | private List questions; 54 | private int score; 55 | 56 | public void loadQuestions() throws FileNotFoundException { 57 | File file = new File(QUESTIONS_FILE); 58 | Scanner scanner = new Scanner(file); 59 | 60 | questions = new ArrayList<>(); 61 | 62 | int lineCount = 1; 63 | while (scanner.hasNextLine()) { 64 | String line = scanner.nextLine().trim(); 65 | 66 | if (line.startsWith("Question:")) { 67 | String questionText = extractContent(line); 68 | String optionAText = extractContent(scanner.nextLine()); 69 | String optionBText = extractContent(scanner.nextLine()); 70 | String optionCText = extractContent(scanner.nextLine()); 71 | String optionDText = extractContent(scanner.nextLine()); 72 | String correctAnswer = extractContent(scanner.nextLine()); 73 | 74 | Question question = new Question(questionText, optionAText, optionBText, optionCText, optionDText, correctAnswer); 75 | questions.add(question); 76 | } else { 77 | System.out.println("Invalid question format at line " + lineCount); 78 | } 79 | 80 | lineCount++; 81 | } 82 | 83 | scanner.close(); 84 | } 85 | 86 | private String extractContent(String line) { 87 | int colonIndex = line.indexOf(":"); 88 | if (colonIndex != -1) { 89 | return line.substring(colonIndex + 1).trim(); 90 | } else { 91 | System.out.println("Invalid format in line: " + line); 92 | return ""; 93 | } 94 | } 95 | 96 | public void startQuiz() { 97 | score = 0; 98 | 99 | System.out.println("Welcome to the Quiz Application!\n"); 100 | 101 | for (int i = 0; i < questions.size(); i++) { 102 | Question question = questions.get(i); 103 | System.out.println("Question " + (i + 1) + ": " + question.getQuestionText()); 104 | System.out.println("A. " + question.getOptionA()); 105 | System.out.println("B. " + question.getOptionB()); 106 | System.out.println("C. " + question.getOptionC()); 107 | System.out.println("D. " + question.getOptionD()); 108 | 109 | String userAnswer = getUserAnswer(); 110 | 111 | if (question.isCorrectAnswer(userAnswer)) { 112 | System.out.println("Correct!\n"); 113 | score += SCORE_PER_QUESTION; 114 | } else { 115 | System.out.println("Incorrect!\n"); 116 | } 117 | } 118 | 119 | System.out.println("Quiz Summary:"); 120 | System.out.println("Total Questions: " + questions.size()); 121 | System.out.println("Correct Answers: " + (score / SCORE_PER_QUESTION)); 122 | System.out.println("Incorrect Answers: " + ((questions.size() * SCORE_PER_QUESTION - score) / SCORE_PER_QUESTION)); 123 | System.out.println("Score: " + score + "%\n"); 124 | 125 | System.out.println("Thank you for playing!"); 126 | } 127 | 128 | private String getUserAnswer() { 129 | Scanner scanner = new Scanner(System.in); 130 | System.out.print("Your Answer: "); 131 | return scanner.nextLine().toUpperCase(); 132 | } 133 | 134 | public static void RunQuizApplication(String[] args) { 135 | QuizApplication quiz = new QuizApplication(); 136 | 137 | try { 138 | quiz.loadQuestions(); 139 | quiz.startQuiz(); 140 | } catch (FileNotFoundException e) { 141 | System.out.println("Failed to load questions from file: " + QUESTIONS_FILE); 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Quiz Application/README.md: -------------------------------------------------------------------------------- 1 | # Quiz Application 2 | The Quiz Application is a multiple-choice quiz program written in Java. It allows you to load questions from a file, present them to the user, and keep track of the score. 3 | 4 | ## Features 5 | - Loads questions from a text file 6 | - Presents questions one by one with multiple-choice options 7 | - Keeps track of the user's score 8 | - Provides a summary of the quiz results at the end 9 | 10 | ## Usage 11 | 1. Ensure you have Java installed on your machine. 12 | 2. Clone or download the Quiz Application repository. 13 | 3. Prepare the questions file: 14 | - Create a text file named "questions.txt" in the same directory as the Java file. 15 | - Populate the file with questions in the specified format (see example in the repository). 16 | 4. Open a terminal or command prompt and navigate to the project directory. 17 | 5. Compile the Java file: 18 | ```javac QuizApplication.java``` 19 | 6. Run the application: 20 | ```java QuizApplication``` 21 | 7. Follow the prompts in the console to answer the quiz questions. 22 | 8. After answering all the questions, the application will display a summary of the results. 23 | 24 | ## Customization 25 | You can customize the Quiz Application according to your needs: 26 | - Modify the `questions.txt` file to include your own set of questions. 27 | - Adjust the scoring system by modifying the `SCORE_PER_QUESTION` constant in the Java file. 28 | - Enhance the user interface by adding additional formatting or interaction features. 29 | 30 | ## Contributing 31 | Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. 32 | 33 | ## Credits 34 | This project is created by Kalutu Daniel. 35 | -------------------------------------------------------------------------------- /Quiz Application/questions.txt: -------------------------------------------------------------------------------- 1 | Question: What is the capital of France? 2 | Option A: Paris 3 | Option B: London 4 | Option C: Rome 5 | Option D: Madrid 6 | Correct Answer: A 7 | 8 | Question: Who painted the Mona Lisa? 9 | Option A: Leonardo da Vinci 10 | Option B: Pablo Picasso 11 | Option C: Vincent van Gogh 12 | Option D: Michelangelo 13 | Correct Answer: A 14 | 15 | Question: What is the largest planet in our solar system? 16 | Option A: Mercury 17 | Option B: Venus 18 | Option C: Jupiter 19 | Option D: Saturn 20 | Correct Answer: C 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-Projects-for-Beginners 2 | Welcome to our repository of Java projects for beginners! This repository is designed to provide new Java developers with a collection of simple, practical projects that they can use to hone their skills and gain experience working with Java. 3 | 4 | ## Contents 5 | The repository contains a variety of Java projects, including: 6 | 7 | - Calculator App - a simple calculator program written in Java that can perform basic arithmetic operations such as addition, subtraction, multiplication, and division. 8 | - Contact Book - a simple Java program that allows users to store and manage a list of contacts. 9 | - Quiz Application - is a multiple-choice quiz program written in Java. It allows you to load questions from a file, present them to the user, and keep track of the score. 10 | - Todo List App - a simple command-line Todo List App implemented in Java using the ArrayList data structure. 11 | - And more... 12 | 13 | ## How to Use 14 | To use this repository, simply clone or download the repository to your local machine and open the project you are interested in using an IDE of your choice. Each project comes with a README file that explains the project's requirements, features, and implementation details. 15 | 16 | ## Contributing 17 | If you have a simple, beginner-level Java project that you would like to add to this repository, please feel free to create a pull request. All contributions are welcome! 18 | 19 | ## License 20 | This repository is licensed under the MIT License, which means that you can use, modify, and distribute the code for any purpose, commercial or non-commercial, as long as you give credit to the original author. 21 | -------------------------------------------------------------------------------- /Simple Bank Account/BankAccountManagementSystem.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | import java.util.Scanner; 4 | 5 | public class BankAccountManagementSystem { 6 | 7 | private Map accounts; 8 | 9 | public BankAccountManagementSystem() { 10 | accounts = new HashMap<>(); 11 | } 12 | 13 | public void createAccount(String accountNumber) { 14 | if (accounts.containsKey(accountNumber)) { 15 | System.out.println("Account already exists."); 16 | } else { 17 | accounts.put(accountNumber, 0.0); 18 | System.out.println("Account created successfully."); 19 | } 20 | } 21 | 22 | public void deposit(String accountNumber, double amount) { 23 | if (accounts.containsKey(accountNumber)) { 24 | double balance = accounts.get(accountNumber); 25 | balance += amount; 26 | accounts.put(accountNumber, balance); 27 | System.out.println("Deposit successful."); 28 | } else { 29 | System.out.println("Account does not exist."); 30 | } 31 | } 32 | 33 | public void withdraw(String accountNumber, double amount) { 34 | if (accounts.containsKey(accountNumber)) { 35 | double balance = accounts.get(accountNumber); 36 | if (balance >= amount) { 37 | balance -= amount; 38 | accounts.put(accountNumber, balance); 39 | System.out.println("Withdrawal successful."); 40 | } else { 41 | System.out.println("Insufficient balance."); 42 | } 43 | } else { 44 | System.out.println("Account does not exist."); 45 | } 46 | } 47 | 48 | public void checkBalance(String accountNumber) { 49 | if (accounts.containsKey(accountNumber)) { 50 | double balance = accounts.get(accountNumber); 51 | System.out.println("Account Balance: " + balance); 52 | } else { 53 | System.out.println("Account does not exist."); 54 | } 55 | } 56 | 57 | public static void RunBankAccountManagementSystem(String[] args) { 58 | BankAccountManagementSystem bank = new BankAccountManagementSystem(); 59 | Scanner scanner = new Scanner(System.in); 60 | 61 | while (true) { 62 | System.out.println("\nBank Account Management System"); 63 | System.out.println("1. Create Account"); 64 | System.out.println("2. Deposit"); 65 | System.out.println("3. Withdraw"); 66 | System.out.println("4. Check Balance"); 67 | System.out.println("5. Exit"); 68 | System.out.print("Enter your choice: "); 69 | int choice = scanner.nextInt(); 70 | scanner.nextLine(); 71 | 72 | switch (choice) { 73 | case 1: 74 | System.out.print("Enter account number: "); 75 | String accountNumber = scanner.nextLine(); 76 | bank.createAccount(accountNumber); 77 | break; 78 | case 2: 79 | System.out.print("Enter account number: "); 80 | accountNumber = scanner.nextLine(); 81 | System.out.print("Enter amount to deposit: "); 82 | double depositAmount = scanner.nextDouble(); 83 | bank.deposit(accountNumber, depositAmount); 84 | break; 85 | case 3: 86 | System.out.print("Enter account number: "); 87 | accountNumber = scanner.nextLine(); 88 | System.out.print("Enter amount to withdraw: "); 89 | double withdrawAmount = scanner.nextDouble(); 90 | bank.withdraw(accountNumber, withdrawAmount); 91 | break; 92 | case 4: 93 | System.out.print("Enter account number: "); 94 | accountNumber = scanner.nextLine(); 95 | bank.checkBalance(accountNumber); 96 | break; 97 | case 5: 98 | System.out.println("Exiting..."); 99 | return; 100 | //System.exit(0); 101 | default: 102 | System.out.println("Invalid choice. Please try again."); 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Simple Bank Account/README.md: -------------------------------------------------------------------------------- 1 | # Bank Account Management System 2 | This is a simple bank account management system implemented in Java. The program allows users to create accounts, deposit money, withdraw money, and check their balance. 3 | 4 | ## Features 5 | - Create a new bank account. 6 | - Deposit money into an existing bank account. 7 | - Withdraw money from an existing bank account. 8 | - Check the balance of an existing bank account. 9 | 10 | ## Getting Started 11 | 12 | ### Prerequisites 13 | - Java Development Kit (JDK) installed on your machine. 14 | 15 | ### Running the Program 16 | 1. Clone the repository: 17 | ``` 18 | git clone https://github.com/kalutu/bank-account-management-system.git 19 | ``` 20 | 21 | 2. Navigate to the project directory: 22 | ``` 23 | cd bank-account-management-system 24 | ``` 25 | 26 | 3. Compile the Java file: 27 | ``` 28 | javac BankAccountManagementSystem.java 29 | ``` 30 | 31 | 4. Run the program: 32 | ``` 33 | java BankAccountManagementSystem 34 | ``` 35 | 36 | 5. Follow the on-screen instructions to perform various operations on the bank accounts. 37 | 38 | ## Usage 39 | - Choose options from the provided menu to create accounts, deposit money, withdraw money, or check balances. 40 | - Enter the required information as prompted by the program. 41 | - The program will provide appropriate messages and notifications based on the selected options. 42 | 43 | ## Contributing 44 | Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. 45 | 46 | ## Credits 47 | This project is created by Kalutu Daniel. 48 | -------------------------------------------------------------------------------- /Student Grade Calculator/README.md: -------------------------------------------------------------------------------- 1 | # Student Grade Calculator 2 | This Java program calculates and displays the average grades for a group of students. 3 | 4 | ## Features 5 | - Input student names and their respective grades 6 | - Calculate the average grade 7 | - Display a report with each student's name and grade, along with the overall average grade 8 | 9 | ## Usage 10 | 1. Launch the program. 11 | 2. Enter the number of students. 12 | 3. For each student, enter their name and grade. 13 | 4. The program will calculate the average grade and display a report with each student's name and grade, along with the overall average grade. 14 | 15 | ## Contributing 16 | Contributions are welcome! If you have any suggestions or improvements, please feel free to submit a pull request. 17 | 18 | ## Credits 19 | This project was created by Kalutu Daniel. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Student Grade Calculator/StudentGradeCalculator.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | 5 | public class StudentGradeCalculator { 6 | 7 | public static void RunStudentGradeCalculator(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | System.out.print("Enter the number of students: "); 11 | int numberOfStudents = scanner.nextInt(); 12 | 13 | List studentNames = new ArrayList<>(); 14 | List studentGrades = new ArrayList<>(); 15 | 16 | for (int i = 0; i < numberOfStudents; i++) { 17 | System.out.print("Enter the name of student " + (i + 1) + ": "); 18 | String name = scanner.next(); 19 | studentNames.add(name); 20 | 21 | System.out.print("Enter the grade of student " + (i + 1) + ": "); 22 | double grade = scanner.nextDouble(); 23 | studentGrades.add(grade); 24 | } 25 | 26 | double average = calculateAverage(studentGrades); 27 | 28 | System.out.println("\nStudent Grade Report:"); 29 | for (int i = 0; i < numberOfStudents; i++) { 30 | System.out.println(studentNames.get(i) + ": " + studentGrades.get(i)); 31 | } 32 | 33 | System.out.println("\nAverage Grade: " + average); 34 | } 35 | 36 | private static double calculateAverage(List grades) { 37 | double sum = 0.0; 38 | for (Double grade : grades) { 39 | sum += grade; 40 | } 41 | return sum / grades.size(); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Temperature Converter/README.md: -------------------------------------------------------------------------------- 1 | # Temperature Converter 2 | This is a simple Java program that converts temperature between Celsius, Fahrenheit, and Kelvin. 3 | 4 | ## How to Use 5 | - Clone or download this repository. 6 | - Compile the Java file using the command: javac TemperatureConverter.java 7 | - Run the program using the command: java TemperatureConverter 8 | - Enter the temperature you want to convert and its unit (Celsius, Fahrenheit, or Kelvin). 9 | - The program will display the converted temperature in the other two units. 10 | 11 | 12 | ## Examples 13 | ``` 14 | Convert 30 Celsius to Fahrenheit and Kelvin 15 | Enter temperature: 30 16 | Enter unit (C/F/K): C 17 | 30.00 C = 86.00 F 18 | 30.00 C = 303.15 K 19 | 20 | Convert 95 Fahrenheit to Celsius and Kelvin 21 | Enter temperature: 95 22 | Enter unit (C/F/K): F 23 | 95.00 F = 35.00 C 24 | 95.00 F = 308.15 K 25 | 26 | Convert 373 Kelvin to Celsius and Fahrenheit 27 | Enter temperature: 373 28 | Enter unit (C/F/K): K 29 | 373.00 K = 99.85 C 30 | 373.00 K = 675.67 F 31 | ``` 32 | ## Supported Units 33 | The program supports the following temperature units: 34 | - Celsius (C) 35 | - Fahrenheit (F) 36 | - Kelvin (K) 37 | -------------------------------------------------------------------------------- /Temperature Converter/TemperatureConverter.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TemperatureConverter { 4 | public static void RunTemperatureConverter(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | double temperature; 7 | char unit; 8 | 9 | // Prompt the user to enter the temperature and its unit 10 | System.out.print("Enter temperature: "); 11 | temperature = input.nextDouble(); 12 | System.out.print("Enter unit (C/F/K): "); 13 | unit = input.next().charAt(0); 14 | 15 | // Convert the temperature to other units based on the input unit 16 | switch (unit) { 17 | case 'C': 18 | case 'c': 19 | System.out.printf("%.2f C = %.2f F%n", temperature, celsiusToFahrenheit(temperature)); 20 | System.out.printf("%.2f C = %.2f K%n", temperature, celsiusToKelvin(temperature)); 21 | break; 22 | case 'F': 23 | case 'f': 24 | System.out.printf("%.2f F = %.2f C%n", temperature, fahrenheitToCelsius(temperature)); 25 | System.out.printf("%.2f F = %.2f K%n", temperature, fahrenheitToKelvin(temperature)); 26 | break; 27 | case 'K': 28 | case 'k': 29 | System.out.printf("%.2f K = %.2f C%n", temperature, kelvinToCelsius(temperature)); 30 | System.out.printf("%.2f K = %.2f F%n", temperature, kelvinToFahrenheit(temperature)); 31 | break; 32 | default: 33 | System.out.println("Invalid unit."); 34 | break; 35 | } 36 | } 37 | 38 | // Conversion methods 39 | public static double celsiusToFahrenheit(double celsius) { 40 | return (celsius * 9 / 5) + 32; 41 | } 42 | 43 | public static double celsiusToKelvin(double celsius) { 44 | return celsius + 273.15; 45 | } 46 | 47 | public static double fahrenheitToCelsius(double fahrenheit) { 48 | return (fahrenheit - 32) * 5 / 9; 49 | } 50 | 51 | public static double fahrenheitToKelvin(double fahrenheit) { 52 | return (fahrenheit + 459.67) * 5 / 9; 53 | } 54 | 55 | public static double kelvinToCelsius(double kelvin) { 56 | return kelvin - 273.15; 57 | } 58 | 59 | public static double kelvinToFahrenheit(double kelvin) { 60 | return (kelvin * 9 / 5) - 459.67; 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Tic Tac Toe/README.md: -------------------------------------------------------------------------------- 1 | # Tic Tac Toe in Java 2 | This is a simple implementation of the Tic Tac Toe game in Java, where two players take turns to place their mark (X or O) on a 3x3 board. The game ends when one player gets three marks in a row, column, or diagonal, or when the board is filled with marks without a winner. 3 | 4 | ## Usage 5 | - To play the game, simply run the TicTacToe class in your Java IDE or command line. 6 | - You will see an empty board with a prompt for the first player to enter their move. 7 | - Enter the row and column numbers (0-2) for your mark, and the game will update the board and prompt the other player to make their move. 8 | - The game will continue until there is a winner or a draw, at which point the program will display the final board and exit. 9 | 10 | ## Implementation 11 | The game is implemented using a 2D char array to represent the board, with '-' representing empty spots, 'X' for player 1, and 'O' for player 2. The program uses a simple algorithm to check for wins and draws, by checking each row, column, and diagonal for matching marks. 12 | 13 | The program also includes basic error handling to ensure that players cannot place their mark on an already filled spot or outside the board boundaries. 14 | 15 | ## Contributing 16 | Contributions to this project are welcome, including suggestions for improvement, bug fixes, or additional features. Please fork the project and create a new pull request with your changes. 17 | -------------------------------------------------------------------------------- /Tic Tac Toe/TicTacToe.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class TicTacToe { 4 | 5 | static String[] board; 6 | static String turn; 7 | 8 | 9 | // CheckWinner method will 10 | // decide the combination 11 | // of three box given below. 12 | static String checkWinner() 13 | { 14 | for (int a = 0; a < 8; a++) { 15 | String line = null; 16 | 17 | switch (a) { 18 | case 0: 19 | line = board[0] + board[1] + board[2]; 20 | break; 21 | case 1: 22 | line = board[3] + board[4] + board[5]; 23 | break; 24 | case 2: 25 | line = board[6] + board[7] + board[8]; 26 | break; 27 | case 3: 28 | line = board[0] + board[3] + board[6]; 29 | break; 30 | case 4: 31 | line = board[1] + board[4] + board[7]; 32 | break; 33 | case 5: 34 | line = board[2] + board[5] + board[8]; 35 | break; 36 | case 6: 37 | line = board[0] + board[4] + board[8]; 38 | break; 39 | case 7: 40 | line = board[2] + board[4] + board[6]; 41 | break; 42 | } 43 | //For X winner 44 | if (line.equals("XXX")) { 45 | return "X"; 46 | } 47 | 48 | // For O winner 49 | else if (line.equals("OOO")) { 50 | return "O"; 51 | } 52 | } 53 | 54 | for (int a = 0; a < 9; a++) { 55 | if (Arrays.asList(board).contains( 56 | String.valueOf(a + 1))) { 57 | break; 58 | } 59 | else if (a == 8) { 60 | return "draw"; 61 | } 62 | } 63 | 64 | // To enter the X Or O at the exact place on board. 65 | System.out.println( 66 | turn + "'s turn; enter a slot number to place " 67 | + turn + " in:"); 68 | return null; 69 | } 70 | 71 | // To print out the board. 72 | static void printBoard() 73 | { 74 | System.out.println("|---|---|---|"); 75 | System.out.println("| " + board[0] + " | " 76 | + board[1] + " | " + board[2] 77 | + " |"); 78 | System.out.println("|-----------|"); 79 | System.out.println("| " + board[3] + " | " 80 | + board[4] + " | " + board[5] 81 | + " |"); 82 | System.out.println("|-----------|"); 83 | System.out.println("| " + board[6] + " | " 84 | + board[7] + " | " + board[8] 85 | + " |"); 86 | System.out.println("|---|---|---|"); 87 | } 88 | 89 | public static void RunTicTacToe(String[] args) 90 | { 91 | Scanner in = new Scanner(System.in); 92 | board = new String[9]; 93 | turn = "X"; 94 | String winner = null; 95 | 96 | for (int a = 0; a < 9; a++) { 97 | board[a] = String.valueOf(a + 1); 98 | } 99 | 100 | System.out.println("Welcome to 3x3 Tic Tac Toe."); 101 | printBoard(); 102 | 103 | System.out.println( 104 | "X will play first. Enter a slot number to place X in:"); 105 | 106 | while (winner == null) { 107 | int numInput; 108 | 109 | // Exception handling. 110 | try { 111 | numInput = in.nextInt(); 112 | if (!(numInput > 0 && numInput <= 9)) { 113 | System.out.println( 114 | "Invalid input; re-enter slot number:"); 115 | continue; 116 | } 117 | } 118 | catch (InputMismatchException e) { 119 | System.out.println( 120 | "Invalid input; re-enter slot number:"); 121 | continue; 122 | } 123 | 124 | // This game has two player x and O. 125 | // Here is the logic to decide the turn. 126 | if (board[numInput - 1].equals( 127 | String.valueOf(numInput))) { 128 | board[numInput - 1] = turn; 129 | 130 | if (turn.equals("X")) { 131 | turn = "O"; 132 | } 133 | else { 134 | turn = "X"; 135 | } 136 | 137 | printBoard(); 138 | winner = checkWinner(); 139 | } 140 | else { 141 | System.out.println( 142 | "Slot already taken; re-enter slot number:"); 143 | } 144 | } 145 | 146 | // If no one win or lose from both player x and O. 147 | // then here is the logic to print "draw". 148 | if (winner.equalsIgnoreCase("draw")) { 149 | System.out.println( 150 | "It's a draw! Thanks for playing."); 151 | } 152 | 153 | // For winner -to display Congratulations! message. 154 | else { 155 | System.out.println( 156 | "Congratulations! " + winner 157 | + "'s have won! Thanks for playing."); 158 | } 159 | //in.close(); 160 | } 161 | } 162 | 163 | -------------------------------------------------------------------------------- /Todo List App/README.md: -------------------------------------------------------------------------------- 1 | # Todo List App in Java 2 | This is a simple command-line Todo List App implemented in Java using the ArrayList data structure. 3 | 4 | ## Features 5 | - Add items to the todo list 6 | - Remove items from the todo list 7 | - Display the current items in the todo list 8 | ## Usage 9 | - Compile the Java program. 10 | - Run the program. 11 | - Follow the on-screen instructions to add, remove, or view items in the todo list. 12 | 13 | ## Contributing 14 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 15 | Please make sure to update tests as appropriate. 16 | -------------------------------------------------------------------------------- /Todo List App/TodoListApp.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class TodoListApp { 5 | public static void RunTodoListApp(String[] args) { 6 | ArrayList todoList = new ArrayList(); 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | while (true) { 10 | System.out.println("====Todo List===="); 11 | for (int i = 0; i < todoList.size(); i++) { 12 | System.out.println((i+1) + ". " + todoList.get(i)); 13 | } 14 | System.out.println("================="); 15 | System.out.println("1. Add item"); 16 | System.out.println("2. Remove item"); 17 | System.out.println("3. Exit"); 18 | System.out.print("Enter choice: "); 19 | 20 | int choice = scanner.nextInt(); 21 | scanner.nextLine(); // consume the newline character 22 | 23 | if (choice == 1) { 24 | System.out.print("Enter item to add: "); 25 | String item = scanner.nextLine(); 26 | todoList.add(item); 27 | System.out.println("Item added!"); 28 | } else if (choice == 2) { 29 | System.out.print("Enter item number to remove: "); 30 | int itemNum = scanner.nextInt(); 31 | scanner.nextLine(); // consume the newline character 32 | if (itemNum > 0 && itemNum <= todoList.size()) { 33 | todoList.remove(itemNum-1); 34 | System.out.println("Item removed!"); 35 | } else { 36 | System.out.println("Invalid item number."); 37 | } 38 | } else if (choice == 3) { 39 | break; 40 | } else { 41 | System.out.println("Invalid choice. Please try again."); 42 | } 43 | } 44 | 45 | System.out.println("Exiting Todo List App."); 46 | //scanner.close(); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /menu.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class menu { 4 | public static void main(String[] args) { 5 | 6 | char Menu; 7 | String temp = ""; 8 | String printmenu = "\nApplication Menu\n\n1 - Address Book App\n2 - Calculator App\n3 - Contact Book App\n4 - File Encryption App\n5 - Guess Game App\n6 - Hang Man App\n7 - Library Management System App\n8 - Quiz Application App\n9 - Bank Account Management System App\nA - Student Grade Calculator App\nB - Temperature Converter App\nC - TicTacToe App\nD - To Do List App\nE - Exit"; 9 | 10 | 11 | AddressBook addressBook = new AddressBook(); 12 | Calculator calculator = new Calculator(); 13 | ContactBookProgram contactBook = new ContactBookProgram(); 14 | FileEncryptionDecryption fileEncryptionDecryption = new FileEncryptionDecryption(); 15 | GuessGame guessGame = new GuessGame(); 16 | HangmanGame hangmanGame = new HangmanGame(); 17 | LibraryManagementSystem libraryManagementSystem = new LibraryManagementSystem(); 18 | QuizApplication quizApplication = new QuizApplication(); 19 | BankAccountManagementSystem bankAccountManagementSystem = new BankAccountManagementSystem(); 20 | StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator(); 21 | TemperatureConverter temperatureConverter = new TemperatureConverter(); 22 | TicTacToe ticTacToe = new TicTacToe(); 23 | //TodoListApp todoListApp = new TodoListApp(); 24 | 25 | boolean quit = false; 26 | while (!quit) 27 | { 28 | Menu = ' '; 29 | Scanner input = new Scanner(System.in); 30 | 31 | System.out.println(printmenu); 32 | System.out.print("\nEnter your choice: "); 33 | 34 | if(input.hasNext()) 35 | { 36 | temp = input.next(); 37 | Menu = temp.charAt(0); 38 | input.nextLine(); 39 | } 40 | 41 | switch (Menu) { 42 | case '1': 43 | addressBook.RunAddressBook(args); 44 | break; 45 | case '2': 46 | calculator.RunCalculator(args); 47 | break; 48 | case '3': 49 | //input.close(); 50 | contactBook.RunContactBook(args); 51 | break; 52 | case '4': 53 | fileEncryptionDecryption.RunFileEncryptionDecryption(args); 54 | break; 55 | case '5': 56 | //input.close(); 57 | guessGame.RunGuessGame(args); 58 | break; 59 | case '6': 60 | hangmanGame.play(); 61 | break; 62 | case '7': 63 | libraryManagementSystem.RunLibraryManagementSystem(args); 64 | break; 65 | case '8': 66 | quizApplication.RunQuizApplication(args); 67 | break; 68 | case '9': 69 | bankAccountManagementSystem.RunBankAccountManagementSystem(args); 70 | break; 71 | case 'A': 72 | studentGradeCalculator.RunStudentGradeCalculator(args); 73 | break; 74 | case 'B': 75 | temperatureConverter.RunTemperatureConverter(args); 76 | break; 77 | case 'C': 78 | ticTacToe.RunTicTacToe(args); 79 | break; 80 | case 'D': 81 | TodoListApp.RunTodoListApp(args); 82 | break; 83 | case 'E': 84 | input.close(); 85 | quit = true; 86 | break; 87 | 88 | } 89 | } 90 | 91 | } 92 | 93 | } --------------------------------------------------------------------------------