Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions VisitorTracker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
How to Run this program
======
You can import this to your favorite IDE and run main method it from there or you can run it from the command line.

Steps to run in command line:
1. Make sure you have java installed on your machine. If not, you can download it from here: https://www.java.com/en/download/
2. Open command line
3. Navigate to the directory where the file is located (VisitorTracker/src)
4. Compile the file using the command: javac Main.java
5. Run the file using the command: java Main
11 changes: 11 additions & 0 deletions VisitorTracker/VisitorTracker.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
19 changes: 19 additions & 0 deletions VisitorTracker/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Main {
public static void main(String[] args) {
WebServer webServer = new WebServer();
Site site1 = new Site("site1");
Site site2 = new Site("site2");
webServer.addSite(site1);
webServer.addSite(site2);

webServer.handleRequest("site1");
webServer.handleRequest("site1");
webServer.handleRequest("site2");
webServer.displayVisitorCount("site1");
webServer.displayVisitorCount("site2");
webServer.handleRequest("site1");
webServer.handleRequest("site2");
webServer.displayVisitorCount("site1");
webServer.displayVisitorCount("site3");
}
}
16 changes: 16 additions & 0 deletions VisitorTracker/src/Site.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Site {
private final String siteName;
private final VisitorCounter visitorCounter;

public Site(String siteName) {
this.siteName = siteName;
this.visitorCounter = new VisitorCounter();
}
public String getSiteName() {
return this.siteName;
}

public VisitorCounter getVisitorCounter() {
return visitorCounter;
}
}
15 changes: 15 additions & 0 deletions VisitorTracker/src/VisitorCounter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class VisitorCounter {
private int count;

public VisitorCounter() {
this.count = 0;
}

public void incrementCount() {
this.count++;
}

public int getCount() {
return this.count;
}
}
45 changes: 45 additions & 0 deletions VisitorTracker/src/WebServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.util.ArrayList;
import java.util.List;

public class WebServer {
private final List<Site> sites;

public WebServer() {
this.sites = new ArrayList<>();
}

public void addSite(Site site) {
this.sites.add(site);
}

public List<Site> getSites() {
return this.sites;
}

public void handleRequest(String siteName) {
Site site = findSite(siteName);
if (site != null) {
site.getVisitorCounter().incrementCount();
} else {
System.out.println("Site not found");
}
}

public void displayVisitorCount(String siteName) {
Site site = findSite(siteName);
if (site != null) {
System.out.println(site.getVisitorCounter().getCount());
} else {
System.out.println("Site not found");
}
}

private Site findSite(String siteName) {
for (Site site : this.sites) {
if (site.getSiteName().equals(siteName)) {
return site;
}
}
return null;
}
}
3 changes: 3 additions & 0 deletions cab-booking/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cab-booking/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cab-booking/.idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cab-booking/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions cab-booking/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cab-booking/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cab-booking/.idea/project-template.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions cab-booking/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cab-booking/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cab-booking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Add lombok.jar to this project
[Click Here to downlod lombok jar](https://projectlombok.org/download)

Configure Run Environment like :point_down::

![img.png](img.png)
12 changes: 12 additions & 0 deletions cab-booking/cab-booking.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lombok" level="application" />
</component>
</module>
Binary file added cab-booking/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
53 changes: 53 additions & 0 deletions cab-booking/src/com/cab/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.cab;

import com.cab.constants.Constants;
import com.cab.models.Location;
import com.cab.services.ApplicationService;
import javafx.util.Pair;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

public static void main(String[] args) throws FileNotFoundException {
// write your code here
ApplicationService applicationService = new ApplicationService();
Scanner input = new Scanner(new File(args[0]));

System.out.println("Enter Historical Data and Enter Exit to complete historical data");

while(input.hasNextLine()) {
String line = input.nextLine().trim();
if (line.equalsIgnoreCase(Constants.EXIT)) {
break;
}
String[] commands = line.split(" ");
if (commands.length == 4) {
applicationService.processHistoricalData(commands[0], Integer.parseInt(commands[1]), commands[2], Integer.parseInt(commands[3]));
}
}
while(true) {
System.out.println("Enter Continue or Exit like C or E");
String userPref = input.nextLine();
if (userPref.equalsIgnoreCase(Constants.E)) {
break;
}
System.out.println("Enter Number of Available Driver");
int numberOfDriver = Integer.parseInt(input.nextLine());
List<Pair<String, Location>> driverList = new ArrayList<>();
System.out.println("Enter Driver list like: d1,1,0");
for (int i = 0; i < numberOfDriver; i++) {
String line = input.nextLine();
driverList.add(applicationService.praseInput(line));
}
System.out.println("Enter passenger details");
Pair<String, Location> customerDetails = applicationService.praseInput(input.nextLine());

applicationService.getAvailableDriver(driverList, customerDetails);
}
}
}
6 changes: 6 additions & 0 deletions cab-booking/src/com/cab/constants/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cab.constants;

public class Constants {
public static final String EXIT = "EXIT";
public static final String E = "E";
}
Loading