You are on page 1of 16

:

)) ((
.

Practical Example
In multiusers-multitasks system it is required to register users in the
system with the following information:
user name
password
memory size : allocated memory size to the user
CPU time : time period allowed to the user
Directory path : working directory for the user
number of tasks running for the user
On this information the following operations are performed:
register user
delete user
change password
set CPU time
set memory size
get user information
get number of users currently in the system
NOTES: 1. Let maximum memory size available in the system= 10 GByte
2. Let maximum CPU time 24 hours per day.


class ( Information)
import javax.swing.JOptionPane;
JOptionPane
public class Informatiom
{
private String userName,password;
private String directoryPath;
public float memoryUser;// memory size for each user
public int numberUser;// number of users currently in the system for each user
public int timeUser;// cpu time for each user

//constractor
public Informatiom(){
userName=" ";
password=" ";
directoryPath=" ";
timeUser=0;
memoryUser=0.0f;
numberUser=0;
}

Information
//method for register
public void register()
{
System.out.print("Enter the name :");
userName=Keyboard.getString();
System.out.print("Enter the password :");
password=Keyboard.getString();
System.out.print("Enter the directoryPath :");
directoryPath=Keyboard.getString();
System.out.print("Enter the number of system for user :");
numberUser=Keyboard.getInteger();
}
class keyboard
//method for display informaion users
public void getUserInformation()
{
System.out.println("The name :"+ userName );
System.out.print("\tThe password :"+ password);
System.out.print("\tThe directoryPath :" +directoryPath);
System.out.println("The cpuTime for user :" + timeUser);
System.out.print("\tThe Memory Size for user :" + memoryUser);
System.out.print("\tThe number of Application for user :" + numberUser +"\n");
}

//method for set cpu time each user


public void setCpuTime(int total){
int time;
time=1440-total;
if (time>0){
do
{System.out.println("you can Enter cpu time less then or equal to use
ments:" + time );
timeUser=Keyboard.getInteger();}//end loop
while(timeUser>=time);
//return(timeUser);
}
else
{System.out.println("you can not create cpu time full time :" + time );}

24
1440
24

}//end set cpu time


//method for set memory size each user
public void setMemorySize(float total){
float size;
size=10000-total;
if (size>0){
do
{System.out.println("you can Enter cpu time less then or equal to use
Mbyte:" + size );
memoryUser=Keyboard.getFloat();}
while(memoryUser>=size);
}
else
{System.out.println("you can not create cpu time full time :" + size );}
}//end set Memory Size

10240
10 10240

//method for change password each user


public void changePassword(){
String frist,second;
int m=0;
do{
frist=JOptionPane.showInputDialog("Enter the new password" );
second=JOptionPane.showInputDialog(" Agian Enter the new
password" );
if(frist.equals(second))
m=1;
}while(m==0);
password=frist;
JOptionPane.showMessageDialog(null,"complete the change
password");
} //method
} // end class informaion


2- class (ClassSystem )
import javax.swing.JOptionPane;
import java.util.*;
public class ClassSystem
{
public static float memoryTotal=0.0f;//variable for sum memory size all users
private static int systemTotal=0;//variable for sum number of users currently in the system
private static int timeTotal=0;//variable for sum cpu time all users


public static void main(String args[]){
int maxUsers;//the maximum for users
maxUsers=Integer.parseInt(JOptionPane.showInputDialog("Enter the maximum of the number
Of users" ));
Informatiom[] info=new Informatiom[maxUsers];
int numberOfUser;//the number Of users
numberOfUser=Integer.parseInt(JOptionPane.showInputDialog("Enter the number Of
users" ));

maxUsers
numberOfUser

Class Information

for(int i=1;i<=numberOfUser;i++){
if(memoryTotal<10000 && timeTotal<1440)
{info[i]=new Informatiom();
info[i].register();
info[i].setMemorySize(memoryTotal);
info[i].setCpuTime(timeTotal);
memoryTotal= memoryTotal + info[i].memoryUser;
timeTotal = timeTotal + info[i].timeUser;
systemTotal= systemTotal + info[i].numberUser;
}
else
{
System.out.println("The number Of user is full");
break;
}}// end loop
int element;//variable for limit in array
String check;// varible for limit command of user
System.out.println(" Enter dis if want see All users - Enter reg if want add All user - Enter ch if
want change password user");
System.out.println(" Enter getinfo if want see user - Enter del if want delete user ");
System.out.println(" Enter getinfosys if see the iformation for system - Enter end if want end
execute");

)
(

do
{
check=JOptionPane.showInputDialog("Enter what do you" );

:
if(check.equals("dis"))
{ //for loop display informaion all users
for(int i=1;i<=numberOfUser;i++){
info[i].getUserInformation();}
}
:
// this else if for call regsiter method for register user
else if(check.equals("reg")){
numberOfUser=+1;
info[numberOfUser]=new Informatiom();
info[numberOfUser].register();
info[numberOfUser].setMemorySize(memoryTotal);
info[numberOfUser].setCpuTime(timeTotal);
memoryTotal= memoryTotal + info[numberOfUser].memoryUser;
timeTotal = timeTotal + info[numberOfUser].timeUser;
systemTotal= systemTotal + info[numberOfUser].numberUser;
}// end else if

:
// this else if for call change password method
else if(check.equals("ch")){
element=Integer.parseInt(JOptionPane.showInputDialog("Enter the element want change
password user" ));
info[element].changePassword();
}// end else if
:
// this else if for call getinformation user method
else if(check.equals("getinfo")){
element=Integer.parseInt(JOptionPane.showInputDialog("Enter the element want
display information
user" ));
info[element].getUserInformation();
}// end else if
:
// this else if for call delete user
else if(check.equals("del")){
element=Integer.parseInt(JOptionPane.showInputDialog("Enter the element want
delete user" ));
memoryTotal= memoryTotal - info[element].memoryUser;
info[element].memoryUser=0.0f;
timeTotal = timeTotal - info[element].timeUser;
info[element].timeUser=0;
systemTotal= systemTotal - info[element].numberUser;
info[element].numberUser=0;
}// end else if

:
// this else if for end execute
else if(check.equals("end")){
System.exit(0);;
}// end else if
( ) :
// this else if for call getInformationSystem method in the same class
else if(check.equals("getinfosys")){
getInformationSystem();
}// end else if
}//end do-while loop
while(check!="end");
}//end main method
( ) :
//method for display informaion system
public static void getInformationSystem(){
System.out.println(" cpu time full time :" + timeTotal);
System.out.println(" the memory size full :" + memoryTotal);
System.out.println("The total number of Application for users : :" + systemTotal);
}
} //end class system

) (

You might also like