Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace demo
- {
- class Truck
- {
- //име, товароносимост и списък с товари
- //валидации:
- //1. името не трябва да е празно -> Name cannot be empty
- //2. товаримостта не трябава да е < 0 -> Weight cannot be negative
- private string name;
- private int freightness;
- private List<Freight> freights;
- //конструктор
- public Truck(string name, int freightness)
- {
- this.Name = name;
- this.Freightness = freightness;
- this.freights = new List<Freight>();
- }
- //get и set за name
- public string Name
- {
- get { return this.name; }
- set
- {
- //валидация на стойността
- if (string.IsNullOrEmpty(value))
- {
- Console.WriteLine("Name cannot be empty");
- }
- else
- {
- this.name = value;
- }
- }
- }
- //get и set за freightness
- public int Freightness
- {
- get { return this.freightness; }
- set
- {
- if (value < 0)
- {
- Console.WriteLine("Weight cannot be negative");
- }
- else
- {
- this.freightness = value;
- }
- }
- }
- //get за List<Freight>
- public List<Freight> Freights
- {
- get { return this.freights; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment