diff --git a/App.js b/App.js new file mode 100644 index 000000000..7b8998812 --- /dev/null +++ b/App.js @@ -0,0 +1,183 @@ +import React, { useEffect, useState } from "react"; + +function App() { + const [products, setProducts] = useState([]); + const [searchText, setSearchText] = useState(""); + const [category, setCategory] = useState("All"); + const [sortOrder, setSortOrder] = useState("asc"); + + // Custom home appliances products to add + const customHomeAppliances = [ + { + id: 1001, + title: "Air Conditioner", + price: 499.99, + category: "home appliances", + image: + "https://cdn-icons-png.flaticon.com/512/684/684908.png", + }, + { + id: 1002, + title: "Microwave Oven", + price: 149.99, + category: "home appliances", + image: + "https://cdn-icons-png.flaticon.com/512/2972/2972185.png", + }, + { + id: 1003, + title: "Vacuum Cleaner", + price: 199.99, + category: "home appliances", + image: + "https://cdn-icons-png.flaticon.com/512/2965/2965567.png", + }, + ]; + + useEffect(() => { + fetch("https://fakestoreapi.com/products") + .then((res) => res.json()) + .then((data) => { + // Combine API data + custom home appliances + setProducts([...data, ...customHomeAppliances]); + }); + }, []); + + // Get unique categories + "All" + const categories = ["All", ...new Set(products.map((p) => p.category))]; + + // Filter and sort products + const filteredProducts = products + .filter( + (product) => + (category === "All" || product.category === category) && + product.title.toLowerCase().includes(searchText.toLowerCase()) + ) + .sort((a, b) => + sortOrder === "asc" ? a.price - b.price : b.price - a.price + ); + + return ( +
+

Welcome to Product Listing

+ + {/* Controls */} +
+ setSearchText(e.target.value)} + style={{ + padding: "10px", + width: "250px", + fontSize: "16px", + borderRadius: "5px", + border: "1px solid #ccc", + }} + /> + + + + +
+ + {/* Products grid */} +
+ {filteredProducts.length === 0 ? ( +

No products found.

+ ) : ( + filteredProducts.map((product) => ( +
+ {product.title} +

+ {product.title} +

+

+ {product.category.charAt(0).toUpperCase() + product.category.slice(1)} +

+

+ ${product.price.toFixed(2)} +

+
+ )) + )} +
+
+ ); +} + +export default App; diff --git a/NDV_Code_by_Chandini_OrderManagement/OrderManagement.java b/NDV_Code_by_Chandini_OrderManagement/OrderManagement.java new file mode 100644 index 000000000..dbe9df5a7 --- /dev/null +++ b/NDV_Code_by_Chandini_OrderManagement/OrderManagement.java @@ -0,0 +1,48 @@ +import org.hibernate.*; +import org.hibernate.cfg.Configuration; + +import jakarta.persistence.*; + +@Entity +class Customer { + @Id + @GeneratedValue + private int id; + private String name; + + public Customer() {} + public Customer(String name) { this.name = name; } + + public int getId() { return id; } + public String getName() { return name; } + public void setName(String name) { this.name = name; } +} + +public class SimpleOrderApp { + public static void main(String[] args) { + // Hibernate config + Configuration cfg = new Configuration(); + cfg.setProperty("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver"); + cfg.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/orderdb"); + cfg.setProperty("hibernate.connection.username", "root"); + cfg.setProperty("hibernate.connection.password", "your_password"); // <-- Change this + cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); + cfg.setProperty("hibernate.hbm2ddl.auto", "update"); + cfg.setProperty("hibernate.show_sql", "true"); + + cfg.addAnnotatedClass(Customer.class); + + SessionFactory factory = cfg.buildSessionFactory(); + Session session = factory.openSession(); + Transaction tx = session.beginTransaction(); + + Customer customer = new Customer("Honey"); + session.save(customer); + + tx.commit(); + session.close(); + factory.close(); + + System.out.println("✔ Customer saved to DB!"); + } +} diff --git a/NDV_code_by_Chandini_Orderbook/Orderbook.java b/NDV_code_by_Chandini_Orderbook/Orderbook.java new file mode 100644 index 000000000..dbe9df5a7 --- /dev/null +++ b/NDV_code_by_Chandini_Orderbook/Orderbook.java @@ -0,0 +1,48 @@ +import org.hibernate.*; +import org.hibernate.cfg.Configuration; + +import jakarta.persistence.*; + +@Entity +class Customer { + @Id + @GeneratedValue + private int id; + private String name; + + public Customer() {} + public Customer(String name) { this.name = name; } + + public int getId() { return id; } + public String getName() { return name; } + public void setName(String name) { this.name = name; } +} + +public class SimpleOrderApp { + public static void main(String[] args) { + // Hibernate config + Configuration cfg = new Configuration(); + cfg.setProperty("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver"); + cfg.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/orderdb"); + cfg.setProperty("hibernate.connection.username", "root"); + cfg.setProperty("hibernate.connection.password", "your_password"); // <-- Change this + cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); + cfg.setProperty("hibernate.hbm2ddl.auto", "update"); + cfg.setProperty("hibernate.show_sql", "true"); + + cfg.addAnnotatedClass(Customer.class); + + SessionFactory factory = cfg.buildSessionFactory(); + Session session = factory.openSession(); + Transaction tx = session.beginTransaction(); + + Customer customer = new Customer("Honey"); + session.save(customer); + + tx.commit(); + session.close(); + factory.close(); + + System.out.println("✔ Customer saved to DB!"); + } +} diff --git a/NDV_code_by_Chandini_contactbook.java/contactbook.java b/NDV_code_by_Chandini_contactbook.java/contactbook.java new file mode 100644 index 000000000..c3cbad326 --- /dev/null +++ b/NDV_code_by_Chandini_contactbook.java/contactbook.java @@ -0,0 +1,79 @@ +import java.sql.*; +import java.util.Scanner; + +public class ContactBookApp { + static final String URL = "jdbc:mysql://localhost:3306/contact_book_db"; + static final String USER = "root"; // Replace if needed + static final String PASS = "your_mysql_password"; // Replace with your MySQL password + static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + int choice; + do { + System.out.println("\n1. Add Contact\n2. View Contacts\n3. Delete Contact\n0. Exit"); + System.out.print("Enter choice: "); + choice = sc.nextInt(); sc.nextLine(); + switch (choice) { + case 1 -> addContact(); + case 2 -> viewContacts(); + case 3 -> deleteContact(); + case 0 -> System.out.println("Goodbye!"); + default -> System.out.println("Invalid choice."); + } + } while (choice != 0); + } + + static void addContact() { + try (Connection conn = DriverManager.getConnection(URL, USER, PASS)) { + System.out.print("Enter Name: "); + String name = sc.nextLine(); + System.out.print("Enter Phone: "); + String phone = sc.nextLine(); + System.out.print("Enter Email: "); + String email = sc.nextLine(); + + String sql = "INSERT INTO contacts (name, phone, email) VALUES (?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(sql); + ps.setString(1, name); + ps.setString(2, phone); + ps.setString(3, email); + ps.executeUpdate(); + + System.out.println("Contact added!"); + } catch (Exception e) { + System.out.println("Error: " + e); + } + } + + static void viewContacts() { + try (Connection conn = DriverManager.getConnection(URL, USER, PASS)) { + String sql = "SELECT * FROM contacts"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + System.out.println("Contacts:"); + while (rs.next()) { + System.out.println("ID: " + rs.getInt("id") + + ", Name: " + rs.getString("name") + + ", Phone: " + rs.getString("phone") + + ", Email: " + rs.getString("email")); + } + } catch (Exception e) { + System.out.println("Error: " + e); + } + } + + static void deleteContact() { + try (Connection conn = DriverManager.getConnection(URL, USER, PASS)) { + System.out.print("Enter Contact ID to delete: "); + int id = sc.nextInt(); sc.nextLine(); + String sql = "DELETE FROM contacts WHERE id = ?"; + PreparedStatement ps = conn.prepareStatement(sql); + ps.setInt(1, id); + int rows = ps.executeUpdate(); + if (rows > 0) System.out.println("Contact deleted!"); + else System.out.println("Contact not found."); + } catch (Exception e) { + System.out.println("Error: " + e); + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 000000000..a20db318f --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ + Contact Book App (Java + MySQL) +This is a simple console-based Contact Book application developed in Java using JDBC to connect to a MySQL database. + +Features: +Add Contact: Save a new contact with name, phone, and email. + +View Contacts: Display all saved contacts from the database. + +Delete Contact: Remove a contact by entering its ID. + +🔧 Technologies Used: +Java + +JDBC (Java Database Connectivity) + +MySQL