Project Summary

advertisement
Matt Stegner
CS 101
12.7.2010
Final Project Summary
Real world software requires that the software be stable, protect its self, and
perform the required functions with out errors. Users will abandon, or simply not
pay for software that can give erroneous result and handle erroneous input. With
that I wanted to build a final project that would be fully functional, but that also
would be production ready and handle spurious input from users, filter it, and
return only answers the software is possible. For my project I created a software
implementation of soda vending machine that accepts and tabulates user input,
compares text strings to arrays, tracks the amount of soda in the machine, performs
initial set of the machine, dispenses soda and change. There is also the ability to
unplug the machine, which simulates unplugging a real soda machine (resets all
temporary variables, but does not reset physical variable like the amount of soda in
the machine).
My application consisted of an HTML page that utilized Forms and JavaScript. Data
is passed back and forth between the Form and the JavaScript. Inside the JavaScript
I used various functions and global variables to change the state of the machine.
One For loop is used, and various If, Else, and Else If statements are used throughout
the machine. Data in the machine is stored in strings, numbers, and arrays.
User interface:
The user interface of the “machine” consisted of 7 buttons that represent the
possible types of money that a user can add to the machine. This money is tabulated
in the “Total Money Entered:”
Next is the text area where users can input the name of the soda they desire.
Below that is the dispensing text area, this is used to relay the messages of success,
failure, and errors to the user.
Beyond that is the combo “Dispense Change” button and text box, which is user to
return the remaining money to the user and display how much is left at the end of
the transaction.
Functions:
The application consists of 8 functions that perform all work. These functions
accept and return data not only to the Form element of the application, but also
among each other and with the main JavaScript global variables. All work in
application is performed inside the functions. Below are the functions:
checkSodaName(array,key):
This function is the largest and most complex in that machine. It consists of
4 separate “If, Else” statement, one for loop that pares through a loop, and calls to all
the other functions in the application (except for Pulling the Plug).
There are two arguments passed into the function; a text string, and an array.
Other data from the JavaScript is used in the function.
The first “If, Else” statement is a check that the user has actually typed a
desired selection into the machine. If the have not, an error is returned.
The second “If, Else” statement checks that the user has entered enough
money into the machine. This check is performed every time the function is called.
It ensures that no soda will be dispensed with less than 50 cents in the machine. If
the user attempts to purchase a soda with not enough money in the machine, an
error will be displayed.
Next is a For loop that searches through the inventory of the machine.
Imbedded inside the For loop is an “If, Else If” statement that matches the soda that
the user asked for with the known soda inventory of the machine. If no match is
found, an error is thrown, and the machine will display the available inventory of
the machine.
If a match is found, another “If, Else” statement checks the inventory of the
machine to ensure that there is at there is enough of the desired soda to dispense.
If there is enough inventory, the machine will do three things; Dispense the
desired soda, subtract the cost of the soda from the total money deposited by the
user, and remove one soda from the inventory of the machine.
dispenceChange():
This function performs two actions; it dispenses the amount of change the
user is to receive (the running total) and sets the total amount of money in the
machine to zero.
generateRandomNumber():
This function is used to set the initial inventory of the machine. Each type of
soda calls this function and is returned a random number between 0 and 12 (one
case of soda). This represents the random state that a user would find the machine
in when first approached.
calculateTotalMoney(x):
This function is used to calculate the total amount of money the user has
entered into the machine. This function returns directly to the form text area,
simulating the running total a user would see as money is added to the machine.
This function also rounds all money to two decimal places (this is also performed
elsewhere in the application).
decrementSoda(key):
This function takes the soda asked for by the user, compares it to the list of
available soda in the machine, and removes one soda from the inventory of the soda
that was asked for. This function is run every time a soda is dispensed.
convertSodaToInventory(key):
This function convert the soda name asked for by the user to the
corresponding soda inventory number. This is partially used to check that the
machine will not dispense more soda than is in the machine.
flushPenny():
Simple flushes a penny through the machine since they are not used and does
not add it to the total of the money in the machine.
pullThePlug():
This function empty all the text boxes and remove any money from the
machine. This is for testing and debugging purposes and would not exist in a actual
vending machine in this form. This is the virtual equivalent of “Pulling the Plug”
(which resets any variables except the physical variables represented in the
machine: the inventory of soda).
The primary purpose of my application was to show that it is possible create an
application that handles user input, even erroneous user input correctly and
attempt to not fail drastically. In building my soda machine, it would have been
much more easy to simple give the user a row of buttons that represents the
available soda, and not bother with matching text strings input by the user to the
internal inventory of the machine. What I did was more challenging; Properly
handling errors as they propagated through the system.
Also added, simple for some whimsy, are some sound effects that are fired off when
certain work is done inside the machine.
Download