Debugging + matching Specs + Writing a report

profilebhihu45
vendingmachine_final.zip

VendingMachine_final/build.xml

Builds, tests, and runs the project VendingMachine.

VendingMachine_final/build/classes/.netbeans_automatic_build

VendingMachine_final/build/classes/.netbeans_update_resources

VendingMachine_final/build/classes/currencyHandler.txt

USD,true,true,true,true

VendingMachine_final/build/classes/currencyInventory.txt

PaperCurrency 100 Dollar Bill 100.0 medium paper 0
PaperCurrency 50 Dollar Bill 50.0 medium paper 0
PaperCurrency 20 Dollar Bill 200.0 medium paper 0
PaperCurrency 10 Dollar Bill 10.0 medium paper 4
PaperCurrency 5 Dollar Bill 5.0 medium paper 8
PaperCurrency 1 Dollar Bill 1.0 medium paper 16
CoinCurrency 50 cent piece 0.5 large metal 10
CoinCurrency Quarter 0.25 medium metal 20
CoinCurrency Dime 0.1 small metal 30
CoinCurrency Nickel 0.05 small metal 40
CoinCurrency penny 0.01 small metal 50

VendingMachine_final/build/classes/inventory.txt

Diet Coke,1.0,Bottle-soda,liter,0.5,10 Coke,1.0,Bottle-soda,liter,0.5,10 Apple Juice,1.0,Carton-thinRectangle,ounces,6.0,10 Peanuts,0.5,Bag-small,ounces,2.5,10 Potato Chips,0.5,Bag-medium,ounces,6.0,10 Hersey Chocolate,1.0,Bag-medium,ounces,4.0,10

VendingMachine_final/build/classes/vendingmachine/Currency.rs

VendingMachine_final/build/classes/vendingmachine/CurrencyHandler.rs

VendingMachine_final/build/classes/vendingmachine/currencyHandler.txt

USD,true,true,true,true

VendingMachine_final/build/classes/vendingmachine/CurrencyInventory.rs

VendingMachine_final/build/classes/vendingmachine/currencyInventory.txt

PaperCurrency 100 Dollar Bill 100.0 medium paper 0
PaperCurrency 50 Dollar Bill 50.0 medium paper 0
PaperCurrency 20 Dollar Bill 200.0 medium paper 0
PaperCurrency 10 Dollar Bill 10.0 medium paper 4
PaperCurrency 5 Dollar Bill 5.0 medium paper 8
PaperCurrency 1 Dollar Bill 1.0 medium paper 16
CoinCurrency 50 cent piece 0.5 large metal 10
CoinCurrency Quarter 0.25 medium metal 20
CoinCurrency Dime 0.1 small metal 30
CoinCurrency Nickel 0.05 small metal 40
CoinCurrency penny 0.01 small metal 50

VendingMachine_final/build/classes/vendingmachine/inventory.txt

Diet Coke,1.0,Bottle-soda,liter,0.5,10 Coke,1.0,Bottle-soda,liter,0.5,10 Apple Juice,1.0,Carton-thinRectangle,ounces,6.0,10 Peanuts,0.5,Bag-small,ounces,2.5,10 Potato Chips,0.5,Bag-medium,ounces,6.0,10 Hersey Chocolate,1.0,Bag-medium,ounces,4.0,10

VendingMachine_final/build/classes/vendingmachine/InventoryItem.rs

VendingMachine_final/build/classes/vendingmachine/Item.rs

VendingMachine_final/build/classes/vendingmachine/Main.rs

VendingMachine_final/build/classes/vendingmachine/Purchase.rs

VendingMachine_final/build/classes/vendingmachine/VendingMachine.rs

VendingMachine_final/build/classes/vending/Currency.class

                package vending;

                public 
                synchronized 
                class Currency {
    
                private String 
                name;
    
                private double 
                value;
    
                private String 
                size;
    
                private String 
                material;
    
                private int 
                quantity;
    
                private String 
                curencyinventorytype;
    
                public void Currency();
    
                public String 
                getName();
    
                public void 
                setName(String);
    
                public double 
                getValue();
    
                public void 
                setValue(double);
    
                public String 
                getSize();
    
                public void 
                setSize(String);
    
                public String 
                getMaterial();
    
                public void 
                setMaterial(String);
    
                public int 
                getQuantity();
    
                public void 
                setQuantity(int);
    
                public String 
                getCurencyinventorytype();
    
                public void 
                setCurencyinventorytype(String);
    
                public String 
                toString();
    
                public String 
                available();
    
                public String 
                record();
}

            

VendingMachine_final/build/classes/vending/CurrencyHandler.class

                package vending;

                public 
                synchronized 
                class CurrencyHandler {
    
                private String 
                handler;
    
                private boolean 
                coins;
    
                private boolean 
                paper;
    
                private boolean 
                paperchange;
    
                private boolean 
                coinchange;
    
                public void CurrencyHandler();
    
                public String 
                getHandler();
    
                public void 
                setHandler(String);
    
                public boolean 
                isCoins();
    
                public void 
                setCoins(boolean);
    
                public boolean 
                isPaper();
    
                public void 
                setPaper(boolean);
    
                public boolean 
                isPaperchange();
    
                public void 
                setPaperchange(boolean);
    
                public boolean 
                isCoinchange();
    
                public void 
                setCoinchange(boolean);
    
                public String 
                toString();
}

            

VendingMachine_final/build/classes/vending/CurrencyInventory.class

                package vending;

                public 
                synchronized 
                class CurrencyInventory {
    
                private java.util.List 
                currency;
    
                public void CurrencyInventory();
    
                public void 
                addItem(Currency);
    
                public String 
                printInventory();
    
                public String 
                availableInventory();
    
                public String 
                getCurrencyInventory();
    
                public double 
                getCurrencyValue(int);
    
                public int 
                getInventorySize();
    
                public boolean 
                printChange(double);
    
                public void 
                recordCurrencyAdded(java.util.List);
}

            

VendingMachine_final/build/classes/vending/InventoryItem.class

                package vending;

                public 
                synchronized 
                class InventoryItem {
    
                private java.util.List 
                items;
    
                public void InventoryItem();
    
                public void 
                addItem(Item);
    
                public String 
                printInventory();
    
                public int 
                getInventorySize();
    
                public String 
                getCurrentItemsRecord();
    
                public double 
                getItemPrice(int);
    
                public void 
                recordStockSold(int);
}

            

VendingMachine_final/build/classes/vending/Item.class

                package vending;

                public 
                synchronized 
                class Item {
    
                private String 
                name;
    
                private String 
                container;
    
                private String 
                unit;
    
                private double 
                size;
    
                private int 
                quantity;
    
                private double 
                price;
    
                public void Item();
    
                public String 
                getName();
    
                public void 
                setName(String);
    
                public String 
                getContainer();
    
                public void 
                setContainer(String);
    
                public String 
                getUnit();
    
                public void 
                setUnit(String);
    
                public double 
                getSize();
    
                public void 
                setSize(double);
    
                public int 
                getQuantity();
    
                public void 
                setQuantity(int);
    
                public double 
                getPrice();
    
                public void 
                setPrice(double);
    
                public String 
                toString();
    
                public String 
                record();
}

            

VendingMachine_final/build/classes/vending/Main.class

                package vending;

                public 
                synchronized 
                class Main {
    
                public void Main();
    
                public 
                static void 
                main(String[]);
}

            

VendingMachine_final/build/classes/vending/Purchase.class

                package vending;

                public 
                synchronized 
                class Purchase {
    
                public void Purchase();
    
                public 
                static void 
                updateItemsFile(String, InventoryItem);
    
                public 
                static void 
                updateCurrencyFile(String, CurrencyInventory);
}

            

VendingMachine_final/build/classes/vending/VendingMachine.class

                package vending;

                public 
                synchronized 
                class VendingMachine {
    
                private InventoryItem 
                inventory;
    
                private CurrencyHandler 
                currencyhandler;
    
                private CurrencyInventory 
                currencyinventory;
    
                public void VendingMachine();
    
                public void 
                loadInventory(String);
    
                public void 
                loadCurrencyInventory(String);
    
                public String 
                printInventoryLoad();
    
                public String 
                printCurrencyInventoryLoad();
    
                public void 
                loadCurrencyHandler(String);
    
                public void 
                loadCommands();
    
                public void 
                makePurchase(int, int);
    
                public int 
                itemNumberInput();
    
                public int 
                typesOfCurrencyInput();
    
                public int 
                CurrencyTypeInput();
    
                public void 
                listCommands();
    
                public int 
                readInput();
}

            

VendingMachine_final/currencyHandler.txt

USD,true,true,true,true

VendingMachine_final/currencyInventory.txt

PaperCurrency 100 Dollar Bill 100.0 medium paper 0
PaperCurrency 50 Dollar Bill 50.0 medium paper 0
PaperCurrency 20 Dollar Bill 200.0 medium paper 0
PaperCurrency 10 Dollar Bill 10.0 medium paper 4
PaperCurrency 5 Dollar Bill 5.0 medium paper 8
PaperCurrency 1 Dollar Bill 1.0 medium paper 16
CoinCurrency 50 cent piece 0.5 large metal 10
CoinCurrency Quarter 0.25 medium metal 20
CoinCurrency Dime 0.1 small metal 30
CoinCurrency Nickel 0.05 small metal 40
CoinCurrency penny 0.01 small metal 50

VendingMachine_final/inventory.txt

Diet Coke,1.0,Bottle-soda,liter,0.5,10 Coke,1.0,Bottle-soda,liter,0.5,10 Apple Juice,1.0,Carton-thinRectangle,ounces,6.0,10 Peanuts,0.5,Bag-small,ounces,2.5,10 Potato Chips,0.5,Bag-medium,ounces,6.0,10 Hersey Chocolate,1.0,Bag-medium,ounces,4.0,10

VendingMachine_final/manifest.mf

Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build

VendingMachine_final/MiniProject (1).pdf

605.201 Mini-Project 2:

Please do the following to complete this assignment.

Purpose:

The purpose of this project is to provide non-trivial practice in the use of Java object-oriented programming features to implement an object-oriented design and have a bit of fun doing it.

Resources Needed:

You will need a computer system with Java 7 or greater SE edition run-time and Java Development Kit (JDK). You may optionally use a Java IDE for example NetBeans, Eclipse, etc. However application builders are not allowed.

Submitted Files:

Design and Analysis:

This is an informal essay-style single-spaced word-processed document. The file formats accepted will be announced at project assignment. The length of the document should be between 1 and 1.5 pages. The following subjects should be discussed in this order:

1. General program design. How is the program organized? What major data structures were used? How did you divide the functionality among your classes? How are commands processed? Etc.

2. What alternative approaches were considered and why were they rejected? 3. What did you learn from doing this project and what would you do differently?

Source files:

Each public class must be contained in a separate Java source file. Only one source file will have a main() method and this source will be named VendingMachineSimulator.java. Other source/class names are up to you following the guidelines specified so far in the course.

The format of the Java source must meet the general Java coding style guidelines discussed so far during the course. Pay special attention to naming guidelines, use of appropriate variable names and types, variable scope (public, private, protected, etc.), indentation, and comments. Classes and methods should be commented with JavaDoc-style comments (see below). Please use course office hours or contact the instructor directly if there are any coding style questions.

JavaDocs:

Sources should be commented using JavaDoc-style comments for classes and methods. Each class should have a short comment on what it represents and use the @author annotation. Methods should have a short (usually 1 short sentence) description of what the results are of calling it. Parameters and returns should be documented with the @param and @return annotations respectively with a short comment on each.

JavaDocs must be generated against every project Java source file. They should be generated with a -private option (to document all protection-level classes) and a –d [dir] option to place the resulting files in a javadocs directory/folder at the same level as your source files. See the JavaDocs demonstration for more details.

Submit file:

The submit file is to be a Zip file containing your design and analysis document, your Java sources, and your javadocs directory/folder. Any appropriate file name for this Zip file is acceptable.

If you know how to create a standard Java JAR file, this is also acceptable for your source code. However, make sure you include the source code in your JAR file.

Collaboration:

It is encouraged to discuss technical or small design parts of this project with your fellow students. However the resulting design and implementation must be your own. For example, it is acceptable to discuss different ways of maintaining the vending machine state but not detailed design or implementation information on processing the purchase command. When in doubt, ask during office hours or contact your instructor.

Program Specification:

1. Create a new multi-class Java program which implements a vending machine simulator which contains the following functionality: A) At program startup, the vending machine is loaded with a variety of products in a variety of

packaging for example soda/tonic/Coke in bottles, peanuts in bags, juice in cartons, etc. Also included is the cost of each item. The program should be designed to easily load a different set of products easily (for example, from a file).

Also at program startup, money should be loaded into the vending machine. Money should consist of different monetary objects for the specified currency for example $1 bills, $5 bills, quarters, dimes, etc. Your program should be designed to use different national currencies easily (for example the Euro) without changing source code. Money should be maintained as paper bills and coins, not just amounts.

B) A menu of commands must be provided. At a minimum the menu should consists of the following commands: 1. Display the list of commands 2. Display the vending machine inventory. For each item, this command should result in

displaying a description and current quantity. 3. Display the money currently held in the vending machine. 4. Purchase an item. The result of this selection should be the following actions:

1. Prompt the user to indicate what item to purchase 2. Prompt the user to specify what monetary items are being used for payment (the actual

items for example quarters, dimes, etc.), not a money amount 3. If the user specified enough money to purchase the selected item, the item is purchased

(deducted from inventory), supplied money is added to the vending machine, and any change is returned in the form of monetary items (quarters, dimes, etc.).

4. If the user did not specify enough money for the selected item, the transaction is aborted with the supplied money not added to the machine (not accepted) and the product not purchased (i.e. the state of the vending machine is unchanged).

5. Exit – exits the program displaying a departing message.

2. Additional points to consider: A) You can use the Java Standard Edition (SE) API library as supplied by Oracle (AKA Sun)

except the collection classes other than String and standard arrays (i.e. not ArrayList, Map, Vector, etc.). These other collections will be covered later in the course.

B) When developing complex classes, consider creating a main() method to test them out. Once tested successfully, delete the main() method.

C) You should generate error messages when appropriate, for example on invalid input values or not enough money supplied for the selected item to purchase. Exceptions will be covered later in the course so for this program displaying appropriate messages on the console is fine.

Other Activates:

1. Observe the presentation on JavaDocs.

2. Observe the Vending Machine Simulator demonstration for an example of one implementation.

3. Create a compressed zipped folder containing your Design and Analysis document, your Java source code files, and your javadocs folder.

4. Submit your compressed zipped folder as directed by your instructor.

Assignment Rubric:

Part 70% 80% 90% 100% % of Grade

Design and Analysis Document

All but one subject addressed with relevant, information. Few minor typographical issues. Document is close to assigned length

All assigned subjects address with mostly relevant information. Nicely formatted document. Document is close to assigned length

All assigned subjects address with accurate and relevant. Nicely formatted document. Document is within assigned length

All assigned subjects address with accurate, relevant, and insightful information. Very nicely formatted. Document is within assigned length

15%

Functionality Majority of required function parts work as indicted in the assignment text. One major or 3 minor defects. All major functionality at least partially

Most required function parts work as indicted in the assignment text above and submitted documentation. One major or 3

Nearly all required function parts work as indicted in the assignment text above and submitted documentation. One to two minor defects.

All required function parts work as indicted in the assignment text above and submitted documentation.

55%

working (example change provided but not correct). Design document does not fully reflect functionality.

minor defects. All major functionality at least partially working ((example change provided but not correct).

Code Majority of the code conforms to coding standards as explained and demonstrated so far in the course (ex. method design, naming, formatting, etc.). Five to six minor coding standard violations. Some useful comments. Some JavaDocs commenting. Code compiles with multiple warnings or fails to compile with difficult to diagnose error.

Most of the code conforms to coding standards as explained and demonstrated so far in the course (ex. method design, naming, formatting, etc.). Three to four minor coding standard violations. Mostly useful comments. Public class JavaDocs complete. Code compiles with one to two warnings.

Almost all code conforms to coding standards as explained and demonstrated so far in the course (ex. method design, naming, formatting, etc.). One to two minor coding standard violations. Appropriate level of useful comments. Public class JavaDocs complete. Code compiles. Code compiles with no errors or warnings.

All code conforms to coding standards as explained and demonstrated so far in the course (ex. method design, naming, formatting, etc.). Appropriate level of useful comments. Complete JavaDocs as specified. Code compiles with no errors or warnings.

25%

Submit package

More than one file submitted in incorrect format. Files not enclosed in the specified compressed file.

All but one file submitted in correct format. Files not enclosed in the specified compressed file.

All file submitted in correct format but not in the specified compressed file.

All file submitted in correct file formats and compressed as specified.

5%

VendingMachine_final/nbproject/build-impl.xml

Must set src.dir Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent Must select some files in the IDE or set javac.includes To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}" Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set run.class Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url Must select some files in the IDE or set javac.includes Some tests failed; see details above. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url

VendingMachine_final/nbproject/genfiles.properties

build.xml.data.CRC32=c0328b06 build.xml.script.CRC32=fe5fa101 [email protected] # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=c0328b06 nbproject/build-impl.xml.script.CRC32=c07d815d nbproject/[email protected]

VendingMachine_final/nbproject/private/private.properties

compile.on.save=true user.properties.file=C:\\Users\\justi\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

VendingMachine_final/nbproject/project.properties

annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} # Files in build.classes.dir which should be excluded from distribution jar dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/VendingMachine.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.external.vm=true javac.processorpath=\ ${javac.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=vending.Main manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs= run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src test.src.dir=test

VendingMachine_final/nbproject/project.xml

org.netbeans.modules.java.j2seproject VendingMachine

VendingMachine_final/src/currencyHandler.txt

USD,true,true,true,true

VendingMachine_final/src/currencyInventory.txt

PaperCurrency 100 Dollar Bill 100.0 medium paper 0
PaperCurrency 50 Dollar Bill 50.0 medium paper 0
PaperCurrency 20 Dollar Bill 200.0 medium paper 0
PaperCurrency 10 Dollar Bill 10.0 medium paper 4
PaperCurrency 5 Dollar Bill 5.0 medium paper 8
PaperCurrency 1 Dollar Bill 1.0 medium paper 16
CoinCurrency 50 cent piece 0.5 large metal 10
CoinCurrency Quarter 0.25 medium metal 20
CoinCurrency Dime 0.1 small metal 30
CoinCurrency Nickel 0.05 small metal 40
CoinCurrency penny 0.01 small metal 50

VendingMachine_final/src/inventory.txt

Diet Coke,1.0,Bottle-soda,liter,0.5,10 Coke,1.0,Bottle-soda,liter,0.5,10 Apple Juice,1.0,Carton-thinRectangle,ounces,6.0,10 Peanuts,0.5,Bag-small,ounces,2.5,10 Potato Chips,0.5,Bag-medium,ounces,6.0,10 Hersey Chocolate,1.0,Bag-medium,ounces,4.0,10

VendingMachine_final/src/vendingmachine/Currency.java

VendingMachine_final/src/vendingmachine/Currency.java

package  vending ;

/**
 *
 *  @author  DCCLXXVII
 * This is the currency class whic is used
 * to create currency objects with the given characteristics
 *
 */
public   class   Currency   {

     private   String  name ;
     private   double  value ;
     private   String  size ;
     private   String  material ;
     private   int  quantity ;
     private   String  curencyinventorytype ;

     /**
     * constuctor
     */
     public   Currency (){



     /**
     * setters set   @param  fieldvalue
     *  and
     *  getters
     *  @return  fieldValue
     */
     public   String  getName ()   {
         return  name ;
     }

     public   void  setName ( String  name )   {
         this . name  =  name ;
     }

     public   double  getValue ()   {
         return  value ;
     }

     public   void  setValue ( double  value )   {
         this . value  =  value ;
     }

     public   String  getSize ()   {
         return  size ;
     }

     public   void  setSize ( String  size )   {
         this . size  =  size ;
     }

     public   String  getMaterial ()   {
         return  material ;
     }

     public   void  setMaterial ( String  material )   {
         this . material  =  material ;
     }

     public   int  getQuantity ()   {
         return  quantity ;
     }

     public   void  setQuantity ( int  quantity )   {
         this . quantity  =  quantity ;
     }

     public   String  getCurencyinventorytype ()   {
         return  curencyinventorytype ;
     }

     public   void  setCurencyinventorytype ( String  curencyinventorytype )   {
         this . curencyinventorytype  =  curencyinventorytype ;
     }

     /**
     *  @return  class fields contents
     */
     public   String  toString (){

         return   "CurrencyInventory: " + curencyinventorytype  + " CurrencyUnit: Name: " +
        name +   " Value: " + value +   " Size: " + size  + " Material: " + material +
         " Quantity: " + quantity  + "\n" ;
     }
     /**
     *  @return  class fields contents
     */
public   String  available (){

         return  curencyinventorytype  + " CurrencyUnit: Name: " +
        name +   " Value: " + value +   " Size: " + size  + " Material: " + material + "\n" ;
     }

/**
 *  @return  class fields contents
 */

public   String  record (){
     return  curencyinventorytype + "," + name + "," + value + "," + size + "," + material + "," + quantity ;
}

}
}

VendingMachine_final/src/vendingmachine/CurrencyHandler.java

VendingMachine_final/src/vendingmachine/CurrencyHandler.java

package  vending ;

public   class   CurrencyHandler   {
    
     private   String  handler ;
     private   boolean  coins ;
     private   boolean  paper ;
     private   boolean  paperchange ;
     private   boolean  coinchange ;
    
     public   CurrencyHandler (){
        
        handler =   "Not set" ;
        coins =   false ;
        paper =   false ;
        paperchange =   false ;
        coinchange =   false ;
        
     }

     public   String  getHandler ()   {
         return  handler ;
     }

     public   void  setHandler ( String  handler )   {
         this . handler  =  handler ;
     }

     public   boolean  isCoins ()   {
         return  coins ;
     }

     public   void  setCoins ( boolean  coins )   {
         this . coins  =  coins ;
     }

     public   boolean  isPaper ()   {
         return  paper ;
     }

     public   void  setPaper ( boolean  paper )   {
         this . paper  =  paper ;
     }

     public   boolean  isPaperchange ()   {
         return  paperchange ;
     }

     public   void  setPaperchange ( boolean  paperchange )   {
         this . paperchange  =  paperchange ;
     }

     public   boolean  isCoinchange ()   {
         return  coinchange ;
     }

     public   void  setCoinchange ( boolean  coinchange )   {
         this . coinchange  =  coinchange ;
     }
    
     public   String  toString (){
        
         return   "CurrencyHandler: " +  handler  + " Handles Paper Currrency: " +  paper  +  
                 " Handles Coins: " + coins +   "Provides Change Paper: " + paperchange +
                 " Provides Change Coins: " + coinchange ;
     }
    

}

VendingMachine_final/src/vendingmachine/currencyHandler.txt

USD,true,true,true,true

VendingMachine_final/src/vendingmachine/CurrencyInventory.java

VendingMachine_final/src/vendingmachine/CurrencyInventory.java

package  vending ;

import  java . util . ArrayList ;
import  java . util . List ;
/**
 * 
 *  @author  DCCLXXVII
 * this class handles the collection of currencies
 *
 */

public   class   CurrencyInventory   {
    
     private   List < Currency >  currency ;
    
     public   CurrencyInventory (){
        
        currency =   new   ArrayList <> ();
     }
    
     public   void  addItem ( Currency  curr ){
        
        currency . add ( curr );
     }
    
     /**
     * 
     *  @return  currencyList This is the list of currency loaded from txt file
     */
     public   String  printInventory (){
         String  inventory = "" ;
        
         for ( int  i = 0 ; i < currency . size (); i ++ ){
            
            inventory  +=  currency . get ( i ). toString ();
         }
        
         return  inventory ;
     }
    
    
     /**
     * 
     *  @return  currencyList This is the list of currency available
     */
     public   String  availableInventory (){
         String  inventory = "Available Currency Denominations. \n" ;
        
         for ( int  i = 0 ; i < currency . size (); i ++ ){
            
            inventory  +=   "Currency #: " + i + ": " + currency . get ( i ). available ();
         }
        
         return  inventory ;
     }
    
     /**
     * 
     *  @return  currencyList this is the current list of currency 
     */
    
     public   String  getCurrencyInventory (){
String  inventory = "" ;
        
         for ( int  i = 0 ; i < currency . size (); i ++ ){
            
            inventory  += currency . get ( i ). record () + "\n" ;
         }
        
         return  inventory ;
        
     }
    
    
     /**
     * get the value of a single currency
     *  @param  currencyType
     *  @return
     */
     public   double  getCurrencyValue ( int  currencyType ){
        
        
         return  currency . get ( currencyType ). getValue ();
        
     }
    
     /**
     * 
     *  @return  currencyList size
     */
    
public   int  getInventorySize (){
        
         return  currency . size ();
     }

/**
 * 
 *  @param  change
 *  @return  boolean This is to check whether there is sufficient amount to give change
 */

public   boolean  printChange ( double  change ){
     boolean  state =   false ;
     double  checkChange =  change ;
    
     for ( int  i = 0 ; i < currency . size (); i ++ ){
        
         double  amountPerCurency =  currency . get ( i ). getValue () * currency . get ( i ). getQuantity ();
         if ( checkChange % currency . get ( i ). getValue () == 0   &&  amountPerCurency >= checkChange  &&  checkChange  !=   0.0 ){
            
            state = true ;
             int  printControl =    ( int )   (( int )  checkChange / currency . get ( i ). getValue ());
             for ( int  j = 0 ;  j < printControl ; j ++ ){
                 System . out . print ( currency . get ( i ). available ());
             }
            
             double  remainingCurrencyAmount = amountPerCurency - checkChange ;
            currency . get ( i ). setQuantity (( int )   ( remainingCurrencyAmount / currency . get ( i ). getValue ()));
            checkChange = 0.0 ;
            
         }
        
        
     }
    
    
    
    
     return  state ;
}


/**
 * record currency added after a purchase
 *  @param  count
 */

public   void  recordCurrencyAdded ( List < Integer >  count ){
     for ( int  i = 0 ;  i < count . size (); i ++ ){
        
        currency . get ( count . get ( i )). setQuantity ( currency . get ( count . get ( i )). getQuantity () + 1 );
     }
    
}


}

VendingMachine_final/src/vendingmachine/currencyInventory.txt

PaperCurrency 100 Dollar Bill 100.0 medium paper 0
PaperCurrency 50 Dollar Bill 50.0 medium paper 0
PaperCurrency 20 Dollar Bill 200.0 medium paper 0
PaperCurrency 10 Dollar Bill 10.0 medium paper 4
PaperCurrency 5 Dollar Bill 5.0 medium paper 8
PaperCurrency 1 Dollar Bill 1.0 medium paper 16
CoinCurrency 50 cent piece 0.5 large metal 10
CoinCurrency Quarter 0.25 medium metal 20
CoinCurrency Dime 0.1 small metal 30
CoinCurrency Nickel 0.05 small metal 40
CoinCurrency penny 0.01 small metal 50

VendingMachine_final/src/vendingmachine/inventory.txt

Diet Coke,1.0,Bottle-soda,liter,0.5,10 Coke,1.0,Bottle-soda,liter,0.5,10 Apple Juice,1.0,Carton-thinRectangle,ounces,6.0,10 Peanuts,0.5,Bag-small,ounces,2.5,10 Potato Chips,0.5,Bag-medium,ounces,6.0,10 Hersey Chocolate,1.0,Bag-medium,ounces,4.0,10

VendingMachine_final/src/vendingmachine/InventoryItem.java

VendingMachine_final/src/vendingmachine/InventoryItem.java

package  vending ;

import  java . util . ArrayList ;
import  java . util . List ;


/**
 *
 *  @author  DCCLXXVII
 *Hanldes the collection of items
 */
public   class   InventoryItem   {

     private   List < Item >  items ;

     public   InventoryItem (){

        items =   new   ArrayList <> ();
     }

     public   void  addItem ( Item  item ){

        items . add ( item );
     }


     /**
     *
     *  @return  itemsList This is the list of all items loaded from the txt file
     */
     public   String  printInventory (){
         String  inventory = "" ;

         for ( int  i = 0 ; i < items . size (); i ++ ){

            inventory  +=  i + ": " +  items . get ( i ). toString ();
         }

         return  inventory ;
     }

     /**
     *
     *  @return  itemsList size
     */
     public   int  getInventorySize (){

         return  items . size ();
     }

     /**
     *
     *  @return  itemsList in record form
     */
     public   String  getCurrentItemsRecord (){
         String  inventory = "" ;

                 for ( int  i = 0 ; i < items . size (); i ++ ){

                    inventory  +=  items . get ( i ). record () + "\n" ;
                 }

                 return  inventory ;

     }


     /**
     *
     *  @param  itemNo
     *  @return  price of a single item
     */
     public   double  getItemPrice ( int  itemNo ){
         return  items . get ( itemNo ). getPrice ();
     }

     public   void  recordStockSold ( int  itemNO ){
        items . get ( itemNO ). setQuantity ( items . get ( itemNO ). getQuantity () - 1 );
     }

}

VendingMachine_final/src/vendingmachine/Item.java

VendingMachine_final/src/vendingmachine/Item.java

package  vending ;

/**
 *
 *  @author  DCCLXXVII
 *Handles item objects
 */
public   class   Item   {

     private    String  name ;
     private    String  container ;
     private   String  unit ;
     private   double  size ;
     private    int  quantity ;
     private   double  price ;


     public   Item (){

     }
     /**
     * setters
     *  @param  fieldValue
     *
     * getters
     *  @return  fieldValue
     */
     public   String  getName ()   {
         return  name ;
     }
     public   void  setName ( String  name )   {
         this . name  =  name ;
     }
     public   String  getContainer ()   {
         return  container ;
     }
     public   void  setContainer ( String  container )   {
         this . container  =  container ;
     }
     public   String  getUnit ()   {
         return  unit ;
     }
     public   void  setUnit ( String  unit )   {
         this . unit  =  unit ;
     }
     public   double  getSize ()   {
         return  size ;
     }
     public   void  setSize ( double  size )   {
         this . size  =  size ;
     }
     public   int  getQuantity ()   {
         return  quantity ;
     }
     public   void  setQuantity ( int  quantity )   {
         this . quantity  =  quantity ;
     }


     public   double  getPrice ()   {
         return  price ;
     }
     public   void  setPrice ( double  price )   {
         this . price  =  price ;
     }

     /**
     *  @return  classFieldsVlaues
     */
     public   String  toString (){

         return   "InventoryItem: Name: " + name + " Price: "   + price +
                 " Container: " + container +   " Unit: " +  unit  + " Size:  " +
                size +   " Quantity: " + quantity  + " IN STOCK \n" ;
     }

     /**
     *  @return  classFieldsVlaues
     */

     public   String  record (){
         return  name  + "," + price + "," + container + "," + unit + "," + size + "," + quantity ;
     }





}

VendingMachine_final/src/vendingmachine/Main.java

VendingMachine_final/src/vendingmachine/Main.java

package  vending ;

/**
 * 
 *  @author  DCCLXXVII
 * this is the main class where the program execution is 
 * called from
 *
 */

public   class   Main   {

     public   static   void  main ( String []  args )   {
    
        
         VendingMachine  machine  =   new   VendingMachine ();
      
       
            /**
            * loadInventory from a text file
            */
            machine . loadInventory ( "inventory.txt" );
            
             /**
             * loadCurrencyHandler from a text file
             */
            
            machine . loadCurrencyHandler ( "currencyHandler.txt" );
            
             /**
             * loadCurencyInventory from a text file
             */
            
            machine . loadCurrencyInventory ( "currencyInventory.txt" );
            
             /**
             * list commands option
             */
          machine . listCommands ();
          
           /**
           * process command input
           */
            machine . loadCommands ();
            
           
            
         
           
        
       
     }
}

VendingMachine_final/src/vendingmachine/Purchase.java

VendingMachine_final/src/vendingmachine/Purchase.java

package  vending ;

import  java . io . File ;
import  java . io . FileWriter ;
import  java . io . IOException ;
import  java . io . PrintWriter ;

/**
 * 
 *  @author  DCCLXXVII
 * 
 * This class updates the test files of both currency and items
 *
 */

public   class   Purchase {
    
    
    
    
    
     /**
     * upadte the items after a successfull purchase
     *  @param  filepath
     *  @param  items
     */
    
     public   static   void  updateItemsFile ( String  filepath ,   InventoryItem  items ){
        
         try {
            
            
             File  file =   new   File ( filepath );
             PrintWriter  out =   new   PrintWriter (
                     new   FileWriter ( file , false ));
                out . println (  items . getCurrentItemsRecord ());
            out . close ();
        
            
            
            
            
             }
             catch   ( IOException  e ){
                
                 System . out . println ( e . getMessage ());
             }
                
     }
    
     /**
     * update currency file after a successful purchase
     *  @param  filepath
     *  @param  currency
     */
    
     public    static   void  updateCurrencyFile ( String  filepath ,   CurrencyInventory  currency ){
        
try {
            
            
             File  file =   new   File ( filepath );
             PrintWriter  out =   new   PrintWriter (
                     new   FileWriter ( file , false ));
                out . println (  currency . getCurrencyInventory ());
            out . close ();
        
            
            
            
            
             }
             catch   ( IOException  e ){
                
                 System . out . println ( e . getMessage ());
             }
                
                
             }

}

VendingMachine_final/src/vendingmachine/VendingMachine.java

VendingMachine_final/src/vendingmachine/VendingMachine.java

package  vending ;

import  java . io . BufferedReader ;
import  java . io . File ;
import  java . io . FileReader ;
import  java . io . IOException ;
import  java . util . ArrayList ;
import  java . util . List ;
import  java . util . Scanner ;

public   class   VendingMachine   {
     private    InventoryItem  inventory ;
     private    CurrencyHandler  currencyhandler ;
     private    CurrencyInventory  currencyinventory ;

     /**
     * constructor
     */
     public   VendingMachine ()   {
        inventory =   new   InventoryItem ();
        currencyhandler =   new   CurrencyHandler ();
        currencyinventory =   new   CurrencyInventory ();


     }

     /**
     * loadInventory from a text file
     */
     public   void  loadInventory ( String  filePath ){
         try {
             File  file =   new   File ( "" );

             FileReader  fileReader  =   new   FileReader ( file );
             BufferedReader  bufferedReader  =   new   BufferedReader ( fileReader );
             String  temp  = null ;
             String []  list ;
             while   (( temp  =  bufferedReader . readLine ())   !=   null )   {

                        list =  temp . split ( "," );
                         if ( list . length  > 1 ){
                         Item  item =   new   Item ();
                        item . setName ( list [ 0 ]);
                        item . setPrice (   Double . parseDouble (  list [ 1 ]));
                        item . setContainer ( list [ 2 ]);
                        item . setUnit ( list [ 3 ]);
                        item . setSize ( Double . parseDouble ( list [ 4 ]));
                        item . setQuantity ( Integer . parseInt ( list [ 5 ]));


                        inventory . addItem ( item );
                         }

                     }

         }
         catch   ( IOException  e ){

             System . out . println ( e . getMessage ());
         }
     }


     /**
     * loadCurencyInventory from a text file
     */

public   void  loadCurrencyInventory ( String  filePath ){

         try {
         File  file =   new   File ( "" );
         //File file = new File("c:/example/filedata.txt");
         FileReader  fileReader  =   new   FileReader ( file );
         BufferedReader  bufferedReader  =   new   BufferedReader ( fileReader );
                     String  temp  = null ;

                     String []  list ;

                     while   (( temp  =  bufferedReader . readLine ())   !=   null )   {

                        list =  temp . split ( "," );
                         if ( list . length  > 1 ){
                         Currency  currency =   new   Currency ();
                        currency . setCurencyinventorytype ( list [ 0 ]);
                        currency . setName ( list [ 1 ]);
                        currency . setValue ( Double . parseDouble ( list [ 2 ]));
                        currency . setSize ( list [ 3 ]);
                        currency . setMaterial ( list [ 4 ]);
                        currency . setQuantity ( Integer . parseInt ( list [ 5 ]));



                        currencyinventory . addItem ( currency );
                         }

                     }

         }
         catch   ( IOException  e ){

             System . out . println ( e . getMessage ());
         }
     }


     /**
     *
     *  @return   itemslist of all items in stock
     */
     public   String  printInventoryLoad (){

         return  inventory . printInventory ();
     }

     /**
     *
     *  @return  Currencylist of all currency available
     */
  public   String  printCurrencyInventoryLoad (){

         return  currencyhandler . toString () + "\n" +  currencyinventory . printInventory ();
     }


  /**
  * loadCurrencyHandler from a text file
  */
     public   void  loadCurrencyHandler ( String  filePath ){

         try {
         File  file =   new   File ( "" );
         //File file = new File("c:/example/filedata.txt");
         FileReader  fileReader  =   new   FileReader ( file );
         BufferedReader  bufferedReader  =   new   BufferedReader ( fileReader );
                     String  temp  = null ;

                     String []  list ;

                     while   (( temp  =  bufferedReader . readLine ())   !=   null )   {

                        list =  temp . split ( "," );

                        currencyhandler . setHandler ( list [ 0 ]);
                        currencyhandler . setPaper ( Boolean . parseBoolean ( list [ 1 ]));
                        currencyhandler . setCoins ( Boolean . parseBoolean ( list [ 2 ]));
                        currencyhandler . setPaperchange ( Boolean . parseBoolean ( list [ 3 ]));
                        currencyhandler . setCoinchange ( Boolean . parseBoolean ( list [ 4 ]));

                     }

         }
         catch   ( IOException  e ){

             System . out . println ( e . getMessage ());
         }



     }


     /**
     * process the command input choice
     */
     public   void  loadCommands (){




         int  navvalue = readInput ();

         if ( navvalue  ==   0 ){
            listCommands ();
            loadCommands ();

         } else   if ( navvalue  ==   1   ){
          System . out . println ( printInventoryLoad ());
          System . out . print ( "Command:" );
         loadCommands ();

         }
         else   if ( navvalue  ==   2 ){

             System . out . println ( printCurrencyInventoryLoad ());
             System . out . print ( "Command:" );
             loadCommands ();
                 }
         else   if ( navvalue  == 3 ){



             int  itemNo =  itemNumberInput ();

             int  typesOfCurrency =  typesOfCurrencyInput ();


            makePurchase ( itemNo ,  typesOfCurrency );

             System . out . print ( "Command:" );
             loadCommands ();

                 }
         else   if ( navvalue  ==   - 1   ){
             System . out . println ( "Goodbye!" );
             System . exit ( 0 );

                 }
         else {

             System . out . println ( "Invalid input, please try agian" );
            listCommands ();
            loadCommands ();

         }



     }


    /**
    *  process purchase
    *  @param  itemNo
    *  @param  typesOfCurrency
    */
public    void  makePurchase ( int  itemNo ,   int  typesOfCurrency ){

         Double  totalAmount = 0.0 ;
         List < Integer >  currencyPickCount =   new   ArrayList <> ();
         for ( int  i = 0 ;  i < typesOfCurrency ; i ++ ){

             System . out . println ( currencyinventory . availableInventory ());
             int  currencyPicked =   CurrencyTypeInput ();

            totalAmount +=  currencyinventory . getCurrencyValue ( currencyPicked );
            currencyPickCount . add ( currencyPicked );

         }


         if (  inventory . getItemPrice ( itemNo )   <=  totalAmount ){
                 double  change =  totalAmount - inventory . getItemPrice ( itemNo );

             System . out . printf ( "Change :%4f \n" , change );

             if ( currencyinventory . printChange ( change )){
            currencyinventory . recordCurrencyAdded ( currencyPickCount );

            inventory . recordStockSold ( itemNo );


             Purchase . updateItemsFile ( "inventory.txt" ,  inventory );

             Purchase . updateCurrencyFile ( "currencyInventory.txt" ,  currencyinventory );




             System . out . println ( "Item Purchased successful" );
             } else {
                 System . out . println ( "Vending machine out of cash" );
             }

         } else {
             System . out . println ( "Insufficient amount" );
         }


     }


     /**
     *
     *  @return  itemNo The item number of the item selected
     */
     public   int  itemNumberInput (){
         System . out . print ( "item #:" );

         int  itemNotest =   readInput ();

         if ( itemNotest ==   7   ||  itemNotest  >=  inventory . getInventorySize ()   ||  itemNotest  < 0 ){
             System . out . println ( "Invalid item input, please try agian" );
            itemNumberInput ();

         }

         return  itemNotest ;
     }


     /**
     *
     *  @return  currencyCount This is the currency count  selected
     */
     public   int  typesOfCurrencyInput (){
         System . out . print ( "How many differnt currency items?:" );

         int  typestest =   readInput ();

         if ( typestest ==   7   ||  typestest  >=  currencyinventory . getInventorySize ()   ||  typestest  <= 0 ){
             System . out . println ( "Invalid currency input, please try agian" );
            typesOfCurrencyInput ();

         }

         return  typestest ;
     }

     /**
     *
     *  @return  currencySelected This is the type of curency selected
     */
     public   int   CurrencyTypeInput (){
         System . out . print ( "Currency type:" );

         int  typestest =   readInput ();

         if ( typestest ==   7   ||  typestest  >=  currencyinventory . getInventorySize ()   ||  typestest  < 0 ){
             System . out . println ( "Invalid currency input, please try agian" );
            typesOfCurrencyInput ();

         }

         return  typestest ;
     }


     /**
     * list the commands on the console
     */
     public   void  listCommands (){

         System . out . println ( ""
                 +   "Available Commands \n" );

         System . out . printf ( "Show Commands:%8s\n"
                 +   "Display Inventory:%4s\n"
                 +   "Display Currency:%5s\n"
                 +   "Purchase Item:%8s\n"
                 +   "Exit:%17s\n" , "0" , "1" , "2" , "3" , "-1" );
         System . out . print ( "Command:" );
     }

     /**
     *
     *  @return  inputValue This is the command value inputed
     */
     public   int  readInput (){
         int  inputValue = 7 ;
         Scanner  in  =   new   Scanner ( System . in );
         String  input =  in . nextLine ();
         try {
         inputValue =   Integer . parseInt ( input );
          return  inputValue ;

         } catch ( NumberFormatException  e ){

             return  inputValue ;
         }




     }











}