diff --git a/AshutoshSinghRana/hospitalsystem.java b/AshutoshSinghRana/hospitalsystem.java new file mode 100644 index 0000000..7de469c --- /dev/null +++ b/AshutoshSinghRana/hospitalsystem.java @@ -0,0 +1,140 @@ +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +class Patient { + private String name; + private int age; + private String gender; + private String address; + private String phoneNumber; + + public Patient(String name, int age, String gender, String address, String phoneNumber) { + this.name = name; + this.age = age; + this.gender = gender; + this.address = address; + this.phoneNumber = phoneNumber; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return String.format("Name: %s, Age: %d, Gender: %s, Address: %s, Phone: %s", name, age, gender, address, phoneNumber); + } +} + +class HospitalManagementSystem { + private List patientRecords; + private Map> appointmentSchedule; + + public HospitalManagementSystem() { + patientRecords = new ArrayList<>(); + appointmentSchedule = new HashMap<>(); + } + + public void addPatientRecord(Patient patient) { + patientRecords.add(patient); + } + + public void scheduleAppointment(Date date, Patient patient) { + appointmentSchedule.computeIfAbsent(date, k -> new ArrayList<>()).add(patient); + } + + public void displayPatientRecords() { + System.out.println("\n=========== Patient Records ==========="); + for (Patient patient : patientRecords) { + System.out.println(patient); + } + System.out.println("=======================================\n"); + } + + public void displayAppointmentSchedule() { + System.out.println("\n=========== Appointment Schedule ==========="); + for (Map.Entry> entry : appointmentSchedule.entrySet()) { + System.out.println("Date: " + entry.getKey()); + System.out.println("Patients:"); + for (Patient patient : entry.getValue()) { + System.out.println(" - " + patient); + } + System.out.println("---------------------------------------------"); + } + System.out.println("=============================================\n"); + } + + public Patient getPatientByName(String name) { + for (Patient patient : patientRecords) { + if (patient.getName().equals(name)) { + return patient; + } + } + return null; + } +} + +public class hospitalsystem { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + HospitalManagementSystem hospitalSystem = new HospitalManagementSystem(); + + // Input patient records + System.out.println("Enter patient information (name, age, gender, address, phone), type 'done' to finish:"); + while (true) { + System.out.print("Patient name: "); + String name = scanner.nextLine(); + if (name.equalsIgnoreCase("done")) break; + System.out.print("Patient age: "); + int age = Integer.parseInt(scanner.nextLine()); + System.out.print("Patient gender: "); + String gender = scanner.nextLine(); + System.out.print("Patient address: "); + String address = scanner.nextLine(); + System.out.print("Patient phone number: "); + String phoneNumber = scanner.nextLine(); + + hospitalSystem.addPatientRecord(new Patient(name, age, gender, address, phoneNumber)); + } + + // Input appointment scheduling + System.out.println("Enter appointment scheduling (date YYYY-MM-DD, patient name), type 'done' to finish:"); + while (true) { + System.out.print("Date (YYYY-MM-DD): "); + String dateString = scanner.nextLine(); + if (dateString.equalsIgnoreCase("done")) break; + System.out.print("Patient name: "); + String patientName = scanner.nextLine(); + + // Parse date + Date date = parseDate(dateString); + if (date != null) { + Patient patient = hospitalSystem.getPatientByName(patientName); + if (patient != null) { + hospitalSystem.scheduleAppointment(date, patient); + } else { + System.out.println("Patient not found."); + } + } else { + System.out.println("Invalid date format."); + } + } + + // Display patient records and appointment schedule + hospitalSystem.displayPatientRecords(); + hospitalSystem.displayAppointmentSchedule(); + + scanner.close(); + } + + private static Date parseDate(String dateString) { + try { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + return dateFormat.parse(dateString); + } catch (ParseException e) { + System.out.println("Error parsing date: " + e.getMessage()); + return null; + } + } +} diff --git a/AshutoshSinghRana/onlinebankingsystem.java b/AshutoshSinghRana/onlinebankingsystem.java new file mode 100644 index 0000000..c4da95e --- /dev/null +++ b/AshutoshSinghRana/onlinebankingsystem.java @@ -0,0 +1,148 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +class Account { + private String accountNumber; + private String holderName; + private double balance; + + public Account(String accountNumber, String holderName, double balance) { + this.accountNumber = accountNumber; + this.holderName = holderName; + this.balance = balance; + } + + public String getAccountNumber() { + return accountNumber; + } + + public String getHolderName() { + return holderName; + } + + public double getBalance() { + return balance; + } + + public void deposit(double amount) { + balance += amount; + } + + public void withdraw(double amount) { + if (amount <= balance) { + balance -= amount; + } else { + System.out.println("Insufficient funds!"); + } + } +} + +public class onlinebankingsystem { + private static Map accounts = new HashMap<>(); + private static Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + while (true) { + printMenu(); + System.out.print("Choose an option: "); + int option = scanner.nextInt(); + scanner.nextLine(); // Consume newline character + + switch (option) { + case 1: + createAccount(); + break; + case 2: + deposit(); + break; + case 3: + withdraw(); + break; + case 4: + displayAccountDetails(); + break; + case 5: + System.out.println("Thank you for using the banking system. Goodbye!"); + System.exit(0); + default: + System.out.println("Invalid option! Please try again."); + } + } + } + + private static void printMenu() { + System.out.println("======================================="); + System.out.println("| Banking System |"); + System.out.println("======================================="); + System.out.println("| 1. Create Account |"); + System.out.println("| 2. Deposit |"); + System.out.println("| 3. Withdraw |"); + System.out.println("| 4. Display Account Details |"); + System.out.println("| 5. Exit |"); + System.out.println("======================================="); + } + + private static void createAccount() { + System.out.println("---------- Create Account ----------"); + System.out.print("Enter account number: "); + String accountNumber = scanner.nextLine(); + System.out.print("Enter holder name: "); + String holderName = scanner.nextLine(); + System.out.print("Enter initial balance: "); + double balance = scanner.nextDouble(); + scanner.nextLine(); // Consume newline character + + Account account = new Account(accountNumber, holderName, balance); + accounts.put(accountNumber, account); + System.out.println("Account created successfully!"); + System.out.println("-------------------------------------"); + } + + private static void deposit() { + System.out.println("---------- Deposit ----------"); + System.out.print("Enter account number: "); + String accountNumber = scanner.nextLine(); + Account account = accounts.get(accountNumber); + if (account != null) { + System.out.print("Enter deposit amount: "); + double amount = scanner.nextDouble(); + account.deposit(amount); + System.out.println("Deposit successful. New balance: " + account.getBalance()); + } else { + System.out.println("Account not found!"); + } + System.out.println("-----------------------------"); + } + + private static void withdraw() { + System.out.println("---------- Withdraw ----------"); + System.out.print("Enter account number: "); + String accountNumber = scanner.nextLine(); + Account account = accounts.get(accountNumber); + if (account != null) { + System.out.print("Enter withdrawal amount: "); + double amount = scanner.nextDouble(); + account.withdraw(amount); + System.out.println("Withdrawal successful. New balance: " + account.getBalance()); + } else { + System.out.println("Account not found!"); + } + System.out.println("-------------------------------"); + } + + private static void displayAccountDetails() { + System.out.println("---------- Display Account Details ----------"); + System.out.print("Enter account number: "); + String accountNumber = scanner.nextLine(); + Account account = accounts.get(accountNumber); + if (account != null) { + System.out.println("Account Number: " + account.getAccountNumber()); + System.out.println("Holder Name: " + account.getHolderName()); + System.out.println("Balance: " + account.getBalance()); + } else { + System.out.println("Account not found!"); + } + System.out.println("---------------------------------------------"); + } +}