Ejemplo n.º 1
0
        public static Boat BuildBoat(string strBoatype)
        {
            try
            {
                switch (strBoatype)
                {
                case "MotorBoat":

                    MotorBoat MB = new MotorBoat("MotorBoat");

                    return(MB);

                case "NarrowBoat":

                    NarrowBoat NB = new NarrowBoat("NarrowBoat");
                    return(NB);

                case "Sailing":

                    SailingBoat SB = new SailingBoat("Sailing");
                    return(SB);


                default:
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public static Boat BuildBoat(int type)
        {
            int subType = 0;

            switch (type)
            {
            case 1:

                MotorBoat MB = new MotorBoat("MotorBoat");

                return(MB);

            case 2:

                NarrowBoat NB = new NarrowBoat("NarrowBoat");
                return(NB);

            case 3:

                SailingBoat SB = new SailingBoat("Sailing");
                return(SB);


            default:
                return(null);
            }
        }
Ejemplo n.º 3
0
        public List <string> convertMarinaToList()
        {
            List <string> list = new List <string>();

            BoatNode current = head;

            while (current != null)
            {
                string data = string.Empty;
                //nameof boat
                data += (current.GetItemData().NameOfBoat + ",");
                //owner
                data += (current.GetItemData().NameOfOwner + ",");
                // draft
                data += (current.GetItemData().BoatDraft.ToString() + ",");
                //get boat type
                string boatType = current.GetItemData().TypeofBoat;
                data += (boatType + ",");
                switch (boatType)
                {
                case "MotorBoat":
                    //MotorBoat
                    // sb.Append("MotorBoat" + " ");
                    Factory.MotorBoat TempMB = new Factory.MotorBoat("MotorBoat");
                    TempMB = (Factory.MotorBoat)current.GetItemData();
                    data  += (TempMB.BoatLength.ToString() + ",");
                    data  += (TempMB.DriveType + ",");
                    break;

                case "NarrowBoat":
                    //NarrowBoat
                    //sb.Append("NarrowBoat" + " ");
                    Factory.NarrowBoat TempNB = new Factory.NarrowBoat("NarrowBoat");
                    TempNB = (Factory.NarrowBoat)current.GetItemData();
                    data  += (TempNB.BoatLength + ",");
                    data  += (TempNB.SternType + ",");
                    break;

                case "Sailing":
                    //Sailing
                    // sb.Append("Sailing" + " ");
                    Factory.SailingBoat TempSB = new Factory.SailingBoat("Sailing");
                    TempSB = (Factory.SailingBoat)current.GetItemData();
                    data  += (TempSB.BoatLength + ",");
                    data  += (TempSB.SailingType + ",");
                    break;

                default:
                    break;
                }
                //add to list
                //sb.AppendLine(data);
                list.Add(data);
                //get next
                current = current.GetNext();
            }
            return(list);
        }
Ejemplo n.º 4
0
        internal static int getBoatSubTypes(int type)
        {
            string subMenuType    = "";
            string subTypeMessage = string.Empty;
            int    retVal         = 0;

            switch (type)
            {
            case 1:
                //"MotorBoat"
                subTypeMessage = "\n Please Select an Option \n" +
                                 "1. Inboard Drive \n" +
                                 "2. OutboardMotors \n";
                while (true)
                {
                    //displayMessage(subTypeMessage);
                    drawRectangle(subTypeMessage, ConsoleColor.White, ConsoleColor.DarkBlue);
                    subMenuType = DisplayManager.getUserInputStr();
                    if (!string.IsNullOrEmpty(subMenuType))
                    {
                        try
                        {
                            int.TryParse(subMenuType, out retVal);
                            Factory.MotorBoat MB = new Factory.MotorBoat();
                            int enumLen          = MB.GetEnumLength();
                            if (retVal > enumLen || retVal < 1)
                            {
                                throw new ArgumentOutOfRangeException("Invalid Option for Drive Types; Please Choose an option between 1 and " + enumLen);
                            }
                            else
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            DisplayManager.displayMessage(ex.Message);
                        }
                    }
                }
                break;

            case 2:
                // "NarrowBoat"
                subTypeMessage = "\n Please Select an Option \n" +
                                 "1. Traditional stern\n" +
                                 "2. Cruiser stern    \n" +
                                 "3. Semi-traditional stern \n";
                while (true)
                {
                    drawRectangle(subTypeMessage, ConsoleColor.White, ConsoleColor.DarkBlue);
                    subMenuType = DisplayManager.getUserInputStr();
                    if (!string.IsNullOrEmpty(subMenuType))
                    {
                        try
                        {
                            int.TryParse(subMenuType, out retVal);
                            Factory.NarrowBoat NB = new Factory.NarrowBoat();
                            int enumLen           = NB.GetEnumLength();
                            if (retVal > enumLen || retVal < 1)
                            {
                                throw new ArgumentOutOfRangeException("Invalid Option for Stern Types; Please Choose an option between 1 and " + enumLen);
                            }
                            else
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            DisplayManager.displayMessage(ex.Message);
                        }
                    }
                }
                break;

            case 3:
                //Sailing
                subTypeMessage = "\n Please Select an Option \n" +
                                 "1. Ketch\n" +
                                 "2. Cutter  \n" +
                                 "3. Junk \n";
                while (true)
                {
                    drawRectangle(subTypeMessage, ConsoleColor.White, ConsoleColor.DarkBlue);
                    subMenuType = DisplayManager.getUserInputStr();
                    if (!string.IsNullOrEmpty(subMenuType))
                    {
                        try
                        {
                            int.TryParse(subMenuType, out retVal);
                            Factory.SailingBoat SB = new Factory.SailingBoat();
                            int enumLen            = SB.GetEnumLength();
                            if (retVal > enumLen || retVal < 1)
                            {
                                throw new ArgumentOutOfRangeException("Invalid Option for Stern Types; Please Choose an option between 1 and " + enumLen);
                            }
                            else
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            DisplayManager.displayMessage(ex.Message);
                        }
                    }
                }
                break;

            default:
                break;
            }
            return(retVal);
        }
Ejemplo n.º 5
0
        private void LoadDataFromFile()
        {
            // Marina marina = new Software_Implementation_Project.Marina();

            try
            {
                FileOperations      fileOps     = new Software_Implementation_Project.FileOperations();
                Factory.BoatFactory BoatFactory = new Factory.BoatFactory();
                List <string>       fileList    = new List <string>();
                Factory.Boat        boat        = null;
                fileList = fileOps.readDataFromFile();

                if (fileList.Count < 1)
                {
                    // throw new Exception("No data was returned from file");
                }
                else
                {
                    foreach (string item in fileList)
                    {
                        //split array at commas and put result into an array
                        string[] arrSplitRow = item.Split(",".ToCharArray());
                        //create boat based on type
                        string strBoatType  = arrSplitRow[3];
                        string strBoatLen   = arrSplitRow[4];
                        string strBoatDraft = arrSplitRow[2];
                        switch (strBoatType)
                        {
                        case "NarrowBoat":
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);

                            //Factory.NarrowBoat NB =(Factory.NarrowBoat)BoatFactory.BuildBoat(strBoatType);
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);
                            Factory.NarrowBoat NB = (Factory.NarrowBoat)boat;
                            int boatSubType       = BoatFactory.BuildBoatSubTypes(strBoatType);
                            NB.TypeofBoat = strBoatType;

                            NB.NameOfBoat  = arrSplitRow[0];
                            NB.NameOfOwner = arrSplitRow[1];
                            int boatLen   = 0;
                            int boatDraft = 0;
                            try
                            {
                                int.TryParse(strBoatLen, out boatLen);
                                NB.BoatLength = boatLen;
                            }
                            catch (Exception ex)
                            {
                                NB.BoatLength = -1;
                            }
                            try
                            {
                                int.TryParse(strBoatDraft, out boatDraft);
                                NB.BoatDraft = boatDraft;
                            }
                            catch (Exception ex)
                            {
                                NB.BoatDraft = 1;
                            }
                            NB.SternType = arrSplitRow[5];
                            boat         = NB;
                            break;

                        case "Sailing":
                            //boat = BoatFactory.BuildBoat(3);
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);
                            Factory.SailingBoat SB = (Factory.SailingBoat)boat;
                            //  Factory.SailingBoat SB = (Factory.SailingBoat)(BoatFactory.BuildBoat(strBoatType));
                            SB.TypeofBoat  = strBoatType;
                            SB.TypeofBoat  = strBoatType;
                            SB.NameOfBoat  = arrSplitRow[0];
                            SB.NameOfOwner = arrSplitRow[1];
                            boatLen        = 0;
                            try
                            {
                                int.TryParse(strBoatLen, out boatLen);
                                SB.BoatLength = boatLen;
                            }
                            catch (Exception ex)
                            {
                                SB.BoatLength = -1;
                            }
                            try
                            {
                                int.TryParse(strBoatDraft, out boatDraft);
                                SB.BoatDraft = boatDraft;
                            }
                            catch (Exception ex)
                            {
                                SB.BoatDraft = 1;
                            }
                            SB.SailingType = arrSplitRow[5];
                            boat           = SB;
                            break;

                        case "MotorBoat":
                            //  boat = BoatFactory.BuildBoat(strBoatType);
                            // Factory.MotorBoat MB = (Factory.MotorBoat)(BoatFactory.BuildBoat(strBoatType));
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);
                            Factory.MotorBoat MB = (Factory.MotorBoat)boat;
                            MB.TypeofBoat  = strBoatType;
                            MB.NameOfBoat  = arrSplitRow[0];
                            MB.NameOfOwner = arrSplitRow[1];
                            MB.DriveType   = arrSplitRow[5];
                            try
                            {
                                int.TryParse(strBoatLen, out boatLen);
                                MB.BoatLength = boatLen;
                            }
                            catch (Exception ex)
                            {
                                MB.BoatLength = -1;
                            }
                            try
                            {
                                int.TryParse(strBoatDraft, out boatDraft);
                                MB.BoatDraft = boatDraft;
                            }
                            catch (Exception ex)
                            {
                                MB.BoatDraft = 1;
                            }
                            boat = MB;
                            break;

                        default:
                            break;
                        }
                        //end of switch
                        // marina.addBoatToMarina(boat);
                        if (boat != null)
                        {
                            if (count == 0)
                            {
                                BoatNode boatNode = new Software_Implementation_Project.BoatNode(boat);

                                Add(0, boatNode);
                            }
                            else
                            {
                                AddToEnd(boat);
                            }
                            // count++;
                        }
                    }
                    //end of foreach loop
                }
            }
            catch (Exception ex)
            {
                DisplayManager.displayInvalidInputMessage(ex.ToString());
            }


            //return Marina;
        }
Ejemplo n.º 6
0
        private string PrintElements()
        {
            int           result      = 0;
            BoatNode      currentBoat = head;
            StringBuilder sb          = new StringBuilder();

            if (currentBoat != null)
            {
                //print curent boat
                sb.Append(currentBoat.GetItemData().NameOfBoat).Append(",");
                sb.Append(currentBoat.GetItemData().NameOfOwner).Append(",");
                sb.Append(currentBoat.GetItemData().BoatDraft.ToString()).Append(",");
                sb.Append(currentBoat.GetItemData().BoatLength.ToString()).Append(",");
                string strBoatType = string.Empty;
                strBoatType = currentBoat.GetItemData().TypeofBoat.ToString();
                //sb.Append(current.GetItemData().strBoatType).Append(",");
                switch (strBoatType)
                {
                case "MotorBoat":
                    Factory.MotorBoat MB = (Factory.MotorBoat)currentBoat.GetItemData();
                    sb.Append(MB.TypeofBoat).Append(",");
                    sb.Append(MB.DriveType).Append(",");
                    break;



                case "NarrowBoat":
                    Factory.NarrowBoat NB = (Factory.NarrowBoat)currentBoat.GetItemData();
                    sb.Append(NB.TypeofBoat).Append(",");
                    sb.Append(NB.SternType).Append(",");

                    break;

                case "Sailing":
                    Factory.SailingBoat SB = (Factory.SailingBoat)currentBoat.GetItemData();
                    sb.Append(SB.TypeofBoat).Append(",");
                    sb.Append(SB.SailingType).Append(",");

                    break;


                default:
                    break;
                }
                //remove last index of ,
            }
            sb.AppendLine("");
            if (currentBoat.GetNext() != null)
            {
                for (int i = 1; i < Count; i++)
                {
                    currentBoat = currentBoat.GetNext();
                    sb.Append(currentBoat.GetItemData().NameOfBoat).Append(",");
                    sb.Append(currentBoat.GetItemData().NameOfOwner).Append(",");
                    sb.Append(currentBoat.GetItemData().BoatDraft.ToString()).Append(",");
                    sb.Append(currentBoat.GetItemData().BoatLength.ToString()).Append(",");
                    string strBoatType = string.Empty;
                    strBoatType = currentBoat.GetItemData().TypeofBoat.ToString();
                    //sb.Append(current.GetItemData().strBoatType).Append(",");
                    switch (strBoatType)
                    {
                    case "MotorBoat":
                        Factory.MotorBoat MB = (Factory.MotorBoat)currentBoat.GetItemData();
                        sb.Append(MB.TypeofBoat).Append(",");
                        sb.Append(MB.DriveType).Append(",");
                        break;



                    case "NarrowBoat":
                        Factory.NarrowBoat NB = (Factory.NarrowBoat)currentBoat.GetItemData();
                        sb.Append(NB.TypeofBoat).Append(",");
                        sb.Append(NB.SternType).Append(",");

                        break;

                    case "Sailing":
                        Factory.SailingBoat SB = (Factory.SailingBoat)currentBoat.GetItemData();
                        sb.Append(SB.TypeofBoat).Append(",");
                        sb.Append(SB.SailingType).Append(",");

                        break;


                    default:
                        break;
                    }
                    sb.AppendLine("");
                }
            }

            return(sb.ToString());;
        }