63 227
Assignments Done
99,3%
Successfully Done
In July 2018

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.
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions