Java projects
import [Link];
public class CurrencyConverter {
private double balance;
private String pin;
public CurrencyConverter(double initialBalance, String pin) {
[Link] = initialBalance;
[Link] = pin;
public static void main(String[] args) {
CurrencyConverter atm = new CurrencyConverter(5000, "1234");
[Link]();
public void start() {
Scanner scanner = new Scanner([Link]);
[Link]("Enter PIN: ");
String enteredPin = [Link]();
if () {
[Link]("Invalid PIN!");
[Link]();
return;
boolean exit = false;
while (!exit) {
[Link]("\n--- ATM Menu ---");
[Link]("1. Check Balance");
[Link]("2. Withdraw");
[Link]("3. Deposit");
[Link]("4. Exit");
[Link]("Choose option: ");
int choice = [Link]();
switch (choice) {
case 1:
checkBalance();
break;
case 2:
withdraw(scanner);
break;
case 3:
deposit(scanner);
break;
case 4:
exit = true;
[Link]("Thank you!");
break;
default:
[Link]("Invalid option!");
[Link]();
private void checkBalance() {
[Link]("Balance: $" + balance);
}
private void withdraw(Scanner scanner) {
[Link]("Enter amount to withdraw: ");
double amount = [Link]();
if (amount > balance) {
[Link]("Insufficient funds!");
} else {
balance -= amount;
[Link]("Withdrawn: $" + amount);
private void deposit(Scanner scanner) {
[Link]("Enter amount to deposit: ");
double amount = [Link]();
balance += amount;
[Link]("Deposited: $" + amount);
}
import [Link].*;
public class CurrencyConverter {
static class Product {
int id;
String name;
double price;
int stock;
Product(int id, String name, double price, int stock) {
[Link] = id;
[Link] = name;
[Link] = price;
[Link] = stock;
@Override
public String toString() {
return "ID: " + id + " | " + name + " | Price: $" + price + " | Stock: " + stock;
static class ShoppingCart {
Map<Integer, Integer> cart = new HashMap<>();
void addProduct(int productId, int quantity) {
[Link](productId, [Link](productId, 0) + quantity);
[Link]("✓ Product " + productId + " added to cart (Qty: " + quantity + ")");
void removeProduct(int productId) {
[Link](productId);
[Link]("✓ Product " + productId + " removed from cart");
void viewCart(List<Product> products) {
if ([Link]()) {
[Link]("Cart is empty!");
return;
[Link]("\n--- Shopping Cart ---");
double total = 0;
for ([Link]<Integer, Integer> entry : [Link]()) {
Product p = [Link]().filter(x -> [Link] == [Link]()).findFirst().orElse(null);
if (p != null) {
double subtotal = [Link] * [Link]();
[Link]([Link] + " x" + [Link]() + " = $" + subtotal);
total += subtotal;
[Link]("Total: $" + total + "\n");
public static void main(String[] args) {
List<Product> products = [Link](
new Product(1, "Laptop", 799.99, 5),
new Product(2, "Phone", 499.99, 10),
new Product(3, "Headphones", 99.99, 15),
new Product(4, "Tablet", 349.99, 8)
);
ShoppingCart cart = new ShoppingCart();
Scanner sc = new Scanner([Link]);
while (true) {
[Link]("\n--- E-Commerce App ---");
[Link]("1. View Products");
[Link]("2. Add to Cart");
[Link]("3. View Cart");
[Link]("4. Remove from Cart");
[Link]("5. Exit");
[Link]("Choose option: ");
int choice = [Link]();
if (choice == 1) {
[Link]("\n--- Available Products ---");
[Link]([Link]::println);
} else if (choice == 2) {
[Link]("Enter Product ID: ");
int id = [Link]();
[Link]("Enter Quantity: ");
int qty = [Link]();
if ([Link]().anyMatch(p -> [Link] == id)) {
[Link](id, qty);
} else {
[Link]("Invalid Product ID!");
} else if (choice == 3) {
[Link](products);
} else if (choice == 4) {
[Link]("Enter Product ID to remove: ");
[Link]([Link]());
} else if (choice == 5) {
[Link]("Thank you for shopping!");
break;
} else {
[Link]("Invalid choice!");
[Link]();