Write an application to simulate the vehicles crossing a toll bridge on a motorway. For the purpose of this exercise, simulate the environment for five vehicles that are approaching the bridge and the toll booth. The vehicles are numbered from one to five. The vehicles have to go through the following five stages: Start the journey Arrive at the toll Enter the toll booth Exit the toll booth Cross the bridge The vehicles can be in any of the stages in parallel, except the third stage as only one vehicle can enter the toll booth at a time. The simulation is performed by having one thread for each vehicle, and consists of the following classes: Vehicle: Simulates the behavior of a vehicle. TollBooth: Simulates the behavior of a toll booth. Simulate: Creates the vehicles and controls the simulation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class vehical
{
private int id;
private static TollBooth = new TollBooth();
public vehicle(int id)
{
this.id=id;
}
public void exec()
{
Console.WriteLine("vehicle {0} starts journey",id+1);
Random RandGen = new Random();
int Rnd=RandGen .Next(0,100);
travel (Rnd);
Console.WriteLine("vehicle {0} arrives at the toll ", id+1);
toll.useToll(this);
travel (Rnd);
Console.WriteLine("vehicle {0} has crossed the bridge ",id+1);
}
public int getVehicleId()
{
return this.id;
}
public void travel (int time)
{
int limit =500000;
for(int j=0; j<time;j++)
{
for(int k =0 ; k<limit;k++)
(// do nothing);
}
}
}
public class TollBooth
{
bool inUse;
public TollBooth()
{
inUse=false;
}
public void useToll(Vehicle vehicle)
{
if(inUse==false)
{
inUse=true;
Console.WriteLine("vehicle {0} enters tollbooth ", vehicle.getVehicleId()+1);
vehicle.travel(50);
Console.WriteLine("Vehicle {0} exits tollbooth ",vehicle.getVehicleId()+1);
inUse=false;
break;
}
}
}
}
public class Simulate
{
private static int noOfVehicles =5;
private static Vehicles[] vehicles;
public static void Main(string[]args)
{
try
{
Simulate sm=new Simulate();
vehicles=new Vehicles[5];
for(int i=0;i<noOfVehicles;i++)
{
vehicles[i]=new Vehicles(i);
Thread t=new Thread(new ThreadStart(vehicles[i].exec);
t.Start();
Thread.Sleep(100);
}
Console.ReadLine();
}
catch (Exception ex)
{
System.Console.WriteLine(ex);
}
}
}
To access the Internet, Sandy uses a computer on which the Windows 7 operating system is installed. His friend, John asks Sandy to allow him to use his computer for accessing the Internet. Before handing over the computer to John, Sandy has to ensure that the private data and browsing history are not accessible to John. Therefore, he wants to perform the following tasks: Delete saved passwords in the browser. Delete browsing history. Delete download history. Increase the space for temporary files. Increase the number of days for which the browsing history is kept. Block the pop-up windows. Help Sandy to accomplish the preceding tasks. Prerequisite:To perform this exercise, you need to have Internet Explorer version 9 installed on your host machine. Hint 1: Delete the browsing history using the Internet Options dialog box. Hint 2: Enable pop-up blocking using the Tools menu.
1. select Start.
2. select All programs.
3.select Internet Explorer.
The Internet Explorer window is displayed.
4. select tools.
5. select Delete browsing history.
the delete Browsing History dialog box is displayed.
6. Ensure that the Temporary Internet file check box is selected.
7. Ensure that the History check box is selected.
8. select the Passwords check box.
9. click the Delete button.
10. select Tools.
11. select Internet options.
the internet Options Dialog box is displayed.
12. click the Settings button.
the Temporary Internet file and History Setting dialog box is pisplayed.
13. Replace value in the Disk space to use spin box with 500.
14. Ensure that the value in the Days to keep pages in history spin box is 20.
15. click the ok button
the Internet options dialog box is displayed again.
16. click the privacy tab.
17. Ensure that the Turn on pop-up Blocker check box is selected.
18. click the ok button.
close the internet Explorer window.
No comments:
Post a Comment