Skip to content
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
183 changes: 183 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
@@ -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 (
<div
style={{
maxWidth: "1200px",
margin: "0 auto",
padding: "20px",
fontFamily: "Arial, sans-serif",
textAlign: "center",
}}
>
<h1>Welcome to Product Listing</h1>

{/* Controls */}
<div
style={{
marginBottom: "30px",
display: "flex",
justifyContent: "center",
gap: "15px",
flexWrap: "wrap",
}}
>
<input
type="text"
placeholder="Search products..."
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
style={{
padding: "10px",
width: "250px",
fontSize: "16px",
borderRadius: "5px",
border: "1px solid #ccc",
}}
/>

<select
value={category}
onChange={(e) => setCategory(e.target.value)}
style={{
padding: "10px",
fontSize: "16px",
borderRadius: "5px",
border: "1px solid #ccc",
}}
>
{categories.map((cat) => (
<option key={cat} value={cat}>
{cat.charAt(0).toUpperCase() + cat.slice(1)}
</option>
))}
</select>

<select
value={sortOrder}
onChange={(e) => setSortOrder(e.target.value)}
style={{
padding: "10px",
fontSize: "16px",
borderRadius: "5px",
border: "1px solid #ccc",
}}
>
<option value="asc">Price: Low to High</option>
<option value="desc">Price: High to Low</option>
</select>
</div>

{/* Products grid */}
<div
style={{
display: "grid",
gridTemplateColumns: "repeat(auto-fill,minmax(220px,1fr))",
gap: "25px",
justifyItems: "center",
}}
>
{filteredProducts.length === 0 ? (
<p>No products found.</p>
) : (
filteredProducts.map((product) => (
<div
key={product.id}
style={{
border: "1px solid #ddd",
borderRadius: "10px",
padding: "15px",
maxWidth: "220px",
textAlign: "center",
boxShadow: "0 2px 5px rgba(0,0,0,0.1)",
backgroundColor: "#fff",
}}
>
<img
src={product.image}
alt={product.title}
style={{ height: "150px", objectFit: "contain", marginBottom: "10px" }}
/>
<h4
style={{
fontSize: "16px",
height: "48px",
overflow: "hidden",
marginBottom: "8px",
}}
title={product.title}
>
{product.title}
</h4>
<p style={{ color: "#666", marginBottom: "6px", fontStyle: "italic" }}>
{product.category.charAt(0).toUpperCase() + product.category.slice(1)}
</p>
<p style={{ fontWeight: "bold", fontSize: "18px", color: "#2a9d8f" }}>
${product.price.toFixed(2)}
</p>
</div>
))
)}
</div>
</div>
);
}

export default App;
48 changes: 48 additions & 0 deletions NDV_Code_by_Chandini_OrderManagement/OrderManagement.java
Original file line number Diff line number Diff line change
@@ -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!");
}
}
48 changes: 48 additions & 0 deletions NDV_code_by_Chandini_Orderbook/Orderbook.java
Original file line number Diff line number Diff line change
@@ -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!");
}
}
79 changes: 79 additions & 0 deletions NDV_code_by_Chandini_contactbook.java/contactbook.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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