Example #1
0
        /// <summary>
        /// checks if the pump number is in use and shows the
        /// percentage and vehicle type of it is.
        /// </summary>
        /// <param name="i">the pump number.</param>
        /// <returns>the console output for the pump.</returns>
        private string pumpUse(char i)
        {
            string container;                                                               //the console output.
            Pump   p = findPump(i);                                                         //finds the pyump based on the name (from the input).

            if (p.status())                                                                 //checks if the pump is occupied.
            {
                FuelInstance fi  = p.fuelinstance();                                        //gets the fuelinstance.
                Vehicle      v   = fi.vehicleOnPump();                                      //gets the vehicle from the fuel instance.
                Fuel         fv  = v.fuelTank();                                            //gets the vehicles fuel.
                double       per = fv.fuelPercent();                                        //gets the percentage of fuel within the vehicle.
                if (per > 9)
                {
                    container = v.vehicleType() + "-" + per + "%";                          //sets the container to the vehicle type and the percentace of fuel it contains.
                }
                else
                {
                    container = v.vehicleType() + "--" + per + "%";
                }
            }
            else                                                                            //if the pump isn't in use it returns dashes.
            {
                container = "-------";
            }
            return(container);
        }
        /// <summary>
        /// finds all the relevent details to do with the car and pump to add
        /// to the transactionlist. but will only update the fuel and add a
        /// transaction if the pump isn't occupied and the pump contains
        /// ennough fuel to fully fuel the vehicle.
        /// </summary>
        public void fuelVehicle(double i)
        {
            Fuel   vehicleTank = m_vehicle.fuelTank();                                                          //the fuel for the vehicle.
            String fuelType    = vehicleTank.fuelType();                                                        // the type of fuel being sold.
            Fuel   pumpTank;                                                                                    //the fuel from the pump in use.
            double cost;                                                                                        //the cost per litre for the fuel.

            if (fuelType == "LGP")                                                                              //checking which fuel type is being sold and setting the price.
            {
                cost     = 1.05;
                pumpTank = m_pump.lgp();
            }
            else if (fuelType == "Diesel")
            {
                cost     = .95;
                pumpTank = m_pump.diesel();
            }
            else
            {
                cost     = .85;
                pumpTank = m_pump.unleaded();
            }

            double pumpAmount = pumpTank.fuelAmount();                                                          //total fuel in the pump of the correct type.
            double fuelneeded = vehicleTank.fuelNeeded();                                                       //the amount of fuel the car needs to be fully fueled.
            bool   occupied   = m_pump.status();                                                                //bool showing whether the pump is occupied.

            if ((pumpAmount > 0))                                                                               //a check to see if theres enough fuel to fully fuel the vehicle, to prevent vehicles from fueling when there is a lack of fuel.
            {
                double fuelAmount = vehicleTank.addFuel(i);                                                     //the amount of fuel added.
                m_litresDispensed += i;
                pumpTank.removeFuel(i);
                m_price += cost * fuelAmount;                                                                   //the price of the fueling.
                String vehicleType = m_vehicle.vehicleType();                                                   //the type of the vehicle fueled.

                if ((vehicleTank.fuelNeeded() <= 0f) || (pumpAmount <= 0))                                      //a check to find out if the vehicle is fully fueled or the pump is out of fuel
                {
                    m_pump.statusUpdate(false);                                                                 //setting the pump to no longer be occupied.
                    Transaction t = new Transaction(m_vehicle, m_pump, m_litresDispensed, fuelType, m_price);   //creating a transaction.
                    TransactionList.addTransaction(t);                                                          //adding the transaction the the list of transactions.
                }
            }
            else if (m_litresDispensed > 0)                                                                     //vehicles leave if there isn't enought fuel to fill their tank.
            {
                m_pump.statusUpdate(false);                                                                     //setting the pump to no longer be occupied.
                Transaction t = new Transaction(m_vehicle, m_pump, m_litresDispensed, fuelType, m_price);       //creating a transaction.
                TransactionList.addTransaction(t);                                                              //adding the transaction the the list of transactions.
            }
            else
            {
                m_pump.statusUpdate(false);
                VehiclesLeft.vehicleLeft();
            }
        }
Example #3
0
        /// <summary>
        /// the back bone of the program
        /// creates two timers, one for the cars to arrive, the other updates everything.
        /// </summary>
        public void timings()
        {
            Random r = new Random();                                                        //gets the random object.
            Timer  t = new Timer()                                                          //creates the timer for the cars to appear.
            {
                Interval  = r.Next(1500, 2200),                                             //the interval of the timer is between 1500ms and 2200ms.
                AutoReset = true,
            };

            t.Elapsed += addVehicle;                                                        //once the time elapses it'll add a new vehicle to the list.
            GC.KeepAlive(t);

            t.Start();                                                                      //starts the timer to updat the vehicle list.

            Timer waitingT = new Timer(100);

            waitingT.Elapsed += update;                                                     //updates the program every 100ms.

            waitingT.Start();                                                               //starts the waitingT timer.

            while (c != 'q')                                                                //checks the user input.
            {
                ConsoleKeyInfo keypress = Console.ReadKey();
                c = keypress.KeyChar;                                                       //reads the keypress of the user.

                if ((c == '1') || (c == '2') || (c == '3') ||                               //checks if the user wants to add a vehicle to a pump.
                    (c == '4') || (c == '5') || (c == '6') ||
                    (c == '7') || (c == '8') || (c == '9'))
                {
                    Pump p = findPump(c);                                                   //finds the pump based on the user input.
                    if (wl.listCout() > 0)                                                  //checks if there are vehicles waiting to be fueled.
                    {
                        if ((!p.status()) && (!pumpBlocker(int.Parse(c + ""))))             //checks if the pump is free and accessible.
                        {
                            Vehicle      v  = wl.vehicleServiced();                         //tells the waiting list the vehicle is to be seviced.
                            FuelInstance fi = new FuelInstance(v, p);                       //creates a a fuel instance with the pump and the vehicle.
                            p.setFuelInstance(fi);                                          //sets the pumps fuel instance.
                        }
                    }
                }
            }

            if (TransactionList.totalSales() > 0)                                           //checks if any transactions have been made.
            {
                waitingT.Stop();                                                            //stops the timers.
                t.Stop();


                overview();                                                                 //prints the overview for all the counters.
            }
        }