From c0bb2dc3d185604d03632522091bf4261094db55 Mon Sep 17 00:00:00 2001 From: vyshnavitellagorla <131364723+vyshnavitellagorla@users.noreply.github.com> Date: Mon, 27 May 2024 12:38:43 +0530 Subject: [PATCH] Add files via upload --- Bank.java | 115 ++++++++++++++++++++++++++++++++++ Ecommerce.java | 166 +++++++++++++++++++++++++++++++++++++++++++++++++ hospital.java | 138 ++++++++++++++++++++++++++++++++++++++++ media.java | 122 ++++++++++++++++++++++++++++++++++++ 4 files changed, 541 insertions(+) create mode 100644 Bank.java create mode 100644 Ecommerce.java create mode 100644 hospital.java create mode 100644 media.java diff --git a/Bank.java b/Bank.java new file mode 100644 index 0000000..5106bd5 --- /dev/null +++ b/Bank.java @@ -0,0 +1,115 @@ +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) { + System.out.println("1. Create Account"); + System.out.println("2. Deposit"); + System.out.println("3. Withdraw"); + System.out.println("4. Exit"); + 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: + System.out.println("Exiting..."); + System.exit(0); + default: + System.out.println("Invalid option!"); + } + } + } + + private static void createAccount() { + 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!"); + } + + private static void 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!"); + } + } + + private static void 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!"); + } + } +} diff --git a/Ecommerce.java b/Ecommerce.java new file mode 100644 index 0000000..40ea379 --- /dev/null +++ b/Ecommerce.java @@ -0,0 +1,166 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +class Product { + private int id; + private String name; + private double price; + + public Product(int id, String name, double price) { + this.id = id; + this.name = name; + this.price = price; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public double getPrice() { + return price; + } +} + +class CartItem { + private Product product; + private int quantity; + + public CartItem(Product product, int quantity) { + this.product = product; + this.quantity = quantity; + } + + public Product getProduct() { + return product; + } + + public int getQuantity() { + return quantity; + } +} + +class ShoppingCart { + private List items; + + public ShoppingCart() { + this.items = new ArrayList<>(); + } + + public void addItem(CartItem item) { + items.add(item); + } + + public List getItems() { + return items; + } + + public double calculateTotal() { + double total = 0; + for (CartItem item : items) { + total += item.getProduct().getPrice() * item.getQuantity(); + } + return total; + } +} + +public class ECommercePlatform { + private static List products = new ArrayList<>(); + private static ShoppingCart cart = new ShoppingCart(); + private static Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + initializeProducts(); + + while (true) { + System.out.println("1. Browse Products"); + System.out.println("2. Add to Cart"); + System.out.println("3. View Cart"); + System.out.println("4. Checkout"); + System.out.println("5. Exit"); + System.out.print("Choose an option: "); + int option = scanner.nextInt(); + scanner.nextLine(); // Consume newline character + + switch (option) { + case 1: + browseProducts(); + break; + case 2: + addToCart(); + break; + case 3: + viewCart(); + break; + case 4: + checkout(); + break; + case 5: + System.out.println("Exiting..."); + System.exit(0); + default: + System.out.println("Invalid option!"); + } + } + } + + private static void initializeProducts() { + products.add(new Product(1, "Product 1", 10.0)); + products.add(new Product(2, "Product 2", 20.0)); + // Add more products here + } + + private static void browseProducts() { + System.out.println("Available Products:"); + for (Product product : products) { + System.out.println(product.getId() + ". " + product.getName() + " - $" + product.getPrice()); + } + } + + private static void addToCart() { + System.out.print("Enter product ID: "); + int productId = scanner.nextInt(); + scanner.nextLine(); // Consume newline character + Product selectedProduct = null; + for (Product product : products) { + if (product.getId() == productId) { + selectedProduct = product; + break; + } + } + if (selectedProduct != null) { + System.out.print("Enter quantity: "); + int quantity = scanner.nextInt(); + scanner.nextLine(); // Consume newline character + cart.addItem(new CartItem(selectedProduct, quantity)); + System.out.println("Item added to cart!"); + } else { + System.out.println("Product not found!"); + } + } + + private static void viewCart() { + List items = cart.getItems(); + if (items.isEmpty()) { + System.out.println("Cart is empty."); + } else { + System.out.println("Cart:"); + for (CartItem item : items) { + System.out.println(item.getProduct().getName() + " - Quantity: " + item.getQuantity()); + } + System.out.println("Total: $" + cart.calculateTotal()); + } + } + + private static void checkout() { + System.out.println("Checkout - Total: $" + cart.calculateTotal()); + System.out.println("Thank you for shopping with us!"); + // Logic for completing the checkout process (e.g., payment, order creation, etc.) would go here + // This is a simplified version without payment integration or order tracking + cart = new ShoppingCart(); // Clear the cart after checkout + } +} diff --git a/hospital.java b/hospital.java new file mode 100644 index 0000000..a34b246 --- /dev/null +++ b/hospital.java @@ -0,0 +1,138 @@ +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 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("Patient Records:"); + for (Patient patient : patientRecords) { + System.out.println(patient); + } + } + + public void displayAppointmentSchedule() { + System.out.println("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(); + } + } + + 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(); + + // 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.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)); + } + + // 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.equals("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/media.java b/media.java new file mode 100644 index 0000000..9d103d3 --- /dev/null +++ b/media.java @@ -0,0 +1,122 @@ +import java.util.*; + +class User { + private String username; + private String fullName; + private String email; + // Add more user profile information as needed + + public User(String username, String fullName, String email) { + this.username = username; + this.fullName = fullName; + this.email = email; + } + + public String getUsername() { + return username; + } + + @Override + public String toString() { + return "Username: " + username + ", Full Name: " + fullName + ", Email: " + email; + } +} + +class Post { + private String content; + private User author; + private List comments; + + public Post(String content, User author) { + this.content = content; + this.author = author; + this.comments = new ArrayList<>(); + } + + public void addComment(Comment comment) { + comments.add(comment); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Author: ").append(author.getUsername()).append("\n"); + sb.append("Content: ").append(content).append("\n"); + sb.append("Comments:\n"); + for (Comment comment : comments) { + sb.append(comment).append("\n"); + } + return sb.toString(); + } +} + +class Comment { + private String content; + private User author; + + public Comment(String content, User author) { + this.content = content; + this.author = author; + } + + @Override + public String toString() { + return "Comment by " + author.getUsername() + ": " + content; + } +} + +public class SocialNetworkingDemo { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + List users = new ArrayList<>(); + List posts = new ArrayList<>(); + + // Dynamic input for creating users + System.out.println("Create users (username, full name, email), type 'done' to finish:"); + while (true) { + System.out.print("Username: "); + String username = scanner.nextLine(); + if (username.equals("done")) break; + System.out.print("Full Name: "); + String fullName = scanner.nextLine(); + System.out.print("Email: "); + String email = scanner.nextLine(); + + User user = new User(username, fullName, email); + users.add(user); + } + + // Dynamic input for creating posts and comments + for (User user : users) { + System.out.println("User: " + user.getUsername()); + System.out.println("Create posts, type 'done' to finish:"); + while (true) { + System.out.print("Post content: "); + String content = scanner.nextLine(); + if (content.equals("done")) break; + + Post post = new Post(content, user); + posts.add(post); + + // Allow commenting on the post + System.out.println("Add comments to this post, type 'done' to finish:"); + while (true) { + System.out.print("Comment content: "); + String commentContent = scanner.nextLine(); + if (commentContent.equals("done")) break; + + Comment comment = new Comment(commentContent, user); + post.addComment(comment); + } + } + } + + // Display all posts + System.out.println("\nAll Posts:"); + for (Post post : posts) { + System.out.println(post); + } + + scanner.close(); + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy