0% found this document useful (0 votes)
19 views14 pages

Java Project San

Uploaded by

sandybbc12106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views14 pages

Java Project San

Uploaded by

sandybbc12106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

23CSR306 JAVA PROGRAMMING

Assignment

Vending Machine Order Processing

Submitted by

717823L149 R SANTHOSH

Department of Electronics and communication engineering

KARPAGAM COLLEGE OF ENGINEERING


(Autonomous)

Myleripalayam Village, Othakkal Mandapam Post,


Coimbatore - 641032, Tamilnadu, India

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.

Programme Educational Objectives (PEOs)


 PEO1: Graduates will be able to comprehend mathematics, science, engineering
fundamentals, laboratory and work-based experiences to formulate and solve problems in
the domain of Information Technology and acquire proficiency in Computer-based
engineering and the use of computational tools..

 PEO2: Graduates will be prepared to communicate and work effectively on


multidisciplinary engineering projects and practicing the ethics of their profession.

 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.

 PO10: Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.

 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.

Program Specific Outcomes (PSO)


After successful completion of the program, graduates of B.E (CSE) will:

 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

public String toString() Returns the message “Invalid Order”

ItemOutOfStockException A user defined Exception Class

public String toString() Returns the message “Item Out Of


Stock”

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;

public class Inventory {


private String itemId;
private String itemName;
private int quantity;
private double price;

public Inventory(String itemId, String itemName, int quantity, double price) {


this.itemId = itemId;
this.itemName = itemName;
this.quantity = quantity;
this.price = price;
}

// Getters and Setters


public String getItemId() {
return itemId;
}

public void setItemId(String itemId) {


this.itemId = itemId;
}

public String getItemName() {


return itemName;
}

public void setItemName(String itemName) {


this.itemName = itemName;
}

public int getQuantity() {


return quantity;
}

public void setQuantity(int quantity) {


this.quantity = quantity;
}

public double getPrice() {


return price;
Page 8 of 14
}

public void setPrice(double price) {


this.price = price;
}
}
Order.java
package project.entity;

public class Order {


public static Inventory[] stock;
private String orderId;
private String item;
private int orderQuantity;
private double totalAmount;

public Order(String orderId, String item, int orderQuantity) {


this.orderId = orderId;
this.item = item;
this.orderQuantity = orderQuantity;
}

public static void setStock(Inventory[] stock) {


Order.stock = stock;
}

public void calculateBill() {


for (Inventory inv : stock) {
if (inv.getItemName().equals(item)) {
this.totalAmount = inv.getPrice() * orderQuantity;
updateStock(inv.getItemId(), orderQuantity);
break;
}
}
}

public void updateStock(String itemId, int quantity) {


for (Inventory inv : stock) {
if (inv.getItemId().equals(itemId)) {
inv.setQuantity(inv.getQuantity() - quantity);
break;
}
}
}

Page 9 of 14
// Getters and Setters
public String getOrderId() {
return orderId;
}

public void setOrderId(String orderId) {


this.orderId = orderId;
}

public String getItem() {


return item;
}

public void setItem(String item) {


this.item = item;
}

public int getOrderQuantity() {


return orderQuantity;
}

public void setOrderQuantity(int orderQuantity) {


this.orderQuantity = orderQuantity;
}

public double getTotalAmount() {


return totalAmount;
}

public void setTotalAmount(double totalAmount) {


this.totalAmount = totalAmount;
}
}
VendingMachineService.java
package project.service;

import project.entity.Inventory;
import project.entity.Order;
import project.util.InvalidOrderException;
import project.util.ItemOutOfStockException;

public class VendingMachineService {


public String checkInventoryStatus(String item, int orderQuantity) throws
ItemOutOfStockException {
Page 10 of 14
for (Inventory inv : Order.stock) {
if (inv.getItemName().equals(item)) {
if (inv.getQuantity() < orderQuantity) {
throw new ItemOutOfStockException();
} else {
return "Item in Stock";
}
}
}
return "Item not found";
}

public String validateData(String orderId, String item, int orderQuantity) throws


InvalidOrderException, ItemOutOfStockException {
if (orderId == null || orderId.length() != 5 || !orderId.startsWith("OR")) {
throw new InvalidOrderException();
}

if (orderQuantity <= 0 || orderQuantity > 10) {


throw new InvalidOrderException();
}

return checkInventoryStatus(item, orderQuantity);


}

public String generateBill(Order order) {


order.calculateBill();
return "Order id:" + order.getOrderId() + "\nAmount:Rs." + order.getTotalAmount();
}

public String processOrder(String orderId, String item, int orderQuantity) {


try {
String validationResult = validateData(orderId, item, orderQuantity);
if ("Item in Stock".equals(validationResult)) {
Order order = new Order(orderId, item, orderQuantity);
return generateBill(order);
} else {
return validationResult;
}
} catch (InvalidOrderException | ItemOutOfStockException e) {
return e.toString();
}
Page 11 of 14
}
}
Mainclass.java
package com.wipro.vm.main;

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 Item Name:");


String item = scanner.nextLine();

System.out.println("Enter Quantity:");
int quantity = scanner.nextInt();

Page 12 of 14
scanner.nextLine(); // consume newline

// Process the order and display the result


String result = vm.processOrder(orderId, item, quantity);
System.out.println(result + "\n");
}

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

You might also like