Exemplo n.º 1
0
        public void TestCustomers()
        {
            Console.WriteLine("\nTesting Customer class methods\n");
            // Create some Customer Classes and test methods
            Customer    c = new Customer("John", "Key", "09-08-1961", 1111, 200.50);
            VIPCustomer v = new VIPCustomer("The", "Pope", "06-06-1950", 333, 12.00);

            // Test displayInfo()
            c.DisplayInfo();
            // check customer deposit and activity counter
            c.Deposit(100);
            Console.WriteLine("Customer deposited $100.00, the balance is now >> " + c.AccessBalance);
            Console.WriteLine("Customer activity count is now >> " + c.AccessActivityCounter);
            // check customer withdraws and activity counter
            c.Withdraw(10);
            Console.WriteLine("Customer withdrew $10.00, the balance is now >> " + c.AccessBalance);
            Console.WriteLine("Customer activity count is now >> " + c.AccessActivityCounter);
            // check customer can go below zero and transactions dont take place
            c.Withdraw(350);
            Console.WriteLine("Customer balance is >> " + c.AccessBalance);
            Console.WriteLine("Customer activity count is >> " + c.AccessActivityCounter);
            // Check VIP transactions
            v.DisplayInfo();
            v.Deposit(10);
            Console.WriteLine("VIP deposited $10.00, balance is now >> " + v.AccessBalance);
            Console.WriteLine("VIP activity count is >> " + v.AccessActivityCounter);
            // check VIP withdraw (and below zero)
            v.Withdraw(100);
            Console.WriteLine("VIP withdrew $100.00, balance is now >> " + v.AccessBalance);
            Console.WriteLine("VIP activity count is >> " + v.AccessActivityCounter);

            //end of tests
            Console.WriteLine("\nEnd of testing customers, press any key to continue ...\n");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        public static Customer[] CustomerList(String fileLocation, int fileLines)
        {
            Customer[] customerArray = new Customer[fileLines]; // makes an array of Customers, length given by fileLines in constructor
            int        counter       = 0;                       //used to assign an array pointer for each line of the file to the customerArray
            String     myLine;                                  // pointer to a line in the file

            String[] words;                                     // an array for splitting each line

            try
            {
                TextReader tr = new StreamReader(fileLocation);

                while ((myLine = tr.ReadLine()) != null)
                {
                    words = myLine.Split(',');
                    String firstName = words[0];
                    String lastName  = words[1];
                    String dob       = words[2];
                    int    id        = int.Parse(words[3]);
                    double balance   = double.Parse(words[4]);
                    if (words.Length > 5)
                    {
                        if ((words[5] != null) && (words[5].Equals("VIP")))                         // handles a line for a VIP customer
                        {
                            // creates a VIPCustomer object if conditionals are true
                            customerArray[counter] = new VIPCustomer(firstName, lastName, dob, id, balance);
                        }
                    }
                    else
                    {
                        // otherwise a Customer object is created and added to the array
                        customerArray[counter] = new Customer(firstName, lastName, dob, id, balance);
                    }

                    counter++;
                }                 // end of reading file
            }
            // If the file is not found an error will be displayed.
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            return(customerArray);
        }