fork download
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package os_a4;
  7.  
  8. import java.util.Vector;
  9.  
  10. /**
  11.  *
  12.  * @author amr
  13.  */
  14. public class OS_A4 {
  15. String curUserName="admain";
  16. Vector<String>userNames=new Vector<String>();
  17. Vector<String>passwords=new Vector<String>();
  18. public void addNewUser(String userName,String password)
  19. {
  20. // add userName & password that send at parameter
  21. // to vector<string> userNames and vector<string> passwords
  22. // but should (global variable)curUserName is admin
  23. // and userName shouldn't be at vector<string> userNames
  24. // you can use function findAtuserNames that you implement that
  25. if(curUserName.equals("admain"))
  26. {
  27. if(findAtuserNames(userName))
  28. {
  29. userNames.add(userName);
  30. passwords.add(password);
  31. }
  32. else
  33. {
  34. System.err.println("This User Name is Exsist int the System choose another one");
  35. }
  36. }
  37. else
  38. {
  39. System.err.println("YOu Don't have the Rights to Add New User ");
  40. }
  41. }
  42.  
  43. public boolean findAtuserNames(String userName)
  44. {
  45. for(int i=0;i<userNames.size();i++)
  46. if(userNames.get(i).equals(userName))
  47. return false;
  48. return true;
  49. }
  50.  
  51. public boolean correctPassword(String userName,String password)
  52. {
  53. // return if userName and password that send in parameter
  54. // at vector<string> userNames and vector<string> passwords or not
  55. for(int i=0;i<userNames.size();i++)
  56. {
  57. if(userNames.get(i).equals(userName)&&passwords.get(i).equals(password))
  58. return true;
  59. }
  60. return false;
  61. }
  62.  
  63. public void changeUser(String userName,String password)
  64. {
  65. // change curUserName to username that send at parameter
  66. // but you should do that if this username already at vector<string> userNames
  67. // and password match to this userName
  68. if(findAtuserNames(userName)==false )
  69. {
  70. if(correctPassword(userName, password))
  71. {
  72. curUserName=userName;
  73. }
  74. else
  75. {
  76. System.err.println("Wrong Passoword");
  77. }
  78. }
  79. else
  80. {
  81. System.err.println("this user not in the system ");
  82. }
  83. }
  84. public static void main(String[] args) {
  85. OS_A4 a=new OS_A4();
  86. a.addNewUser("amr mamdouh","123");
  87. a.addNewUser("amr mamdouh", "2030");
  88. a.changeUser("amr mamdouh","2030");
  89. a.changeUser("amr mamdouh","123");
  90. System.out.println("Cur User is "+a.curUserName);
  91. }
  92.  
  93. }
  94.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:14: error: class OS_A4 is public, should be declared in a file named OS_A4.java
public class OS_A4 {
       ^
1 error
stdout
Standard output is empty