HowToForums.net Forum Index HowToForums.net
An Open Source of Knowledge
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

3/8/2009 homework

 
Post new topic   Reply to topic    HowToForums.net Forum Index -> OpenU Technical Discussion
View previous topic :: View next topic  
Author Message
sharonshmuelfeldman



Joined: 29 Jul 2009
Posts: 8

PostPosted: Mon Aug 03, 2009 2:47 pm    Post subject: 3/8/2009 homework Reply with quote

here my HW files , if you are interested :

it Contain

Car Class
ParkingLot Class
ParkingLot-Test Main File
My_Func - some function i use.
///////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using My_Functions;

namespace ParkingLot_Cars
{

public class Car
{
private string brandname;
private string year;

public Car(string brandname, string year)
{
this.brandname = brandname;
this.year = year;
}

public Car() { }

public string BRAND
{
set
{
brandname = value;
}
get{
return (brandname);
}
}

public string YEAR
{
set {
year = value;
}
get{
return year;
}
}

public override string ToString()
{
return (string.Format("{0}{1}", my_func.pad(brandname, 20), year));
}

}
}
///////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using My_Functions;

namespace ParkingLot_Cars
{
public class ParkingLot
{
Car[] cars;
int car_num = 0;

public bool Add(Car car)
{
int length = cars.Length;
if (length > car_num)
{
cars[car_num] = car;
car_num ++;
return(true);
}
else{
return(false);
}
}

public ParkingLot(int size)
{
cars = new Car[size];
}

public override string ToString()
{
string st_out="";
for (int i = 0; i < car_num; i++)
{
st_out = string.Format("{0}{1}\n", st_out, cars[i].ToString());
}
return (st_out);
}

public void SortCars()
{
Car temp = new Car();
for (int i = 0; i < car_num; i++)
{
for (int j = 0; j < i; j++)
{
if (int.Parse(cars[j].YEAR) > int.Parse(cars[j + 1].YEAR))
{
temp = (Car)cars[j + 1];
cars[j + 1] = (Car)cars[j];
cars[j] = (Car)temp;
}
}
}
}
}
}
/////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ParkingLot_Cars;

namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
string[] brandname = {"pegougth", "shevrolet", "subaru", "mazda", "toyota" ,"alfa romeo"};
string[] year = { "1995", "1984", "1989", "2003", "2000", "2004"};
int num_of_cars = 6;

int max_parkinglot_size = 10;
ParkingLot My_parkinglot = new ParkingLot(max_parkinglot_size);

for (int i = 0; i < num_of_cars; i++)
{
My_parkinglot.Add(new Car(brandname[i], year[i]));
}
Console.WriteLine("All Parking Lot Content");
Console.WriteLine("----------------------");
Console.WriteLine(My_parkinglot);
Console.WriteLine("Sorting");
Console.WriteLine("----------------------");
My_parkinglot.SortCars();
Console.WriteLine(My_parkinglot);
}

}
}
////////////////////////////////////////

namespace My_Functions
{


public class my_func
{
public static string pad(string s, int size)
{
int num_of_blanks = size - (s.Length);
string temp ="";
for (int i = 0; i < num_of_blanks; i++)
{
temp = temp + " ";
}
return (s + temp);
}
}
}
//////////////////////////////////////////////////
________
Mexico hotels


Last edited by sharonshmuelfeldman on Wed Feb 16, 2011 5:11 am; edited 1 time in total
Back to top
gilad



Joined: 28 Jul 2009
Posts: 3

PostPosted: Mon Aug 03, 2009 10:27 pm    Post subject: nice... thanx Reply with quote

it's all about sharing...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    HowToForums.net Forum Index -> OpenU Technical Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group