/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package os_a4;
import java.util.Vector;
/**
*
* @author amr
*/
public class OS_A4 {
Vector<String>userNames=new Vector<String>();
Vector<String>passwords=new Vector<String>();
{
// add userName & password that send at parameter
// to vector<string> userNames and vector<string> passwords
// but should (global variable)curUserName is admin
// and userName shouldn't be at vector<string> userNames
// you can use function findAtuserNames that you implement that
if(curUserName.equals("admain"))
{
if(findAtuserNames(userName))
{
userNames.add(userName);
passwords.add(password);
}
else
{
System.
err.
println("This User Name is Exsist int the System choose another one"); }
}
else
{
System.
err.
println("YOu Don't have the Rights to Add New User "); }
}
public boolean findAtuserNames
(String userName
) {
for(int i=0;i<userNames.size();i++)
if(userNames.get(i).equals(userName))
return false;
return true;
}
public boolean correctPassword
(String userName,
String password
) {
// return if userName and password that send in parameter
// at vector<string> userNames and vector<string> passwords or not
for(int i=0;i<userNames.size();i++)
{
if(userNames.get(i).equals(userName)&&passwords.get(i).equals(password))
return true;
}
return false;
}
{
// change curUserName to username that send at parameter
// but you should do that if this username already at vector<string> userNames
// and password match to this userName
if(findAtuserNames(userName)==false )
{
if(correctPassword(userName, password))
{
curUserName=userName;
}
else
{
System.
err.
println("Wrong Passoword"); }
}
else
{
System.
err.
println("this user not in the system "); }
}
public static void main
(String[] args
) { OS_A4 a=new OS_A4();
a.addNewUser("amr mamdouh","123");
a.addNewUser("amr mamdouh", "2030");
a.changeUser("amr mamdouh","2030");
a.changeUser("amr mamdouh","123");
System.
out.
println("Cur User is "+a.
curUserName); }
}