Escolar Documentos
Profissional Documentos
Cultura Documentos
)) ((
.
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");
}
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
) (