assignment part 4

profilegental1983
ordering_system2.zip

Ordering System IP2/build/classes/.netbeans_automatic_build

Ordering System IP2/build/classes/.netbeans_update_resources

Ordering System IP2/build/classes/online/ordering/system/ip1/OnlineOrderingSystemIP1.class

                package online.ordering.system.ip1;

                public 
                synchronized 
                class OnlineOrderingSystemIP1 {
    
                public void OnlineOrderingSystemIP1();
    
                private 
                static String 
                getStringInput(String);
    
                private 
                static double 
                totalCost(int, double, double);
    
                private 
                static String 
                getPhoneNumber();
    
                private 
                static int 
                getNumericInput(String);
    
                static void 
                readOrders();
    
                static void 
                writeOrder(String, int, String, String, String, double);
    
                public 
                static void 
                main(String[]);
}

            

Ordering System IP2/build.xml

Builds, tests, and runs the project Online Ordering System IP1.

Ordering System IP2/manifest.mf

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

Ordering System IP2/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

Ordering System IP2/nbproject/genfiles.properties

build.xml.data.CRC32=3fef0086 build.xml.script.CRC32=4bdc748b [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=3fef0086 nbproject/build-impl.xml.script.CRC32=ade8263c nbproject/[email protected]

Ordering System IP2/nbproject/private/private.properties

compile.on.save=true user.properties.file=C:\\Users\\George k\\AppData\\Roaming\\NetBeans\\7.4\\build.properties

Ordering System IP2/nbproject/private/private.xml

Ordering System IP2/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}/Online_Ordering_System_IP1.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.processorpath=\ ${javac.classpath} javac.source=1.7 javac.target=1.7 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=online.ordering.system.ip1.OnlineOrderingSystemIP1 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

Ordering System IP2/nbproject/project.xml

org.netbeans.modules.java.j2seproject Online Ordering System IP1

Ordering System IP2/order.txt

John No Blue 4 (998)567-6453 3355.8 John Yes Blue 3 (678)878-9567 2516.85 Mwangi No blue 5 (455)123-7895 4194.75

Ordering System IP2/src/online/ordering/system/ip1/OnlineOrderingSystemIP1.java

Ordering System IP2/src/online/ordering/system/ip1/OnlineOrderingSystemIP1.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package  online . ordering . system . ip1 ;

import  java . io . BufferedReader ;
import  java . io . BufferedWriter ;
import  java . io . FileInputStream ;
import  java . io . FileOutputStream ;
import  java . io . IOException ;
import  java . io . InputStreamReader ;
import  java . io . OutputStreamWriter ;
import  java . text . DecimalFormat ;
import  java . util . ArrayList ;
import  java . util . HashSet ;
import  java . util . Set ;
import  java . util . regex . Matcher ;
import  java . util . regex . Pattern ;
import  javax . swing . JOptionPane ;

/**
 *
 *  @author  James.Williams
 * 10/13/2014
 */
public   class   OnlineOrderingSystemIP1   {
     private   static   String  getStringInput ( String  prompt ){
         String  input = null ;
         int  count = 0 ;
         while ( count < 3 ){
        input = JOptionPane . showInputDialog ( prompt );
         if ( ! ( input . trim ()). isEmpty ()){
             break ;
         }
        count ++ ;
         //JOptionPane.showMessageDialog(null, "You must enter something in the prompt,\n Please try again, count remains "+(3-count));
         }
          if ( input . isEmpty ()){
              JOptionPane . showMessageDialog ( null ,   "You must enter something in the prompt,\n Please try again latter" );
             System . exit ( 1 );
          }
         return  input ;
     }
     private   static   double  totalCost ( int  number , double  cost , double  salesTaxRate ){
         double  total = number * cost ;
         double  tax = total * salesTaxRate / 100 ;
         return   ( total + tax );
     }
     private   static   String  getPhoneNumber (){
         int  count = 0 ;
         String  phone = "" ;
         boolean  correct = false ;
         do {
         String  regex = "\\((\\d{3})\\)(\\d{3})[-](\\d{4})$" ;
         Pattern  p = Pattern . compile ( regex );
        phone = JOptionPane . showInputDialog ( "Enter your phone number" );
         Matcher  match = p . matcher ( phone );
         if ( match . matches ()){  
            correct = true ;
             break ;
         }
         JOptionPane . showMessageDialog ( null ,   "You entered an invalid phone number" );
        count ++ ;
         } while ( count < 3 );
         if ( ! correct ){
             JOptionPane . showMessageDialog ( null ,   "You entered an invalid phone number three times\nPlease try again latter" );
             System . exit ( 1 );
         }
         return  phone ;
     }
     private   static   int  getNumericInput ( String  s ){
         int  quantity = 0 ;
         boolean  isNumber = false ;
         int  count = 1 ;
                 do {
                      if ( count > 3 )
                             System . exit ( 1 );
                     try {
                        quantity = Integer . parseInt ( getStringInput ( "Please enter quantity to order" ));
                         //Checks to see the number entered is within the rage 1-99
                         if ( quantity > 1   &&  quantity <= 99 )  
                            isNumber = true ;
                     } catch ( NumberFormatException  rr ){
                         JOptionPane . showMessageDialog ( null ,   "Quantity must be a number" );
                         //Exits if the user enters the wrong number three times
                     }
                    count ++ ;
                 } while ( ! isNumber );
              return  quantity ;
}
     static   void  readOrders (){
         ArrayList < String [] >  list = new   ArrayList <> ();
         String [] data = new   String [ 6 ];
         String  separator = "------------------------------------------------------\n" ;
         try {
             //Creates a file if it does not exist and appends the text to the end of the file
         FileInputStream  fi = new   FileInputStream ( "order.txt" );
         BufferedReader  bw = new   BufferedReader ( new   InputStreamReader ( fi ));
         while ( bw . ready ()){
        data [ 0 ] = bw . readLine ();   //Name
        data [ 1 ] = bw . readLine ();   //customer return
        data [ 2 ] = bw . readLine ();   //tablet color
        data [ 3 ] = bw . readLine ();   //Quantity
        data [ 4 ] = bw . readLine ();   //Phone number
        data [ 5 ] = bw . readLine ();
        list . add ( data );
         }
         } catch ( IOException  ee ){
             JOptionPane . showMessageDialog ( null ,   "Could not write the file: \nerror description: \n" + ee . getMessage ());
         }
         String  message = "Thankyou for your order\n" ;
         for ( String [] s : list ){
            message += "Name: " + s [ 0 ] + "\nRetruning Customer: " + s [ 1 ] + "\n Color: " + s [ 2 ] + "\n Quantity: " + s [ 3 ] + "\n Phone: " + s [ 4 ] + "\nTotal cost: " + s [ 5 ] + "\n" + separator ;
         }
         JOptionPane . showMessageDialog ( null ,  message );
     }
     static   void  writeOrder ( String  name , int  quantity , String  color , String  phone , String  cReturn , double  total ){
         FileOutputStream  fs = null ;
         BufferedWriter  bw = null ;
         DecimalFormat  df = new   DecimalFormat ( "#.00" );
         try {
             //Creates a file if it does not exist and appends the text to the end of the file
        fs = new   FileOutputStream ( "order.txt" , true );
        bw = new   BufferedWriter ( new   OutputStreamWriter ( fs ));
        bw . write ( name );
        bw . newLine ();
        bw . write ( cReturn );
        bw . newLine ();
        bw . write ( color );
        bw . newLine ();
        bw . write ( String . valueOf ( quantity ));
        bw . newLine ();
        bw . write ( phone );
        bw . newLine ();
        bw . write ( String . valueOf ( df . format ( total )));
        bw . newLine ();
        bw . flush ();
         } catch ( IOException  ee ){
             JOptionPane . showMessageDialog ( null ,   "Could not write the file: \nerror description: \n" + ee . getMessage ());
         } finally {
         try {
             if ( fs != null ){
                fs . close ();
             }
             if ( bw != null ){
                bw . close ();
             }
         } catch ( Exception  e ){
            
         }
     }
     }
     /**
     *  @param  args the command line arguments
     */
     public   static   void  main ( String []  args )   {
         // declare variables
         Set < String >  colors = new   HashSet < String > ();
        colors . add ( "blue" );
        colors . add ( "yellow" );
        colors . add ( "white" );
        colors . add ( "deep dish" );
             DecimalFormat  df = new   DecimalFormat ( "#.00" );
         String  openingMsg ,  customerName ,  nameOutputMsg
               ,  customerReturn ,  returnOutputMsg ,  
               greetingOutputMsg ,  outputMsg ,
                           colorOutputMsg ,  tabletColor , totalCostMsg , phoneNumber ;
                 int  quantity = 0 ;
                 double  unitCost = 799 ;
                 double  totalCost = 0 ;
                 double  taxRate = 5 ;
         // display opening message
        openingMsg  =   "*** Welcome to Microsoft's Online Ordering System ***\n"
                    +   "                     It's a great day to order a Tablet!" ;
         JOptionPane . showMessageDialog ( null ,  openingMsg );

         // get required input using dialogs
        customerName    =  getStringInput ( "Please enter your name: " );
                 //Check to see whether the customer entered a yes or No
                 int  count = 1 ;
                 do {
                    customerReturn  = getStringInput ( "Are you a returning customer (yes or no)? " );
                 if ( customerReturn . equalsIgnoreCase ( "yes" ) ||  customerReturn . equalsIgnoreCase ( "no" )){
                     break ;
                 } else {
                     JOptionPane . showMessageDialog ( null ,   "You must answer a Yes or No, please try again" );
                    count ++ ;
                 }
                 } while ( count < 3 );
                 if ( count > 3 ) System . exit ( 0 );
                 // Addition of Color Selection
                count = 1 ;
                 do {
                     Object  color [] = colors . toArray ();
                tabletColor       =  getStringInput ( "Please select a color for your Tablet: \n" + color . toString ());
                 if ( count == 3 ){
                     JOptionPane . showMessageDialog ( null ,   "Colors invalid" );
                     System . exit ( 0 );
                 }
                count ++ ;
                
                 } while ( ! colors . contains ( tabletColor ));
                quantity = getNumericInput ( "Please enter quantity" );
                totalCost = totalCost ( quantity , unitCost , taxRate );
                phoneNumber = getPhoneNumber ();
                 // build output strings
        nameOutputMsg      =   "Welcome "   +  customerName  +   ".\n\n" ;
        returnOutputMsg    =   "Your return customer status is "   +  customerReturn  +   ".\n" ;
        colorOutputMsg  =   "Your Tablet color is: "   +  tabletColor  +   "\n" ;
                totalCostMsg = "Total cost for " + quantity + " item(s) is: $" + df . format ( totalCost ) + "\n Phone number: " + phoneNumber + "\n" ;
                greetingOutputMsg  =   "Thank you for visiting Microsoft!"   +   "\n\n"
         +   "Your order should ship in less than 48 hours.\n" ;
                
         // create and display output string
        outputMsg  =  nameOutputMsg  +  returnOutputMsg  +  colorOutputMsg  + totalCostMsg + greetingOutputMsg ;
         JOptionPane . showMessageDialog ( null ,  outputMsg );
                writeOrder ( customerName , quantity , tabletColor , phoneNumber , customerReturn , totalCost );
                 int  choice = JOptionPane . showConfirmDialog ( null ,   "Would you like to read the orders from file?" , "Read orders" , JOptionPane . OK_CANCEL_OPTION );
                 if ( choice == JOptionPane . OK_OPTION ){
                    readOrders ();
                 }
         System . exit ( 0 );
     }   // end main()

}   // end class PizzasRUsPhase1