HELLO, i tried to understand the context, but as an international student i want to make sure that i did it correctly , if someone can verify it with me i will appreciate it, the question is attached below.

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

namespace CarsDemo
{
    class Program
    {
        public class Car 
        {
        public string VehicleIDNumber{get; set;}
        public string VehicleMake{get; set;}
        public string VehicleModel{get; set;}
        public string VehicleColor{get; set;}
        public double VehicleValue{get; set;}
 
        public static void DisplayFleet(params Car[] cars)
        {
                foreach (Car car in cars)
                {
                    Console.WriteLine(car.VehicleIDNumber+"  "+car.VehicleMake + "  " + car.VehicleModel + "  "     + car.VehicleColor + "  " + car.VehicleValue.ToString("C"));
                }
                Console.WriteLine();
        }
        public Car (string vin, string make, string model, string color, double value)
        {
            VehicleIDNumber = vin;
            VehicleMake = make;
            VehicleModel = model;
            VehicleColor = color;
            VehicleValue = value;
        }
    }
  
        static void Main()
        {
            Car car1 = new Car("1010V101", "Ford", "Taurus", "Red", 5000.00);
            Car car2 = new Car("2020V202", "Geo", "Metro", "Yellow", 338291.99);
            Car car3 = new Car("3030V303", "Chevy", "Bolt", "White", 928422.90);
            Car car4 = new Car("4040V404", "Hyundai", "Elantra", "Blue", 4551.17);
            Car car5 = new Car("5050V505", "Kia", "Rio", "Orange", 24050.00);
            Car.DisplayFleet(car1, car2, car3, car4, car5);
        }
    }
}
Attachments Screen_shot_2011-04-02_at_8.02_.11_PM_.png 44.72 KB

Your code looks good except you are missing part of your DisplayFleet() method: "... and displays the total value of all Car objects".

In your main method you are missing some calls to DisplayFleet() "... then calls DisplayFleet() three times - passing three, four, and five Car objects ..."

i had some truble with understanding these instructions it means that i need to use the total method to calculate all the values?

and i need to erase some code from the displayfleet method? to display only three object?

1) You need to total up the value of the cars. Initialize the total to zero and each time you display a car add the value of that car to the total. Once you have displayed all the cars display the value of total.

2) Make 3 calls to DisplayFleet:

DisplayFleet(car1, car2, car3);
DisplayFleet(car1, car2, car3, car4);
DisplayFleet(car1, car2, car3, car4, car5);

something like that will do the job of total?, btw tanks for the display solution i appreciate it

static void Main()
        {
            double total = 0;
            Car car1 = new Car("1010V101",   "Ford", "Taurus",     "Red", 5000.00);
            Car car2 = new Car("2020V202",   "Geo", "Metro",       "Yellow", 338291.99);
            Car car3 = new Car("3030V303",   "Chevy"," Bolt",      "White", 928422.90);
            Car car4 = new Car("4040V404",   "Hyundai"," Elantra", "Blue", 4551.17);
            Car car5 = new Car("5050V505",   "Kia"," Rio",         "Orange", 24050.00);
            total =+ car1.VehicleValue+ car2.VehicleValue+ car3.VehicleValue+car4.VehicleValue+ car5.VehicleValue   ;
          //  Car.DisplayFleet(car1, car2,car3, car4, car5);
            Car.DisplayFleet(car1, car2, car3);
            Car.DisplayFleet(car1, car2, car3, car4);
            Car.DisplayFleet(car1, car2, car3, car4, car5);
            Console.WriteLine("Total is: "+ total.ToString("C"));

Nope, the total goes in the DisplayFleet method. You want the total of the cars you are displaying.

Edited 5 Years Ago by Momerath: n/a

i am struggling with this small problem i did

total =+ car.VehicleValue;

inside the foreach

am i missing something ?

Did you set the total to zero before the foreach and display the results after the foreach? If so, you are done.

thanks Momerath, i guess the key code was the one in the bold
can you tell me how can i align everything to make it user friendly ?

public static void DisplayFleet(params Car[] cars)
        { 
           double total = 0;
           foreach (Car car in cars)
           {
               Console.WriteLine(car.VehicleIDNumber + "  " + car.VehicleMake + "  " + car.VehicleModel + "  " + car.VehicleColor + "  " + car.VehicleValue.ToString("C"));
              [B] total +=car.VehicleValue;[/B]
           }

           Console.WriteLine();
            Console.WriteLine("Total is:"+ total.ToString("C"));
            Console.WriteLine();
This article has been dead for over six months. Start a new discussion instead.