Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5.  
  6. namespace PointExercise
  7. {
  8.     public class Route
  9.     {
  10.        
  11.         List<Point> routeList= new List<Point>();
  12.        
  13.         /*public void Create_Route()
  14.         {
  15.             routeList = new List<Point>();
  16.         }*/
  17.  
  18.         public void Add_Point(double x, double y,int index)
  19.         {
  20.            
  21.             try
  22.             {
  23.                 if (index >= 0 && index <= routeList.Count)
  24.                 {
  25.                     routeList.Insert(index, new Point(x, y));
  26.                 }
  27.             }
  28.             catch (ArgumentException)
  29.             {
  30.                 Console.WriteLine("Add point failed");
  31.             }
  32.            
  33.         }
  34.  
  35.         public void Remove_Point(int indeks)
  36.         {
  37.             try
  38.             {
  39.                 routeList.RemoveAt(indeks);
  40.             }
  41.             catch (ArgumentException)
  42.             {
  43.  
  44.                 Console.WriteLine("Remove point failed");
  45.             }
  46.            
  47.         }
  48.  
  49.         public double Get_Length()
  50.         {
  51.             double tulem =0;
  52.             int i = 1;
  53.  
  54.             if (routeList.Count > 1)
  55.             {
  56.                 foreach (var point in routeList)
  57.                 {
  58.                     if (routeList.Count > i)
  59.                     {
  60.                         tulem = point.distance(routeList[i]);
  61.                         i++;
  62.                     }
  63.                 }
  64.             }
  65.             return tulem ;
  66.         }
  67.  
  68.         //For testing
  69.         public int Get_ListCount()
  70.         {
  71.             return routeList.Count;
  72.         }
  73.  
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement