Java Project San
Java Project San
Assignment
Submitted by
717823L149 R SANTHOSH
SEPTEMBER – 2024
DEPARTMENT OF INFORMATION TECHNOLOGY
VISION
To provide reliable and modern technology resources to the faculty and students to develop the
competence in Information Technology and to endure with the rapidly changing world to serve the
mankind.
MISSION
Imparting technical knowledge through innovative teaching and research for budding
professionals.
To equip the students with strong fundamentals, programming and problem solving skills
with an exposure to emerging technologies and inculcate leadership qualities with a passion
to serve society.
PEO3: Graduates will realize the importance of self-learning and engage in lifelong
learning to become experts either as entrepreneurs or employees in the field to widen the
professional knowledge.
Program Outcomes
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
Page 1 of 14
PO4: Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO11: Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and leader
in a team, to manage projects and in multidisciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
PSO-1 Ability to organize an IT infrastructure, secure the data and analyze the data analytic
techniques in the field of data mining, big data as to facilitate in solving problems.
PSO-2 Ability to analyze and design the system in the domain of Cloud and Internet of Things.
Page 2 of 14
Page 3 of 14
Project Objective:
The objective of the Vending Machine Order Processing system is to develop a robust and user-
friendly console-based Java application that allows customers to interact with a virtual vending
machine. The application will enable customers to place orders for available items while
ensuring inventory management and data validation.
Project Design:
A. System Design:
Name of the package Usage
project.entity This package will contain the Inventory and Order classes
project.util This package will contain the user defined exception class
project.main This package will contain the MainClass that is used to test the
application
project.service This package will contain the class that is used to validate the data and
calculate the bill amount
Package: project.util
Class Method and Variables Description
InvalidOrderException A user defined Exception Class
Package: project.entity
Class Method and Variables Description
Inventory Class
String itemId; item id
String itemName; name of the item
int quantity; Quantity of the item
double price; Price of the item
Page 4 of 14
Inventory(String itemId, String A parameterized constructor to initialize the
itemName, int quantity, double itemId, name, quantity and price.
price)
Getters and Setters Should create the getter and setter methods for all
the attributes mentioned
in the class
Package : project.entity
Class Method and Variables Description
Order Class
static Inventory[] stock; A static array of items in the inventory
String orderId; Order id
String item; Item name
int orderQuantity; Quantity of the item ordered
double totalAmount; Total bill amount for the order
public void calculateBill() This method calculates the bill amount for the
ordered item as item price * quantity and
updates the stock by invoking the updateStock()
method
public void updateStock(String This method updates the value of the quantity
itemId, int quantity) of the item in the stock with the corresponding
item id.
Getters and Setters Should create the getter and setter methods for all
the attributes mentioned in the class
Package : project.service
Class Method and Variables Description
VendingMachineSer Class
vice
public String This method will check the availability of
checkInventoryStatus(String item, the item in the inventory by performing the
int orderQuantity) following operations:
Page 5 of 14
If the quantity of the item in the
stock is less than the order quantity
then ItemOutOfStockException
must be thrown and caught.
If the quantity of the item in stock is
greater than or equal to the order
quantity then "Item in Stock" must
be returned.
public String validateData(String This method should validate the data by
orderId, String item, int performing the following operations:
orderQuantity) The order id must meet the
following requirements:
o Order id must not be null
o The id must contain exactly
five characters
o The order id must be of the
format “ORxxx” where ‘x’
is an integer. [For example
OR101 is valid whereas
DT101 or ORC01 are
invalid.]
The order quantity must meet not be
negative and should not be more
than 10.
If any of the above conditions are
not met then InvalidOrderException
must be thrown and caught.
If all the above conditions are met
then invoke checkInventoryStatus()
method.
If the status returned is "Item in
Stock" then return “Valid”
otherwise return the inventory
status.
public String generateBill(Order This method will invoke the calculateBill()
order) method of the order class and return a string
in the following format:
Order id:OR101 Amount:Rs.150.0
public String processOrder(String This method invokes the validateData()
orderId, String item, int method and performs the following tasks:
orderQuantity) If the validateData() method returns
“Valid” then perform the following
Page 6 of 14
operations:
o Create a new order
o Set the order id ,item name,
the order quantity
o Invoke the generateBill()
method by passing the
created order object.
If the validateData() method returns
anything other than “Valid” then
return that data.
Package : project.main
Class Method and Description
Variables
MainClass Main Class
public static void This method creates and initializes the inventory and then
main(String[] args) creates an object of VendingMachineService and invokes
processOrder () method.
Implementation:
InvalidOrderException.java
package project.util;
public class InvalidOrderException extends Exception{
@Override
public String toString() {
return "Invalid Order";
}
}
ItemOutOfStockException.java
package project.util;
public class ItemOutOfStockException extends Exception{
@Override
public String toString() {
return "Item Out Of Stock";
}
}
Inventory.java
Page 7 of 14
package project.entity;
Page 9 of 14
// Getters and Setters
public String getOrderId() {
return orderId;
}
import project.entity.Inventory;
import project.entity.Order;
import project.util.InvalidOrderException;
import project.util.ItemOutOfStockException;
import com.wipro.vm.entity.Inventory;
import com.wipro.vm.entity.Order;
import com.wipro.vm.service.VendingMachineService;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Creating the inventory
Inventory[] stock = new Inventory[5];
stock[0] = new Inventory("C101", "Lays Potato Chips", 10, 30.00);
stock[1] = new Inventory("C102", "Water", 12, 20.00);
stock[2] = new Inventory("C103", "Pepsi", 25, 15.00);
stock[3] = new Inventory("C104", "Coke", 0, 15.00); // Out of stock
stock[4] = new Inventory("C105", "DairyMilk Silk", 30, 45.00);
Order.setStock(stock);
VendingMachineService vm = new VendingMachineService();
displayInventory(stock);
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\nEnter Order ID (or type 'exit' to quit):");
String orderId = scanner.nextLine();
if (orderId.equalsIgnoreCase("exit")) {
break;
}
System.out.println("Enter Quantity:");
int quantity = scanner.nextInt();
Page 12 of 14
scanner.nextLine(); // consume newline
scanner.close();
}
private static void displayInventory(Inventory[] stock) {
System.out.println("Current Inventory:");
for (Inventory item : stock) {
System.out.println(item.getItemName() + " (ID: " + item.getItemId() + ",
Quantity: " + item.getQuantity() + ", Price: Rs." + item.getPrice() + ")");
}
}
}
Output Screenshots
Page 13 of 14