Development of a Vending Machine Application using Java OOP Principles

Verified

Added on  2025/04/21

|23
|3429
|156
AI Summary
Desklib provides past papers and solved assignments for students. This project details a vending machine application built using Java and OOP.
Document Page
Object-Oriented Programming
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Table of Contents
INTRODUCTION............................................................................................................................................ 4
DEVELOPMENT AND DESIGN......................................................................................................................... 5
USER CLASS......................................................................................................................................................... 6
POWERUSER CLASS...............................................................................................................................................6
CASH CLASS......................................................................................................................................................... 7
ORDERMENU CLASS..............................................................................................................................................8
EXECUTING.......................................................................................................................................................... 9
TEST........................................................................................................................................................... 17
INITIAL TEST.......................................................................................................................................................17
FINAL TEST........................................................................................................................................................ 18
COURSEWORK 2......................................................................................................................................... 19
USE OF OOP CONCEPT........................................................................................................................................19
MEETING THE DESIGN CRITERIA..............................................................................................................................21
REFERENCE LIST.......................................................................................................................................... 22
APPENDICES............................................................................................................................................... 23
Table of Tables
Table 1 – Initial Test................................................................................................................17
Table 2 – Final Test.................................................................................................................18
Table of Figures
Figure 1 – Workflow diagram....................................................................................................5
Figure 2 – User class structure...................................................................................................6
Figure 3 – User class use case code snippet...............................................................................6
Figure 4 – SuperUser Class Structure........................................................................................7
Figure 5 – Admin use case code snippet....................................................................................7
Figure 6 – Cash Class Structure.................................................................................................8
Figure 7 – Cash class use case code snippet..............................................................................8
Document Page
Figure 8 – Order menu structure................................................................................................9
Figure 9 – Order Menu variable defining code snippet.............................................................9
Figure 10 – Order menu for users code snippet.........................................................................9
Figure 11 – Menu screen..........................................................................................................10
Figure 12 – Menu screen code snippet.....................................................................................10
Figure 13 – Quantity selection screen......................................................................................11
Figure 14 – How many items code snippet..............................................................................11
Figure 15 – Quantity selection screen......................................................................................12
Figure 16 – Quantity selection screen code snippet.................................................................12
Figure 17 – Payment screen.....................................................................................................13
Figure 18 – Payment screen code snippet 1.............................................................................13
Figure 19 – Payment screen code snippet 2.............................................................................13
Figure 20 – Due return screen..................................................................................................14
Figure 21 – Due return screen code snippet.............................................................................14
Figure 22 – Another item purchase confirmation....................................................................14
Figure 23 – Another item purchase confirmation code snippet...............................................14
Figure 24 – Logging into power user mode.............................................................................15
Figure 25 – Power user code snippet.......................................................................................15
Figure 26 – Power user mode menu.........................................................................................16
Figure 27 – Power user mode menu code snippet...................................................................16
Figure 28 – Option 1 Power User Mode..................................................................................16
Figure 29 – Displaying menu items to the user.......................................................................19
Document Page
Introduction
Java is a type of language used for computer programming to create some applications. Java
language allows ease of implementation to it where users do not have to use numeric
commands or language but in spite uses and practices giving commands to the computer
based on English commands. As Java language could be easily practiced, understood easily
by the human is also said to be higher leveled language.
Java has a definite way of writing instruction for making a program by using the pre-defined
rule's set of doing it that are present just as in the English language has grammar to phrase
sentences. Just as in English these set of defined rules in Java is identified as its Syntax. Once
the code is developed these language called by high-level instruction are then numeric code
converted by the compiler in order to make it compatible and understandable to execute by
the processing unit.
Java language is a widespread language used for various implementation over varieties of the
platform for developing software. Most of Java's syntax is inspired by the syntax of C++ and
C language of programming. When a programmer or designer write a piece of code to make
Java Application, Java is designed in such a way that it's a cross-platform language. This
states that the code has complied could run over the maximum operating system like MacOS,
Linux, and Windows. Java was first developed by James Gosling in years of the mid-1990s.
James at the time of development was the prominent scientist in Sun Microsystem company
(Leahy, 2019).
In our unit, we are going to understand the coding practices that goes into creating an
application in Java and then, later on, we'll create a software application for the
TenThousandSteps.org for their vending machine dispensing software.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Development and Design
Software developers that are experienced are the one which exercises best design practices
for pattern creation. Designing practices are the worst phase of problems for the developer as
most of the problems are faced in the designing phase. For our application common approach
of error and trial method is followed and collection efforts are cumulated for the creation of
the vending machine software and this was done over a tedious time taking process where all
the developers were indulged.
Here is the diagram that forms the base of the application functionality. In the form of
Workflow diagram with data and connectivity with other entities.
Figure 1 – Workflow diagram
In the above image of the Workflow diagram, the work is divided between four basic
collections of cases namely OrderMenu, User, PowerUser, and Cash. We had several
purposes which state the basic property of the whole design of the application. Cash class
contains required objects like Coins for managing coin transaction, change quantity defines
the amount of change that is available in the Vending machine pool, profit1, profit2, profit3,
profit4, profit5 are the profit-linked with individual product items available in the machine,
and profit collectively is the total profit associated with the overall sales of the vending
machine. total cash function calculates the overall total amount of money that is present in the
machine and returns it. coins available function calculates the total money of each
Document Page
denomination available in the machine. Profit calculates the total profit of the machine that
the machine has collected by the performed sales.
User Class
This class defines the customer that is the end user of the vending machine. User class
contains three major variables that have been put to use for implementation. We have
Balance variable which stores the amount related quantity for the products purchased and the
amount for their purchase. priceTotal is the total amount which the user has to pay based on
their selected in the vending machine software. Purchases are the variable that stores the total
purchases that the user has done via the use of the vending machine. As also being depicted
in the image provided below and lastly purchase is the function to that specific class to
perform all the functions like selecting the item and then selecting the amount of particular
item available in the machine and also allows you to pay for the purchased items.
Figure 2 – User class structure
Figure 3 – User class use case code snippet
PowerUser Class
PowerUser Class main idea is towards creating a Superuser authority for controlling of
Vending Machines features like checking balance available in the machine and total amount
of the items that are sold and available. Here we are using two variable mainly for the
PowerUser class and all the rest details for the PowerUser is also stored in the class User and
Document Page
only privilege’s object are defined under this section. These objects are like username where
the administrator’s user name is stored to identify him/her as the authoritative access to the
vending machine. A password is the data variable of integer type and stores the password for
verifying the validness of the user and making sure that no other user gains access to the
admin panel for controlling the machine functioning.
Figure 4 – SuperUser Class Structure
Figure 5 – Admin use case code snippet
Cash Class
Cash class contains required objects like Coins for managing coin transaction, change
quantity defines the amount of change that is available in the Vending machine pool, profit1,
profit2, profit3, profit4, profit5 are the profit-linked with individual product items available in
the machine, and profit collectively is the total profit associated with the overall sales of the
vending machine. total cash function calculates the overall total amount of money that is
present in the machine and returns it. coins available function calculates the total money of
each denomination available in the machine. Profit calculates the total profit of the machine
that the machine has collected by the performed sales. Profit1 is the variable used to calculate
the profit of the Crisps, Profit2 is the variable used to calculate the profit of the Mars Bars,
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Profit3 is the variable used to calculate the profit of the Coca Cola, Profit4 is the variable
used to calculate the profit of the Eugenia, and Profit5 is the variable used to calculate the
profit of the Water.
Figure 6 – Cash Class Structure
Figure 7 – Cash class use case code snippet
OrderMenu Class
OrderMenu class is the main class that is used for controlling the overall functioning of the
vending machine. First, we have Snacks attribute which stores the names of the items
available in the vending machine for sale. Price stores the respective price amount of the
snacks with correspondence to their available quantity of the individual item for sale which is
stored under the order menu class. Denomination defines the variety of the denomination that
is accepted by the machine for purchasing of the snack items.
Document Page
Figure 8 – Order menu structure
Figure 9 – Order Menu variable defining code snippet
Figure 10 – Order menu for the user's code snippet
Executing
In order to run your Java program make sure that you name your class correctly as Java
language is case sensitive. So for the file name, the class name must be exactly the same and
even change in the letter capitalization makes a difference.
Secondly for make sure that the path for java development kit is properly stated in the
application. The path setting could be made permanent but consistent but make sure you are
careful in doing so as any mistake being made could lead to crashing system (Sumasri, 2017).
Here when we run the program we are greeted with a welcome message which says the
company information. Further, a menu pops up displaying the menu for the items available as
shown in the below figure. The menu contains Snacks which shows the name of the snack
item, Price shows the respective price of individual snack item, and Quantity shows the
available number of the respective item with the vending machine.
Document Page
Figure 11 – Menu screen
Figure 12 – Menu screen code snippet
Further, the user inputs their desired item of choice by selecting their respective number. The
machine then further ask the user about the quantity of the particular item that they want to
purchase and inputs the quantity number in the output screen as shown in the respective
figure below –
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Figure 13 – Quantity selection screen
Figure 14 – How many items code snippets
Then after entering the desired quantity for the item selected. The screen displays the details
of your final billing. The billing contains information like the item user has chosen, the total
price of the item and quantity. Then the remaining item in stock is displayed for the item in
the vending machine and the total amount which is costed to the user.
Document Page
Figure 15 – Quantity selection screen
Figure 16 – Quantity selection screen code snippet
The available denomination that the machine accepts is 0.05, 0.1, 0.2, 0.5, 1.0. So the user
must enter the denomination of these quantities only and any denomination entered by the
user is rejected by the vending machine as shown in the screen diagram below. Then the user
keeps on entering denomination within the acceptable range until the full amount is being
paid.
chevron_up_icon
1 out of 23
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]