Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Hard - Level Tasks added #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions chitta kushal/HospitalSystemDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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 "Name: " + name + ", Age: " + age + ", Gender: " + gender + ", Address: " + address + ", Phone: " + phoneNumber;
}
}

class HospitalManagementSystem {
private List<Patient> patientRecords;
private Map<Date, List<Patient>> 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("Patient Records:");
for (Patient patient : patientRecords) {
System.out.println(patient);
}
}

public void displayAppointmentSchedule() {
System.out.println("Appointment Schedule:");
for (Map.Entry<Date, List<Patient>> 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();
}
}

public Patient getPatientByName(String name) {
for (Patient patient : patientRecords) {
if (patient.getName().equals(name)) {
return patient;
}
}
return null;
}
}

public class HospitalSystemDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HospitalManagementSystem hospitalSystem = new HospitalManagementSystem();

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.equals("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));
}

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.equals("done")) break;
System.out.print("Patient name: ");
String patientName = scanner.nextLine();

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.");
}
}

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;
}
}
}
154 changes: 154 additions & 0 deletions chitta kushal/OnlineBankingSystemMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class BankAccount {
private String accountNumber;
private double balance;
private Map<String, Double> transactionHistory;

public BankAccount(String accountNumber, double initialBalance) {
this.accountNumber = accountNumber;
this.balance = initialBalance;
this.transactionHistory = new HashMap<>();
}

public void deposit(double amount) {
balance += amount;
transactionHistory.put("Deposit", amount);
}

public boolean withdraw(double amount) {
if (balance >= amount) {
balance -= amount;
transactionHistory.put("Withdrawal", -amount);
return true;
}
return false;
}

public double getBalance() {
return balance;
}

public Map<String, Double> getTransactionHistory() {
return transactionHistory;
}
}

class OnlineBankingSystem {
private Map<String, BankAccount> accounts;
private Scanner scanner;

public OnlineBankingSystem() {
accounts = new HashMap<>();
scanner = new Scanner(System.in);
}

public void createAccount() {
System.out.println("Enter account number:");
String accountNumber = scanner.nextLine();
System.out.println("Enter initial balance:");
double initialBalance = scanner.nextDouble();
scanner.nextLine(); // Consume newline
BankAccount account = new BankAccount(accountNumber, initialBalance);
accounts.put(accountNumber, account);
System.out.println("Account created successfully.");
}

public void deposit() {
System.out.println("Enter account number:");
String accountNumber = scanner.nextLine();
BankAccount account = accounts.get(accountNumber);
if (account != null) {
System.out.println("Enter deposit amount:");
double amount = scanner.nextDouble();
scanner.nextLine(); // Consume newline
account.deposit(amount);
System.out.println("Deposit successful.");
} else {
System.out.println("Account not found.");
}
}

public void withdraw() {
System.out.println("Enter account number:");
String accountNumber = scanner.nextLine();
BankAccount account = accounts.get(accountNumber);
if (account != null) {
System.out.println("Enter withdrawal amount:");
double amount = scanner.nextDouble();
scanner.nextLine(); // Consume newline
if (account.withdraw(amount)) {
System.out.println("Withdrawal successful.");
} else {
System.out.println("Insufficient balance.");
}
} else {
System.out.println("Account not found.");
}
}

public void displayBalance() {
System.out.println("Enter account number:");
String accountNumber = scanner.nextLine();
BankAccount account = accounts.get(accountNumber);
if (account != null) {
System.out.println("Current balance: " + account.getBalance());
} else {
System.out.println("Account not found.");
}
}

public void displayTransactionHistory() {
System.out.println("Enter account number:");
String accountNumber = scanner.nextLine();
BankAccount account = accounts.get(accountNumber);
if (account != null) {
System.out.println("Transaction History:");
Map<String, Double> history = account.getTransactionHistory();
for (Map.Entry<String, Double> entry : history.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
} else {
System.out.println("Account not found.");
}
}
}

public class OnlineBankingSystemMain {
public static void main(String[] args) {
OnlineBankingSystem bankingSystem = new OnlineBankingSystem();
Scanner scanner = new Scanner(System.in);

while (true) {
System.out.println("\n1. Create Account\n2. Deposit\n3. Withdraw\n4. Display Balance\n5. Display Transaction History\n6. Exit\n");
System.out.println("Enter your choice:");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
bankingSystem.createAccount();
break;
case 2:
bankingSystem.deposit();
break;
case 3:
bankingSystem.withdraw();
break;
case 4:
bankingSystem.displayBalance();
break;
case 5:
bankingSystem.displayTransactionHistory();
break;
case 6:
System.out.println("Exiting...");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid choice. Please enter a number from 1 to 6.");
}
}
}
}