string array function implementation in C# -


this university c# - windows forms exam, im trying resolve old subjects, seem find myself stuck in situation. code:

  abstract class carfile     {         private string marca;         private readonly string serie;          public carfile(string marca, string serie)         {             this.marca = marca;             this.serie = serie;         }          public string getmarca         {             { return this.marca; }             set { this.marca = value; }         }          public string getserie         {             { return this.serie; }         }          public abstract string getdescriere();     } 

then have this: second class called servicefile : carfile, icloneable. in class have array or list of strings called repaircomands contains necessary repairs. - private atribute called "motor" can take following vallues {gas,gpl,hibrid} . - constructor throws generic exception if "serie==null" -overrides abrstract method getdescriere() return complete description of car file

this code:

  public class myexception : system.exception     {         public myexception(string mesaj) : base(mesaj) { }     }     class servicefile : carfile, icloneable, icomparable, ireparabil     {         string[] repaircomands;         private enum motor {   motorina,     benzina,       gpl,     electric,     hibrid     };          public servicefile(string serie, string marca, string[] repaircomands):base(serie,marca){             if (serie == null)             {                 throw new myexception("mesaj");             }             this.repaircomands = repaircomands;        }          //not sure if correct         public override string getdescriere()         {             string msj = string.format("the car {0} serial {1} , necess. repairs {2}", this.getmarca, this.getserie, this.repaircomands);             return msj;         }           public object clone()         {             servicefile clone = new servicefile(this.getserie, this.getmarca, this.repaircomands);             return clone;         }  //implemented icomparable able compare here 2 files number of repairs needed             public int compareto(object obj)             {                 servicefile altafisa = (servicefile)obj;                 if (this.repaircomands != altafisa.repaircomands)                              return 1;                     else return 0;                 } //overloads tostring return complete file description          public override string tostring()         {             return this.getmarca + " "+ this.getserie + " " + this.repaircomands;         }         } } 

so far good. works.

but problem comes now: have define interface irep contains 2 methods : void repaircar() , void addrepair(string repair). servicefile class implements : irep, , function repaircar() used removing last repair collection repaircomands , function addrepair(string repair) used add repair in collection repaircomands. (for allowing access private list of repairs should overload index operator[] )

thank help, i'm beginnes in c# , wanted understand better subject given in class learn

thank you


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -