Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Need to refractor this piece of shit

Name: OP hates his boss 2012-04-26 3:21

Been given this absolute piece of shit to attempt to refractor
-have i missed anything?

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Assignment1
{
    class Program
    {
        static void recieptHeader()
        {
            Console.WriteLine("\nAUTOMATED FUEL DELIVERY SYSTEM");
            Console.WriteLine("\nRECEIPT");
        }

        private static void RegisteredUsers(ArrayList registeredUsers)
        {
            registeredUsers.Add(new CommunicationSystem("476541", "Visa", 50));
            registeredUsers.Add(new CommunicationSystem("302354", "MasterCard", 400));
            registeredUsers.Add(new CommunicationSystem("470614", "Amex", 200));
            registeredUsers.Add(new CommunicationSystem("711251", "Diners", 90));
        }

        static void Main(string[] args)
        {
            SystemController aSystem = new SystemController();

            ArrayList registeredUsers = new ArrayList();

            // populate registered users
            RegisteredUsers(registeredUsers);

            aSystem.setRegisteredUsers(registeredUsers);


            // Add fuel to tank
            FuelTank aTank = aSystem.getFuelTank();
            aTank.addFuel(1000); // litres

            //validate transaction

            CardReader customer1 = aSystem.getCardReader();
            customer1.readCard("476541", "Visa");

            aSystem.getCardStatus(customer1);


            // Scenario 1 - Enter cash limit
            if (aSystem.getCardReader().getCardSatus() == SystemController.CardStatus_Valid)
            {
                Pump aPump = customer1.getPump();
                // Fuel selection
                aPump.setFuelType(SystemController.Unleaded);
                // set cash
                aPump.setPrice(40);      
                // check credit limit
                // check fuel price with customers selection
                if (customer1.getCreditLimit() > aPump.getPrice())
                {
                    double fuelDelivery = aPump.getPrice() / SystemController.UnleadedPrice;
                  
                    aPump.activate();
                    if (aTank.getTotalLevel() > fuelDelivery)
                    {
                        aPump.setFuelDispensed(fuelDelivery);
                    }
                    aPump.deactivate();
                    aTank.removeFuel(fuelDelivery);
                    customer1.setCreditLimit(customer1.getCreditLimit() - aPump.getPrice());
                    DateTime currTime = DateTime.Now;

                    // Print receipt
                    recieptHeader();
                    Console.WriteLine("\nDate : {0:d}", currTime);
                    Console.Write("\nPaid ${0} for {1:#.##} litres of ", aPump.getPrice(), fuelDelivery);
                    if (aPump.getFuelType() == SystemController.Unleaded)
                        Console.Write("Unleaded");
                    else if (aPump.getFuelType() == SystemController.PremiumUnleaded)
                        Console.Write("Premium Unleaded");
                    else if (aPump.getFuelType() == SystemController.LPG)
                        Console.Write("LPG");
                    else if (aPump.getFuelType() == SystemController.Diesel)
                        Console.Write("Diesel");
                    Console.WriteLine("\n\nPress any key to continue...");
                    string garbage = Console.ReadLine();
                    Console.Clear();
                  
                   
                }
         

                // max amount of fuel
                CardReader customer2 = new CardReader();
                customer2.readCard("302354", "MasterCard");
                aSystem.getCardStatus(customer2);

                // Scenario 2 - Customer enters max fuel
                if (aSystem.getCardReader().getCardSatus() == SystemController.CardStatus_Valid)
                {
                    // check fuel price with customers selection
                   
                    double maxDelivery = customer2.getCreditLimit() / SystemController.PremiumUnleadedPrice;
                    aSystem.setMaxDelivery(maxDelivery);
                    Pump bPump = customer2.getPump();
                    bPump.setFuelType(SystemController.PremiumUnleaded);
                    bPump.activate();
                    double fuelDispensed = 0;
                    double charge = 0;
                    bool filled = false;
                    Console.WriteLine("\n\nDISPENSING FUEL");
                    Console.WriteLine("\nPress y to start dispensing or ..\n\npress any other key to quit");
                    string a = Console.ReadLine().ToLower();
                    if (a.Equals("y"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\nDispensing fuel");
                        Console.WriteLine("\nPress <CR> to dispence in 0.1 litre increment\n\nPress q to terminate dispensing");
                        string req = Console.ReadLine().ToLower();
                        while ((aTank.getTotalLevel() >= maxDelivery) & (!req.Equals("q")) & fuelDispensed <= maxDelivery & customer2.getCreditLimit() >= charge)
                        {
                            filled = true;
                            charge += 0.1 * SystemController.PremiumUnleadedPrice;
                            fuelDispensed += 0.1;
                            aTank.removeFuel(0.1);
                                                      
                            Console.Clear();
                            Console.WriteLine("\n\nDispensing fuel");
                            Console.WriteLine("\nFuel dispensed {0:F2} litre(s) and Cost {1:C}", fuelDispensed, charge);
                            Console.WriteLine("\nPress <CR> to despence in 0.1 litre increment\n\nPress q to terminate dispensing");
                            string ch = Console.ReadLine().ToLower();
                            if (ch.Equals("q"))
                            {
                                bPump.setFuelDispensed(fuelDispensed);
                                bPump.setPrice(charge);
                                break;
                            }
                        }
                        if (filled)
                        {
                            customer2.setCreditLimit(customer2.getCreditLimit() - charge);
                            DateTime currTime = DateTime.Now;
                            // Print receipt
                            recieptHeader();
                            Console.WriteLine("\nDate : {0:d}", currTime);
                            Console.Write("\nPaid ${0} for {1:#.##} litres of ", bPump.getPrice(), bPump.getFuelDispensed());
                            if (bPump.getFuelType() == SystemController.Unleaded)
                                Console.Write("Unleaded");
                            else if (bPump.getFuelType() == SystemController.PremiumUnleaded)
                                Console.Write("Premium Unleaded");
                            else if (bPump.getFuelType() == SystemController.LPG)
                                Console.Write("LPG");
                            else if (bPump.getFuelType() == SystemController.Diesel)
                                Console.Write("Diesel");
                            Console.WriteLine("\n\nPress any key to continue...");
                            string garbage = Console.ReadLine().ToLower();
                            Console.Clear();

                        }
                    }                                       
                }
            }
        }
    }
}

Name: Anonymous 2012-04-26 5:40

>>4
The idea of refactoring is actually to make reusable code.

Why would you want to make reusable methods in a program that doesn't reuse them??  Because of System Extendability.

So, you don't reuse method "A"?  So you get rid of it right?
Well, what happens if you decide you need to extend your system and you realise that you NOW do have to reuse method "A".  Now you have a shit load of recoding to do, and possibly a harder job because you've now built a system around this code, when if you had made it reusable as part of your initial design, you'd have a lot less hastle on your hands.

Systems rarely stay the same size forever.  They change, they get bigger, they do more complex stuff.

It pays to have a system that you can extend easily, as opposed to a system that is effectively set in stone and you find yourself "hacking" into already defined methods.

"A hallmark - if not the hallmark - of good object oriented design is that you can modify and
extend a system by adding code rather than hacking it.... In short, change is additive, not
invasive. Additive change is potentially easier, more localized, less error-prone, and ultimately
more maintainable than invasive change."
John Vlissides, The C++ Report, February 1998

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List