I'm starting my project with C#.
This is my first one, so the question problably is something easy.
I have a list of cars, which I can lend out.
I want to use a list here for keeping the info about how many cars and which cars are lent out.
But I think it needs to be multidimensional, for example:
lent car, Owner, when, etc
Porsche, Jack, 2010, ...
Lada, Owen, 2001, ...
Wolkswagen, Mia, 2005, ...
What collection type should I use, can lists be multidimensional?
Or should I use List as the main type and insert arrays as individual positions?
Thanks
Felipe RamosPosted Sep 16, 2010, 12:03 PM
Sam HobbsPosted Sep 18, 2010, 1:23 PM
So the cars would be the inventory. Your orders (whatever you want to call them) will consiste of customers and order items. Your application is more of a services-oriented application and there are many applications that have been developed for that. You might be able to find samples that can help you.
One possibility is to use the DataTable class for the collection. Doing that will be more work for some things but it will be less work over-all. You can use the DataTable class even if you are not storing the data in a database, but I assume you need to store the data somehow. Whatever you use for storing the data, the DataTable class will probably make it easier.
Moose PickardPosted Sep 18, 2010, 12:36 PM
Hi
I've been working on the structure, I figured it would be easier to make statistics and from overall programming perspective if I make only Car objects. I created an UML diagram, I don't know if I got the symbols right (It isn't that important here). http://www.flickr.com/photos/54126948@N08/5001690602/
I figured I could use an interface for both car subclasses. But I don't know if it is possible to do this.
The flow:
User registers and adds their cars to the CarRental Class.
Then they can rent cars out, so the PersonalCar object should connect with the Rental interface. (Is it possible to do this on runtime?)
The user can rent cars in so the car gets added as the RentedCar object.
Thank you for youre previous help. Can you point me out the flaws in this architecture, and maybe help me fix them.
Moose PickardPosted Sep 16, 2010, 7:11 AM
I would like to do it with car objects, but where do save the information about the rented car. I mean who rented it, when it was rented, how long is it rented, cost etc.
I could add it all to the car object, but it would be a messy object, when was it rented doesn't seem to belong to a car. From OOP it wouldn't be good, of course I am new to this field, so I don't know where to make compromises between OOP and efficency. Or maybe I should make a new loan class?
Also what's with Google Chrome not workinging when I try to reply, it displays the loading but it doesn't complete, I can't type in text into the field.
Adavesh ManagaonPosted Sep 15, 2010, 10:27 PM
Class Car
{
public string CarModel {get; set;}
public string CarOwner {get; set;}
}
Class Cars: ICollection
{
List
public Cars()
{
oCarList = new List
public void Add(Car item)
{
oCarList.Add(item);
}
public void Clear()
{
oCarList.Clear();
}
public bool Contains(Car item)
{
//Implement as you need
}
public void CopyTo(string[] array, int arrayIndex)
{
//implement as u need
}
public int Count
{
get { return oCarList.Count; }
}
public bool IsReadOnly
{
get { return false;}
}
public bool Remove(string item)
{
//implement as u need
}
public IEnumerator
{
foreach(Car car in oCarList)
{
yield return car;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
foreach(Car car in oCarList)
{
yield return car;
}
}
}
Now you can create a Car object & add it to cars collection. Simple right?
Majid KamaliPosted Sep 15, 2010, 3:34 PM
You Can use a 2D array of Objects and with new operator change them in specific class object.
For Example:
object[,] MyArray = new object[n, 4]; // n is e.g number of cars
for (int i = 0; i < n; i++)
MyArray[i, 0] = new Owner(); // Your Defined Class
for (int i = 0; i < n; i++)
MyArray[i, 1] = new Car(); // Your Defined Class
And so on.
Felipe RamosPosted Sep 15, 2010, 2:07 PM
Moose PickardPosted Sep 15, 2010, 2:01 PM
How could I make a list with array objects, so I could insert many things into one list position.
List Cars = new List
Well I guess it is a simple library system, I have 4 classes for now: Owner/Client, Car"Library", Car, CarSpec.
I have thought about the structure of this thing.
So, Felipe, you think I should have a availability boolean in Car class ?
Felipe RamosPosted Sep 15, 2010, 11:05 AM
Mahesh ChandPosted Sep 15, 2010, 10:00 AM