Answer to Question #4766 in C# for sonu

Question #4766
please can you solve this program for me please!!!!!!!!!!!!!!
Design a class called car with data members: model,company and price.include relevant constructors and methods to initialize and print the above data members.create another class called car collection to maintain a list of car objects using an array list.include an indexer to get array like access to car collection object.
1
Expert's answer
2011-10-20T11:39:43-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CarCollection
{
public class Car
{
& private string model;
& private string company;
& private double price;

& public Car() {
&
& }
& //Constructor
& public Car(string model, string company, double price)
& {
this.model = model;
this.company = company;
this.price = price;
& }

& public string GetModel()
& {
return model;
& }
& public string GetCompany()
& {
return company;
& }
& public double GetPrice()
& {
return price;
& }

}
}

//Programm

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

namespace CarCollection
{
class Program
{
& static void Main(string[] args)
& {
List<Car> carcollection = new List<Car>();
Car c1, c2, c3, c4, c5;
c1 = new Car("Ferary", "Ferary", 100);
c2 = new Car("Honda", "Honda", 500);
c3 = new Car("Mersedes", "Mersedes", 600);
c4 = new Car("Ford", "Ford", 700);
c5 = new Car("Mitsubishi", "Mitsubishi", 900);
carcollection.Add(c1);
carcollection.Add(c2);
carcollection.Add(c3);
carcollection.Add(c4);
carcollection.Add(c5);
Console.WriteLine("Model Company Price");
for (int i = 0; i < 5; i++)
{
Console.WriteLine(carcollection[i].GetModel() + "& quot; + carcollection[i].GetCompany() + "& quot; + carcollection[i].GetPrice().ToString());
}
Console.ReadLine();
& }
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS