Java Ass2 Siva
Java Ass2 Siva
ASSIGNMENT 2
DONE BY
B K SIVANANTHAN
B TECH AI&DS
Thinking in java 21UAD603
Inventory Management System
Aim:
To develop an Inventory Management System that tracks product stock, sales, and purchases,
ensuring efficient inventory control and management.
Algorithm:
1. Initialize Inventory: Load product details such as name, stock, price, and supplier.
2. Add/Update Products: Allow adding new products or updating existing ones.
3. Track Stock Levels: Maintain current stock levels and update them based on sales and
purchases.
4. Sales Management: Deduct stock when a sale occurs.
5. Purchase Management: Increase stock when new stock is purchased.
6. Low-Stock Alerts: Notify the user when stock falls below a set threshold.
7. Display Inventory: Show updated inventory after transactions.
Program
import java.util.*;
class Product {
int id;
String name;
int quantity;
double price;
public Product(int id, String name, int quantity, double price)
{
this.id = id;
this.name = name;
this.quantity = quantity;
this.price = price;
}
}
switch (choice) {
case 1:
addProduct();
break;
case 2:
sellProduct();
break;
case 3:
purchaseProduct();
break;
case 4:
checkLowStock();
break;
case 5:
displayInventory();
break;
case 6:
System.out.println("Exiting program...");
return;
default:
System.out.println("Invalid choice. Try again.");
}
}
}
output
Result
Thus the above program was executed and the output is verified.
2. Online voting system
Aim
To develop an Online Voting System where users can securely cast votes for elections or
surveys. The system ensures authentication, real-time vote counting, and accurate result
generation.
Algorithm
1. Initialize the system with predefined candidates.
2. Authenticate users and check eligibility.
3. Display available candidates and allow voting.
4. Store votes securely and prevent multiple voting.
5. Count votes in real-time and declare results.
Program
import java.util.*;
class Voter {
String voterID;
boolean hasVoted;
class Candidate {
String name;
int votes;
while (true) {
System.out.println("\n--- Online Voting System ---");
System.out.println("1. Vote");
System.out.println("2. Show Results");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
castVote();
break;
case 2:
showResults();
break;
case 3:
System.out.println("Exiting system... Thank you!");
return;
default:
System.out.println("Invalid choice. Try again.");
}
}
}
if (!voters.containsKey(voterID)) {
System.out.println("Invalid Voter ID! Access denied.");
return;
}
System.out.println("\nAvailable Candidates:");
for (int i = 0; i < candidates.size(); i++) {
System.out.println((i + 1) + ". " +
candidates.get(i).name);
}
candidates.get(choice - 1).votes++;
voter.hasVoted = true;
System.out.println("Vote cast successfully!");
}