Beispiel #1
0
        public static double LifetimeMaintenance(VehicleWrapper theVehicle)
        {
            double totalMileage        = theVehicle.TotalMiles;
            double lifetimeMaintenance = totalMileage * maintenancePerMile(theVehicle);

            return(lifetimeMaintenance);
        }
Beispiel #2
0
        public static double TotalCost(User theUser, VehicleWrapper theVehicle)
        {
            double tax = theUser.SalesTaxRate;
            double initialCostNoTax   = theVehicle.InitialCostNoTax;
            double initialCostWithTax = initialCostNoTax * (1 + tax);

            return(initialCostWithTax);
        }
Beispiel #3
0
        private static double maintenancePerMile(VehicleWrapper theVehicle)
        {
            double initialMileage      = theVehicle.InitialMileage;
            double finalMileage        = theVehicle.FinalMileage;
            double lifetimeMaintenance = ((initialMileage + finalMileage) / 4444000);

            return(lifetimeMaintenance);
        }
Beispiel #4
0
        public static double TotalYears(User theUser, VehicleWrapper theVehicle)
        {
            double totalMileage = theVehicle.TotalMiles;
            double milesPerYear = theUser.MilesPerYear;
            double totalYears   = (totalMileage > 0 && milesPerYear > 0) ? (totalMileage / milesPerYear) : (0);

            return(totalYears);
        }
Beispiel #5
0
        private static double totalFinalCost(User theUser, VehicleWrapper theVehicle)
        {
            double interest           = theUser.InterestRate;
            double years              = TotalYears(theUser, theVehicle);
            double initialCostWithTax = TotalCost(theUser, theVehicle);
            double finalCost          = initialCostWithTax * Math.Exp(interest * years);

            return(finalCost);
        }
Beispiel #6
0
        public static double AverageMPG(User theUser, VehicleWrapper theVehicle)
        {
            double percentCityMiles      = theUser.PercentCityMiles;
            double percentHighwayMiles   = theUser.PercentHighwayMiles;
            double cityMilesPerGallon    = theVehicle.CityMPG;
            double highwayMilesPerGallon = theVehicle.HighwayMPG;
            double mpg = ((cityMilesPerGallon * percentCityMiles)
                          + (highwayMilesPerGallon * percentHighwayMiles));

            return(mpg);
        }
Beispiel #7
0
        public static double ResellValue(User theUser, VehicleWrapper theVehicle)
        {
            double finalMileage            = theVehicle.FinalMileage;
            double years                   = TotalYears(theUser, theVehicle);
            double initialCostNoTax        = theVehicle.InitialCostNoTax;
            double depreciatedMileageValue =
                0.25 * ((Math.PI / 2) - Math.Atan(((2.5 * finalMileage) / 100000) - 2.1)) - .36;
            double depreciatedTimeValue = 0.9332 * Math.Exp(-0.177 * years);
            double depreciatedRate      = depreciatedMileageValue + depreciatedTimeValue;

            if (depreciatedRate > 1)
            {
                depreciatedRate = 1;
            }
            if (depreciatedRate < 0)
            {
                depreciatedRate = 0;
            }
            double resellValue = initialCostNoTax * (depreciatedRate);

            return(resellValue);
        }
Beispiel #8
0
        public static double CentsPerMile(User theUser, VehicleWrapper theVehicle)
        {
            double totalMileage = theVehicle.TotalMiles;
            double price        = totalFinalCost(theUser, theVehicle);
            double priceRate    = price / totalMileage;

            double fuelCost = theUser.PriceOfFuel;
            double mpg      = AverageMPG(theUser, theVehicle);
            double fuelRate = fuelCost / mpg;

            double maintenanceRate = maintenancePerMile(theVehicle);

            double resellValueRate = (ResellValue(theUser, theVehicle)) / totalMileage;

            double centsPerMile = (priceRate + fuelRate + maintenanceRate - resellValueRate) * 100;

            if (Double.IsNaN(centsPerMile) || Double.IsInfinity(centsPerMile))
            {
                centsPerMile = 0;
            }

            return(centsPerMile);
        }
 private void clearAllData(object sender, TappedRoutedEventArgs e)
 {
     VehicleWrapper.DeleteAllVehicles();
     theUser.ClearDisplay();
 }
 private void deleteVehicle(object sender, TappedRoutedEventArgs e)
 {
     this.theVehicle.Delete();
     this.theVehicle = null;
 }
        public VehicleDisplay(Windows.UI.Xaml.Controls.StackPanel p, VehicleWrapper theVehicle, int numVehicles)
        {
            this.theVehicle = theVehicle;

            //set colors
            SolidColorBrush color1, color2;

            switch (numVehicles % 4)
            {
            case 0:     //red
                color1 = new SolidColorBrush(Color.FromArgb(179, 212, 107, 61));
                color2 = new SolidColorBrush(Color.FromArgb(255, 118, 42, 9)); break;

            case 1:     //green
                color1 = new SolidColorBrush(Color.FromArgb(179, 31, 166, 71));
                color2 = new SolidColorBrush(Color.FromArgb(255, 21, 83, 39)); break;

            case 2:     //purple
                color1 = new SolidColorBrush(Color.FromArgb(179, 128, 74, 133));
                color2 = new SolidColorBrush(Color.FromArgb(255, 83, 19, 89)); break;

            //color1 = new SolidColorBrush(Color.FromArgb(255, 155, 22, 168)); break;
            default:     //orange
                color1 = new SolidColorBrush(Color.FromArgb(179, 228, 184, 67));
                color2 = new SolidColorBrush(Color.FromArgb(255, 220, 171, 40)); break;
            }



            //parent -> display
            this.display = new StackPanel();
            p.Children.Add(this.display);
            this.display.Background  = color1;
            this.display.Height      = 200;
            this.display.Width       = p.Width; // set width to parent's width
            this.display.Orientation = Orientation.Horizontal;

            //parent -> display -> borderName
            DisplayNameBox borderName = new DisplayNameBox(display, color2);

            updateName("New Vehicle " + (numVehicles + 1).ToString());

            //parent -> display -> scroller
            ScrollViewer scroller = new ScrollViewer();

            this.display.Children.Add(scroller);
            scroller.VerticalScrollMode = ScrollMode.Disabled;
            scroller.ZoomMode           = ZoomMode.Disabled;
            scroller.Width  = this.display.Width - 260;
            scroller.Height = this.display.Height;
            scroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
            scroller.VerticalScrollBarVisibility   = ScrollBarVisibility.Disabled;

            //parent -> display -> scroller -> dataStack
            StackPanel dataStack = new StackPanel();

            scroller.Content              = dataStack;
            dataStack.Height              = 200;
            dataStack.Orientation         = Orientation.Horizontal;
            dataStack.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;

            //parent -> display -> scroller -> dataStack -> descStack1
            DisplayTextBlockStack descStack1 = new DisplayTextBlockStack(dataStack, "Year:", "Make:", "Model:", "Source:");

            //parent -> display -> scroller -> dataStack -> descStack2
            DisplayTextBoxStack descStack2 = new DisplayTextBoxStack(dataStack);
            UIElementCollection textBoxes  = descStack2.stackP.Children;

            ((TextBox)textBoxes[0]).TextChanged += new TextChangedEventHandler(updateYear);
            ((TextBox)textBoxes[1]).TextChanged += new TextChangedEventHandler(updateMake);
            ((TextBox)textBoxes[2]).TextChanged += new TextChangedEventHandler(updateModel);
            ((TextBox)textBoxes[3]).TextChanged += new TextChangedEventHandler(updateSource);

            //parent -> display -> scroller -> dataStack -> priceStack
            DisplaySliderStack priceStack = new DisplaySliderStack(dataStack,
                                                                   "Price", "Cost to Repair", VehicleWrapper.MinPrice, VehicleWrapper.MaxPrice,
                                                                   "$" + VehicleWrapper.MinPrice.ToString(), "$" + VehicleWrapper.MaxPrice.ToString(),
                                                                   VehicleWrapper.MinRepairCost, VehicleWrapper.MaxRepairCost,
                                                                   "$" + VehicleWrapper.MinRepairCost.ToString(), "$" + VehicleWrapper.MaxRepairCost.ToString(),
                                                                   color1, color2);
            UIElementCollection priceStackChildren = ((StackPanel)(priceStack.stackP).Children[1]).Children;

            ((Slider)priceStackChildren[1]).ValueChanged += updatePrice;      // price
            priceStackChildren = ((StackPanel)(priceStack.stackP).Children[3]).Children;
            ((Slider)priceStackChildren[1]).ValueChanged += updateRepairCost; // repair

            //parent -> display -> scroller -> dataStack -> mileageStack
            DisplaySliderStack mileageStack = new DisplaySliderStack(dataStack,
                                                                     "Initial Mileage", "Estimated Final Mileage",
                                                                     VehicleWrapper.MinInitialMileage, VehicleWrapper.MaxInitialMileage,
                                                                     ((int)(VehicleWrapper.MinInitialMileage / 1000)).ToString() + "k",
                                                                     ((int)(VehicleWrapper.MaxInitialMileage / 1000)).ToString() + "k",
                                                                     theVehicle.MinFinalMileage, VehicleWrapper.MaxFinalMileage,
                                                                     ((int)(theVehicle.MinFinalMileage / 1000)).ToString() + "k",
                                                                     ((int)(VehicleWrapper.MaxFinalMileage / 1000)).ToString() + "k",
                                                                     color1, color2);
            UIElementCollection mileageStackChildren = ((StackPanel)(mileageStack.stackP).Children[1]).Children;

            ((Slider)mileageStackChildren[1]).ValueChanged += updateInitialMileage; // initial mileage
            mileageStackChildren = ((StackPanel)(mileageStack.stackP).Children[3]).Children;
            ((Slider)mileageStackChildren[1]).ValueChanged += updateFinalMileage;

            //parent -> display -> scroller -> dataStack -> mpgStack
            DisplaySliderStack mpgStack = new DisplaySliderStack(dataStack,
                                                                 "City MPG", "Highway MPG",
                                                                 VehicleWrapper.MinCityMPG, VehicleWrapper.MaxCityMPG,
                                                                 ((int)(VehicleWrapper.MinCityMPG)).ToString(),
                                                                 ((int)(VehicleWrapper.MaxCityMPG)).ToString(),
                                                                 VehicleWrapper.MinHighwayMPG, VehicleWrapper.MaxHighwayMPG,
                                                                 ((int)(VehicleWrapper.MinHighwayMPG)).ToString(),
                                                                 ((int)(VehicleWrapper.MaxHighwayMPG)).ToString(),
                                                                 color1, color2);
            UIElementCollection mpgStackChildren = ((StackPanel)(mpgStack.stackP).Children[1]).Children;

            ((Slider)mpgStackChildren[1]).ValueChanged += updateCityMPG;
            mpgStackChildren = ((StackPanel)(mpgStack.stackP).Children[3]).Children;
            ((Slider)mpgStackChildren[1]).ValueChanged += updateHighwayMPG;

            //parent -> display -> scroller -> dataStack -> notesStack
            DisplayNotesStack   notesStack         = new DisplayNotesStack(dataStack, "Notes:", "Insert any notes about your vehicle here.");
            UIElementCollection notesStackChildren = notesStack.stackP.Children;

            ((TextBox)notesStackChildren[1]).TextChanged += updateNotes;

            //parent -> display -> scroller -> dataStack -> deleteStack
            DisplayDeleteButton displayDeleteButton = new DisplayDeleteButton(dataStack, "Delete Vehicle", color2);
            Button deleteButton = displayDeleteButton.deleteB;

            deleteButton.Tapped += deleteVehicle;

            //parent -> memoBar
            this.memoBar = new StackPanel();
            p.Children.Add(this.memoBar);
            this.memoBar.Width       = p.Width; // set width to parent's width
            this.memoBar.Height      = 64;
            this.memoBar.Orientation = Orientation.Horizontal;

            //parent -> memoBar -> memoScroll -> memoStack -> elements
            DisplayMemoScroll  memoScroll = new DisplayMemoScroll(this.memoBar);
            StackPanel         memoStack  = (StackPanel)memoScroll.memoScroll.Content;
            DisplayMemoTextBox cpm        = new DisplayMemoTextBox(memoStack, (0.ToString("F") + "¢ per mile"), color1);

            cpm.memoText.FontSize        += 13; // make cents per mile display bigger
            cpm.memoText.FontWeight       = Windows.UI.Text.FontWeights.Thin;
            cpm.memoText.CharacterSpacing = 75;
            cpm.memoText.Margin           = new Windows.UI.Xaml.Thickness(0, 0, 0, 0);
            cpm.memoText.Width            = 225;
            DisplayMemoTextBlock totalCostLabel   = new DisplayMemoTextBlock(memoStack, "Total Cost:");
            DisplayMemoTextBox   totalCost        = new DisplayMemoTextBox(memoStack, "$" + (0.ToString()), color1);
            DisplayMemoTextBlock lifeSpanLabel    = new DisplayMemoTextBlock(memoStack, "Life Span:");
            DisplayMemoTextBox   lifeSpan         = new DisplayMemoTextBox(memoStack, (0.ToString("F") + " years"), color1);
            DisplayMemoTextBlock avgMPGLabel      = new DisplayMemoTextBlock(memoStack, "Average MPG:");
            DisplayMemoTextBox   aveMPG           = new DisplayMemoTextBox(memoStack, (1.ToString("F")), color1);
            DisplayMemoTextBlock maintenanceLabel = new DisplayMemoTextBlock(memoStack, "Maintenance:");
            DisplayMemoTextBox   maintenance      = new DisplayMemoTextBox(memoStack, "$" + (0.ToString()), color1);
            DisplayMemoTextBlock resellLabel      = new DisplayMemoTextBlock(memoStack, "Resell:");
            DisplayMemoTextBox   resell           = new DisplayMemoTextBox(memoStack, "$" + (0.ToString()), color1);
        }