Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ArrayList_Siomple_Sorted_10
- {
- class Person
- {
- private string personName;
- private DateTime birthDate;
- private string studiedCourse;
- private double receivedGrade;
- public Person(string name, DateTime bDate, string course, double grade)
- {
- personName = name;
- birthDate = bDate;
- studiedCourse = course;
- receivedGrade = grade;
- }
- public string Name
- {
- get { return personName; }
- set { personName = value; }
- }
- public DateTime Birthdate
- {
- get { return birthDate; }
- set { birthDate = value; }
- }
- public string Course
- {
- get { return studiedCourse; }
- set { studiedCourse = value; }
- }
- public double Grade
- {
- get { return receivedGrade; }
- set { receivedGrade = value; }
- }
- public string Show()
- {
- return "Student Name: " + personName + "\nDate of birth: " + birthDate.ToString("dd.MM.yyyy") + "\nCourse: " + studiedCourse + "\nGrade " + receivedGrade + "\n";
- }
- public string ShowGrade()
- {
- return "Student Name: " + personName + "\nGrade: " + receivedGrade + "\n";
- }
- }
- }
- using System;
- using System.Collections;
- using System.Text;
- using System.Collections.Generic;
- namespace ArrayList_Siomple_Sorted_10
- {
- class Program
- {
- static void Main(string[] args)
- {
- ArrayList ar = new ArrayList();
- string choice;
- begin:
- Console.WriteLine("Choices: 1 to add a user, 2 to see all students on the list, 3 to search if a student is on the list");
- Console.Write("Your choice: ");
- choice = Console.ReadLine();
- switch (choice)
- {
- case "1":
- Console.Write("Input Person Name: ");
- var name = Console.ReadLine();
- Console.Write("Input Person date of birth: ");
- var dob = Console.ReadLine();
- DateTime dateOfBirth = DateTime.Parse(dob);
- Console.Write("Input the course: ");
- var course = Console.ReadLine();
- Console.Write("Input Person grade: ");
- var grade = Convert.ToDouble(Console.ReadLine());
- var p = new Person(name, dateOfBirth, course, grade);
- ar.Add(p);
- Console.WriteLine("Student added succesfully.");
- goto begin;
- case "2":
- foreach (Person obj in ar)
- Console.WriteLine(obj.Show());
- goto begin;
- case "3":
- Console.WriteLine("Student's name search: ");
- string searchedString = Console.ReadLine();
- if (ar.Contains(searchedString) == false)
- {
- Console.WriteLine("Student {0} is on the list.", searchedString);
- }
- else
- {
- Console.WriteLine("Student {0} is not on the list.", searchedString);
- }
- goto begin;
- case "4":
- foreach (Person obj in ar)
- Console.WriteLine(obj.ShowGrade());
- goto begin;
- case "5":
- ar.Sort();
- foreach (Person obj in ar)
- Console.WriteLine(obj.Show());
- goto begin;
- case "6":
- Console.WriteLine("Remove student: ");
- string removeStudent = Console.ReadLine();
- Console.WriteLine("Are you sure you want to remove {0} from the list?", removeStudent);
- Console.WriteLine("Press any key to continue ...");
- Console.ReadKey();
- ar.Remove(removeStudent);
- Console.WriteLine("Student {0} was removed from the list.", removeStudent);
- foreach (Person obj in ar)
- Console.WriteLine(obj.Show());
- goto begin;
- default :
- Console.WriteLine("Bye.");
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment