Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program.cs
- using System;
- using System.IO;
- using System.Text;
- using System.Collections.Generic;
- namespace test
- {
- class Program
- {
- static void Main (string[] args)
- {
- using (StreamReader fileIn = new StreamReader ("/Users/masha/Projects/test/test/test.txt"))
- {
- int n = int.Parse (fileIn.ReadLine ());
- Transport[] list = new Transport[n];
- for (int i = 0; i < n; i++)
- {
- string[] s = fileIn.ReadLine ().Split (' ');
- if (Convert.ToChar (s [0]) == 'c') {
- list [i] = new Car (s [1], int.Parse (s [2]), int.Parse (s [3]), int.Parse (s [4]));
- } else if (Convert.ToChar (s [0]) == 'm') {
- list [i] = new Motorcycle (s [1], int.Parse (s [2]), int.Parse (s [3]), int.Parse (s [4]), s[5]);
- } else {
- list [i] = new Truck (s [1], int.Parse (s [2]), int.Parse (s [3]), int.Parse (s [4]), s[5]);
- }
- }
- for (int i = 0; i < list.Length; i++)
- list [i].Show ();
- Console.WriteLine ();
- Array.Sort (list);
- for (int i = 0; i < list.Length; i++)
- list [i].Show ();
- Console.WriteLine();
- for (int i = 0; i < list.Length; i++)
- {
- if (list [i].Capacity() == 20)
- list [i].Show();
- }
- }
- }
- }
- }
- __________________________________________________________
- Transport.cs
- using System;
- namespace test
- {
- abstract public class Transport: IComparable
- {
- abstract public void Show();
- abstract public int Capacity();
- abstract public bool Find(int a);
- abstract public int CompareTo(object obj);
- protected string model;
- protected int number;
- protected int speed;
- protected int capacity;
- public string Model
- {
- get
- {
- return model;
- }
- set
- {
- model = value;
- }
- }
- public int Number
- {
- get
- {
- return number;
- }
- set
- {
- if (value > 0)
- number = value;
- else
- {
- number = 0;
- Console.WriteLine ("Incorrect number");
- }
- }
- }
- public int Speed
- {
- get
- {
- return speed;
- }
- set
- {
- if (value > 0)
- speed = value;
- else
- {
- speed = 0;
- Console.WriteLine ("Incorrect speed");
- }
- }
- }
- public int Cap
- {
- get
- {
- return capacity;
- }
- set
- {
- if (value >= 0)
- capacity = value;
- else
- {
- capacity = 0;
- Console.WriteLine ("Incorrect capacity");
- }
- }
- }
- }
- }
- ____________________________________________________________________________
- Car.cs
- using System;
- namespace test
- {
- public class Car: Transport
- {
- //конструкторы
- public Car ()
- {
- }
- public Car(string model, int number, int speed, int capacity)
- {
- this.model = model;
- this.number = number;
- this.speed = speed;
- this.capacity = capacity;
- }
- //методы
- public override void Show()
- {
- Console.WriteLine ("Car: Model - {0}, Num {1}, with speed = {2}km/h and capacity = {3} ",
- model, number, speed, capacity);
- }
- public override int Capacity()
- {
- return capacity;
- }
- public override bool Find (int a)
- {
- if (a == this.capacity)
- return true;
- else
- return false;
- }
- public override int CompareTo (object obj)
- {
- Transport item = (Transport) obj;
- if (this.Capacity () == item.Capacity ())
- {
- return 0;
- }
- else
- {
- if (this.Capacity () > item.Capacity ())
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
- }
- }
- }
- _________________________________________________________________________________
- Motorcycle.cs
- using System;
- namespace test
- {
- public class Motorcycle: Car
- {
- protected string sidecar;
- public Motorcycle ()
- {
- }
- public Motorcycle (string model, int number, int speed, int capacity, string sidecar)
- {
- this.model = model;
- this.number = number;
- this.speed = speed;
- this.capacity = capacity;
- this.sidecar = sidecar;
- }
- public override void Show()
- {
- Console.WriteLine ("Moto: Model - {0}, Sidecar - {4}, Num {1}, with speed = {2}km/h and capacity = {3} ",
- model, number, speed, Capacity(), sidecar);
- }
- public override int Capacity()
- {
- if (sidecar != "sidecar")
- return 0;
- else
- return capacity;
- }
- public string Sidecar
- {
- get
- {
- return sidecar;
- }
- set
- {
- sidecar = value;
- }
- }
- public override bool Find (int a)
- {
- if (a == this.capacity)
- return true;
- else
- return false;
- }
- public override int CompareTo (object obj)
- {
- Car item = (Car) obj;
- if (this.Capacity () == item.Capacity ())
- {
- return 0;
- }
- else
- {
- if (this.Capacity () > item.Capacity ())
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
- }
- }
- }
- _______________________________________________________________________
- Truck.cs
- using System;
- namespace test
- {
- public class Truck: Car
- {
- protected string trailer;
- public Truck ()
- {
- }
- public Truck (string model, int number, int speed, int capacity, string trailer)
- {
- this.model = model;
- this.number = number;
- this.speed = speed;
- this.capacity = capacity;
- this.trailer = trailer;
- }
- public override void Show()
- {
- Console.WriteLine ("Truck: Model - {0}, Trailer - {4}, Num {1}, with speed = {2}km/h and capacity = {3} ",
- model, number, speed, Capacity(), trailer);
- }
- public override int Capacity()
- {
- if (trailer == "trailer")
- return 2*capacity;
- else
- return capacity;
- }
- public string Trailer
- {
- get
- {
- return trailer;
- }
- set
- {
- trailer = value;
- }
- }
- public override bool Find (int a)
- {
- if (a == this.capacity)
- return true;
- else
- return false;
- }
- public override int CompareTo (object obj)
- {
- Car item = (Car) obj;
- if (this.Capacity () == item.Capacity ())
- {
- return 0;
- }
- else
- {
- if (this.Capacity () > item.Capacity ())
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
- }
- }
- }
- ________________________________________________________________________
- test.txt
- 6
- c model1 123 200 10
- c model2 234 200 10
- t model3 345 150 10 trailer
- m model4 456 300 10 sidecar
- t model5 567 150 10 no_trailer
- m model6 678 300 10 no_sidecar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement