Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.WriteLine("Hello World!");
  10.  
  11. // init first object of class User
  12. User first = new User();
  13. first.setData("user1", "123123");
  14. first.getData();
  15. first.age = 27;
  16.  
  17. // init second object of class User
  18. User second = new User();
  19. second.setData("user2", "444444");
  20. second.getData();
  21. second.age = 19;
  22. second.compareWith(first);
  23.  
  24. Console.ReadKey();
  25. }
  26. }
  27.  
  28. class User
  29. {
  30. // properties
  31. string username;
  32. string password;
  33. string email;
  34. public int age;
  35. // constructor
  36. /*
  37. public User(string nUsername, string nPassword)
  38. {
  39. username = nUsername;
  40. password = nPassword;
  41. }
  42. */
  43. // functions
  44. public void setData(string nUsername, string nPassword)
  45. {
  46. username = nUsername;
  47. password = nPassword;
  48. }
  49. public void getData()
  50. {
  51. Console.WriteLine("User details u: " + username + " p: " + password);
  52. }
  53.  
  54. public void tryLogin()
  55. {
  56. Console.WriteLine("enter username:");
  57. string tryUsername = Console.ReadLine();
  58. Console.WriteLine("enter password:");
  59. string tryPassword = Console.ReadLine();
  60.  
  61. if(password == tryPassword && username == tryUsername)
  62. {
  63. Console.WriteLine("Success!");
  64. } else
  65. {
  66. Console.WriteLine("Error!");
  67. }
  68. }
  69.  
  70. public void compareWith(User other)
  71. {
  72. if (this.age > other.age)
  73. {
  74. Console.WriteLine(this.username + " is older than " + other.username);
  75. }
  76. else if (this.age < other.age)
  77. {
  78. Console.WriteLine(other.username + " is older than " + this.username);
  79. }
  80. else
  81. {
  82. Console.WriteLine(this.username + " and " + other.username + " are the same age.");
  83. }
  84. }
  85. }
  86.  
  87. }
  88.  
  89. // https://pastebin.com/3GdLbwJj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement