Tuesday, April 30, 2013

Objects in code

Here is the Scanner Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace scannerExample
{
    class Scanner
    { 
        //fields or attributes
        private string idNumber;
        private DateTime timeStamp;
        private string status;

        //properties
#region "Public Properties"
        public string IDNumber
        {
            get { return idNumber; }
            set { idNumber = value; }
        }

        public DateTime TimeStamp
        {
            get { return timeStamp; }
            set { timeStamp = value; }
        }

        public string Status
        {
            get { return status; }
            set { status = value; }
        }
#endregion

        //methods
        public Scan ReadCard(string cardNumber)
        {
            Scan scan = new Scan();
            scan.CardNumber = cardNumber;
            scan.ScanDate = TimeStamp;
            scan.ScannerID = IDNumber;
            scan.CurrentStatus = Status;

            return scan;
        }
        //constructors
        public Scanner()
        {
            IDNumber = null;
            this.Status = "closed";
            this.TimeStamp = DateTime.Now;
        }

        public Scanner(string ID, string doorState, DateTime scanDate)
        {
            IDNumber = ID;
            Status = doorState;
            TimeStamp = scanDate;
        }
        //--events
        //--deconstructors



    }


}

Here is the Scan class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace scannerExample
{
    class Scan
    {
        public string ScannerID { get; set; }
        public string CardNumber { get; set; }
        public DateTime ScanDate { get; set; }
        public string CurrentStatus { get; set; }

        public override string ToString()
        {
            return "Scanner: " + ScannerID + "\nCardNumber" +
                CardNumber + "\nDate: " + ScanDate.ToString() + "\nStatus: " + CurrentStatus;
        }
    }
}


here is the program Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace scannerExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            p.GetScan();
            Console.ReadKey();

        }

        private void GetScan()
        {
            string idNumber = "12345";
            DateTime curTime = DateTime.Now;
            string status = "closed";
            Scanner scanner = new Scanner(idNumber, status, curTime);
            Scan scan = scanner.ReadCard("6789");

            Console.WriteLine(scan.ToString());
   
        }
    }
}

No comments:

Post a Comment