diff --git a/VisitorTracker/README.md b/VisitorTracker/README.md
new file mode 100644
index 0000000..016552d
--- /dev/null
+++ b/VisitorTracker/README.md
@@ -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
diff --git a/VisitorTracker/VisitorTracker.iml b/VisitorTracker/VisitorTracker.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/VisitorTracker/VisitorTracker.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/VisitorTracker/src/Main.java b/VisitorTracker/src/Main.java
new file mode 100644
index 0000000..a048f85
--- /dev/null
+++ b/VisitorTracker/src/Main.java
@@ -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");
+ }
+}
\ No newline at end of file
diff --git a/VisitorTracker/src/Site.java b/VisitorTracker/src/Site.java
new file mode 100644
index 0000000..d7842f3
--- /dev/null
+++ b/VisitorTracker/src/Site.java
@@ -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;
+ }
+}
diff --git a/VisitorTracker/src/VisitorCounter.java b/VisitorTracker/src/VisitorCounter.java
new file mode 100644
index 0000000..679955a
--- /dev/null
+++ b/VisitorTracker/src/VisitorCounter.java
@@ -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;
+ }
+}
diff --git a/VisitorTracker/src/WebServer.java b/VisitorTracker/src/WebServer.java
new file mode 100644
index 0000000..ea9c058
--- /dev/null
+++ b/VisitorTracker/src/WebServer.java
@@ -0,0 +1,45 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class WebServer {
+ private final List sites;
+
+ public WebServer() {
+ this.sites = new ArrayList<>();
+ }
+
+ public void addSite(Site site) {
+ this.sites.add(site);
+ }
+
+ public List 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;
+ }
+}
diff --git a/cab-booking/.idea/.gitignore b/cab-booking/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/cab-booking/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/cab-booking/.idea/compiler.xml b/cab-booking/.idea/compiler.xml
new file mode 100644
index 0000000..a1757ae
--- /dev/null
+++ b/cab-booking/.idea/compiler.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cab-booking/.idea/description.html b/cab-booking/.idea/description.html
new file mode 100644
index 0000000..db5f129
--- /dev/null
+++ b/cab-booking/.idea/description.html
@@ -0,0 +1 @@
+Simple Java application that includes a class with main() method
\ No newline at end of file
diff --git a/cab-booking/.idea/encodings.xml b/cab-booking/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/cab-booking/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cab-booking/.idea/misc.xml b/cab-booking/.idea/misc.xml
new file mode 100644
index 0000000..2fc6c34
--- /dev/null
+++ b/cab-booking/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cab-booking/.idea/modules.xml b/cab-booking/.idea/modules.xml
new file mode 100644
index 0000000..c4badca
--- /dev/null
+++ b/cab-booking/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cab-booking/.idea/project-template.xml b/cab-booking/.idea/project-template.xml
new file mode 100644
index 0000000..1f08b88
--- /dev/null
+++ b/cab-booking/.idea/project-template.xml
@@ -0,0 +1,3 @@
+
+ IJ_BASE_PACKAGE
+
\ No newline at end of file
diff --git a/cab-booking/.idea/uiDesigner.xml b/cab-booking/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/cab-booking/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/cab-booking/.idea/vcs.xml b/cab-booking/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/cab-booking/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cab-booking/README.md b/cab-booking/README.md
new file mode 100644
index 0000000..87d1734
--- /dev/null
+++ b/cab-booking/README.md
@@ -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::
+
+
\ No newline at end of file
diff --git a/cab-booking/cab-booking.iml b/cab-booking/cab-booking.iml
new file mode 100644
index 0000000..6b762ae
--- /dev/null
+++ b/cab-booking/cab-booking.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cab-booking/img.png b/cab-booking/img.png
new file mode 100644
index 0000000..fe7dd20
Binary files /dev/null and b/cab-booking/img.png differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/Main.class b/cab-booking/out/production/cab-booking/com/cab/Main.class
new file mode 100644
index 0000000..5017b92
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/Main.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/constants/Constants.class b/cab-booking/out/production/cab-booking/com/cab/constants/Constants.class
new file mode 100644
index 0000000..43dfdbd
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/constants/Constants.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/enums/CabType.class b/cab-booking/out/production/cab-booking/com/cab/enums/CabType.class
new file mode 100644
index 0000000..10cc0bd
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/enums/CabType.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/models/Application.class b/cab-booking/out/production/cab-booking/com/cab/models/Application.class
new file mode 100644
index 0000000..7e05e3d
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/models/Application.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/models/Driver.class b/cab-booking/out/production/cab-booking/com/cab/models/Driver.class
new file mode 100644
index 0000000..8e13db2
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/models/Driver.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/models/Location.class b/cab-booking/out/production/cab-booking/com/cab/models/Location.class
new file mode 100644
index 0000000..e853082
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/models/Location.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/models/Rating.class b/cab-booking/out/production/cab-booking/com/cab/models/Rating.class
new file mode 100644
index 0000000..3c94562
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/models/Rating.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/models/User.class b/cab-booking/out/production/cab-booking/com/cab/models/User.class
new file mode 100644
index 0000000..55138ad
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/models/User.class differ
diff --git a/cab-booking/out/production/cab-booking/com/cab/services/ApplicationService.class b/cab-booking/out/production/cab-booking/com/cab/services/ApplicationService.class
new file mode 100644
index 0000000..22dd145
Binary files /dev/null and b/cab-booking/out/production/cab-booking/com/cab/services/ApplicationService.class differ
diff --git a/cab-booking/src/com/cab/Main.java b/cab-booking/src/com/cab/Main.java
new file mode 100644
index 0000000..95812c0
--- /dev/null
+++ b/cab-booking/src/com/cab/Main.java
@@ -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> 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 customerDetails = applicationService.praseInput(input.nextLine());
+
+ applicationService.getAvailableDriver(driverList, customerDetails);
+ }
+ }
+}
diff --git a/cab-booking/src/com/cab/constants/Constants.java b/cab-booking/src/com/cab/constants/Constants.java
new file mode 100644
index 0000000..8965e13
--- /dev/null
+++ b/cab-booking/src/com/cab/constants/Constants.java
@@ -0,0 +1,6 @@
+package com.cab.constants;
+
+public class Constants {
+ public static final String EXIT = "EXIT";
+ public static final String E = "E";
+}
diff --git a/cab-booking/src/com/cab/enums/CabType.java b/cab-booking/src/com/cab/enums/CabType.java
new file mode 100644
index 0000000..68d1424
--- /dev/null
+++ b/cab-booking/src/com/cab/enums/CabType.java
@@ -0,0 +1,7 @@
+package com.cab.enums;
+
+public enum CabType {
+ HATCHBACK,
+ SEDAN,
+ SUV
+}
diff --git a/cab-booking/src/com/cab/models/Application.java b/cab-booking/src/com/cab/models/Application.java
new file mode 100644
index 0000000..f674fa8
--- /dev/null
+++ b/cab-booking/src/com/cab/models/Application.java
@@ -0,0 +1,18 @@
+package com.cab.models;
+
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public @Data class Application {
+ private Map customers;
+ private Map drivers;
+ private StringBuilder history;
+
+ public Application() {
+ this.customers = new HashMap<>();
+ this.drivers = new HashMap<>();
+ this.history = new StringBuilder();
+ }
+}
diff --git a/cab-booking/src/com/cab/models/Driver.java b/cab-booking/src/com/cab/models/Driver.java
new file mode 100644
index 0000000..720db59
--- /dev/null
+++ b/cab-booking/src/com/cab/models/Driver.java
@@ -0,0 +1,13 @@
+package com.cab.models;
+
+import com.cab.enums.CabType;
+import lombok.Data;
+
+public class Driver extends User{
+ private CabType cabType;
+
+ public Driver(String name) {
+ super(name);
+ }
+
+}
diff --git a/cab-booking/src/com/cab/models/Location.java b/cab-booking/src/com/cab/models/Location.java
new file mode 100644
index 0000000..be43e5a
--- /dev/null
+++ b/cab-booking/src/com/cab/models/Location.java
@@ -0,0 +1,19 @@
+package com.cab.models;
+
+import lombok.Data;
+
+public @Data
+class Location {
+ private int x;
+ private int y;
+
+ public Location() {
+ this.x = 0;
+ this.y = 0;
+ }
+
+ public Location(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+}
diff --git a/cab-booking/src/com/cab/models/Rating.java b/cab-booking/src/com/cab/models/Rating.java
new file mode 100644
index 0000000..027bf95
--- /dev/null
+++ b/cab-booking/src/com/cab/models/Rating.java
@@ -0,0 +1,13 @@
+package com.cab.models;
+
+import lombok.Data;
+
+public @Data class Rating {
+ private String name;
+ private int rate;
+
+ public Rating(String name, int rating) {
+ this.name = name;
+ this.rate = rating;
+ }
+}
diff --git a/cab-booking/src/com/cab/models/User.java b/cab-booking/src/com/cab/models/User.java
new file mode 100644
index 0000000..1ba869c
--- /dev/null
+++ b/cab-booking/src/com/cab/models/User.java
@@ -0,0 +1,50 @@
+package com.cab.models;
+
+import javafx.util.Pair;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public @Data
+class User {
+ private String name;
+ Map> rate;
+ List ratings;
+ private int totalRating;
+ private Location currentLocation;
+
+ public User(String name) {
+ this.name = name;
+ this.rate = new HashMap<>();
+ //this.ratings = new ArrayList<>();
+ this.totalRating = 0;
+ this.currentLocation = new Location();
+ }
+
+ public void addRating(String name, int rating) {
+ Pair currentRate = new Pair<>(0, 0);
+ if (rate.containsKey(name)) {
+ currentRate = rate.get(name);
+ }
+ rate.put(name, new Pair<>(currentRate.getKey() + rating, currentRate.getValue() + 1));
+ //ratings.add(new Rating(name, rating));
+ totalRating += rating;
+ }
+
+ public double getAverageRating() {
+ if (rate.size() == 0) {
+ return 0;
+ }
+ double rating = (double) totalRating/rate.size();
+ return Double.parseDouble(String.format("%.2f", rating));
+ }
+
+ public double getRateAverageRating(String name) {
+ Pair currentRating = rate.getOrDefault(name, new Pair<>(0,1));
+ double rating = currentRating.getKey() / currentRating.getValue();
+ return Double.parseDouble(String.format("%.2f", rating));
+ }
+}
diff --git a/cab-booking/src/com/cab/services/ApplicationService.java b/cab-booking/src/com/cab/services/ApplicationService.java
new file mode 100644
index 0000000..ffffee4
--- /dev/null
+++ b/cab-booking/src/com/cab/services/ApplicationService.java
@@ -0,0 +1,84 @@
+package com.cab.services;
+
+import com.cab.models.Application;
+import com.cab.models.Driver;
+import com.cab.models.Location;
+import com.cab.models.User;
+import javafx.util.Pair;
+
+import java.util.List;
+
+public class ApplicationService {
+ Application application;
+ public ApplicationService() {
+ this.application = new Application();
+ }
+
+ public void processHistoricalData(String driverName, int driverRating, String customerName, int customerRating) {
+ addDriverRating(driverName, customerName, driverRating);
+ addCustomerRating(customerName, driverName, customerRating);
+ }
+
+ private void addDriverRating(String driverName, String customerName, int rating) {
+ if (!application.getDrivers().containsKey(driverName)) {
+ Driver driver = new Driver(driverName);
+ application.getDrivers().put(driverName, driver);
+ }
+ application.getDrivers().get(driverName).addRating(customerName, rating);
+ System.out.println("Driver Rating Added");
+ }
+
+ private void addCustomerRating(String customerName, String driverName, int rating) {
+ if (!application.getCustomers().containsKey(customerName)) {
+ User customer = new User(customerName);
+ application.getCustomers().put(customerName, customer);
+ }
+ application.getCustomers().get(customerName).addRating(driverName, rating);
+ System.out.println("Customer Rating Added");
+ }
+
+
+
+ public void getAvailableDriver(List> driversDetailsList, Pair customerDetails) {
+ String customerName = customerDetails.getKey();
+ if (!application.getCustomers().containsKey(customerName)) {
+ User user = new User(customerName);
+ application.getCustomers().put(customerName, user);
+ }
+ User customer = application.getCustomers().get(customerName);
+ System.out.println("Average Rating : " + customer.getAverageRating());
+ findEligibleDriveBasedOnRating(customer, driversDetailsList);
+
+ findByDistance(customerDetails, driversDetailsList);
+
+ }
+
+ private void findByDistance(Pair customerDetails, List> driversDetailsList) {
+
+ }
+
+ private void findEligibleDriveBasedOnRating(User customer, List> driversDetailsList) {
+ StringBuilder driverList = new StringBuilder("Eligible Driver :");
+ double customerRating = customer.getAverageRating();
+ for (Pair driverDetails : driversDetailsList) {
+ Driver driver = application.getDrivers().get(driverDetails.getKey());
+ if (driver != null) {
+ double driverRating = driver.getAverageRating();
+ if (driverRating >= customerRating) {
+ driverList.append("\n" + driverDetails.getKey() + ", " + driverRating);
+ }
+ }
+ }
+ System.out.println(new String(driverList));
+ }
+
+ public Pair praseInput(String line) {
+ String[] command = line.split(",");
+ if (command.length != 3) {
+ System.out.println("Invalid Input");
+ System.out.println("Enter like : d1,1,2");
+ return null;
+ }
+ return new Pair<>(command[0], new Location(Integer.parseInt(command[1]), Integer.parseInt(command[2])));
+ }
+}
diff --git a/cab-booking/test/com/cab/testCase1.txt b/cab-booking/test/com/cab/testCase1.txt
new file mode 100644
index 0000000..69e45d1
--- /dev/null
+++ b/cab-booking/test/com/cab/testCase1.txt
@@ -0,0 +1,18 @@
+d1 4 c1 5
+d1 5 c2 4
+d1 1 c3 2
+d2 5 c1 1
+d2 5 c2 5
+d2 4 c3 5
+d3 3 c1 2
+d3 4 c2 5
+d3 3 c3 3
+EXIT
+C
+4
+d1,1,0
+d2,2,0
+d3,3,0
+d4,4,0
+c2,1,0
+E
diff --git a/digital-wallet/.idea/.gitignore b/digital-wallet/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/digital-wallet/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/digital-wallet/.idea/compiler.xml b/digital-wallet/.idea/compiler.xml
new file mode 100644
index 0000000..a1757ae
--- /dev/null
+++ b/digital-wallet/.idea/compiler.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/digital-wallet/.idea/description.html b/digital-wallet/.idea/description.html
new file mode 100644
index 0000000..db5f129
--- /dev/null
+++ b/digital-wallet/.idea/description.html
@@ -0,0 +1 @@
+Simple Java application that includes a class with main() method
\ No newline at end of file
diff --git a/digital-wallet/.idea/encodings.xml b/digital-wallet/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/digital-wallet/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/digital-wallet/.idea/misc.xml b/digital-wallet/.idea/misc.xml
new file mode 100644
index 0000000..2fc6c34
--- /dev/null
+++ b/digital-wallet/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/digital-wallet/.idea/modules.xml b/digital-wallet/.idea/modules.xml
new file mode 100644
index 0000000..119facd
--- /dev/null
+++ b/digital-wallet/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/digital-wallet/.idea/project-template.xml b/digital-wallet/.idea/project-template.xml
new file mode 100644
index 0000000..1f08b88
--- /dev/null
+++ b/digital-wallet/.idea/project-template.xml
@@ -0,0 +1,3 @@
+
+ IJ_BASE_PACKAGE
+
\ No newline at end of file
diff --git a/digital-wallet/.idea/uiDesigner.xml b/digital-wallet/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/digital-wallet/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/digital-wallet/.idea/vcs.xml b/digital-wallet/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/digital-wallet/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/digital-wallet/README.md b/digital-wallet/README.md
new file mode 100644
index 0000000..87d1734
--- /dev/null
+++ b/digital-wallet/README.md
@@ -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::
+
+
\ No newline at end of file
diff --git a/digital-wallet/digital-wallet.iml b/digital-wallet/digital-wallet.iml
new file mode 100644
index 0000000..6b762ae
--- /dev/null
+++ b/digital-wallet/digital-wallet.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/digital-wallet/img.png b/digital-wallet/img.png
new file mode 100644
index 0000000..57acd18
Binary files /dev/null and b/digital-wallet/img.png differ
diff --git a/digital-wallet/out/production/digital-wallet/com/wallet/Main.class b/digital-wallet/out/production/digital-wallet/com/wallet/Main.class
new file mode 100644
index 0000000..43a2ec9
Binary files /dev/null and b/digital-wallet/out/production/digital-wallet/com/wallet/Main.class differ
diff --git a/digital-wallet/out/production/digital-wallet/com/wallet/constants/Constant.class b/digital-wallet/out/production/digital-wallet/com/wallet/constants/Constant.class
new file mode 100644
index 0000000..67546d3
Binary files /dev/null and b/digital-wallet/out/production/digital-wallet/com/wallet/constants/Constant.class differ
diff --git a/digital-wallet/out/production/digital-wallet/com/wallet/models/Account.class b/digital-wallet/out/production/digital-wallet/com/wallet/models/Account.class
new file mode 100644
index 0000000..bb17d31
Binary files /dev/null and b/digital-wallet/out/production/digital-wallet/com/wallet/models/Account.class differ
diff --git a/digital-wallet/out/production/digital-wallet/com/wallet/models/User.class b/digital-wallet/out/production/digital-wallet/com/wallet/models/User.class
new file mode 100644
index 0000000..56245e9
Binary files /dev/null and b/digital-wallet/out/production/digital-wallet/com/wallet/models/User.class differ
diff --git a/digital-wallet/out/production/digital-wallet/com/wallet/models/Wallet.class b/digital-wallet/out/production/digital-wallet/com/wallet/models/Wallet.class
new file mode 100644
index 0000000..7eac13b
Binary files /dev/null and b/digital-wallet/out/production/digital-wallet/com/wallet/models/Wallet.class differ
diff --git a/digital-wallet/out/production/digital-wallet/com/wallet/service/WalletService.class b/digital-wallet/out/production/digital-wallet/com/wallet/service/WalletService.class
new file mode 100644
index 0000000..258b9cd
Binary files /dev/null and b/digital-wallet/out/production/digital-wallet/com/wallet/service/WalletService.class differ
diff --git a/digital-wallet/src/com/wallet/Main.java b/digital-wallet/src/com/wallet/Main.java
new file mode 100644
index 0000000..b046698
--- /dev/null
+++ b/digital-wallet/src/com/wallet/Main.java
@@ -0,0 +1,67 @@
+package com.wallet;
+
+import com.wallet.constants.Constant;
+import com.wallet.service.WalletService;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+public class Main {
+
+ public static void main(String[] args) throws FileNotFoundException {
+ // write your code here
+ Scanner input = new Scanner(new File(args[0]));
+
+ WalletService walletService = new WalletService(3);
+
+ while (input.hasNextLine()) {
+ String line = input.nextLine().trim();
+ String[] commands = line.split(" ");
+ switch (commands[0]) {
+ case Constant.CREATE_WALLET:
+ if (commands.length != 3) {
+ System.out.println(Constant.INVALID_INPUT);
+ break;
+ }
+ walletService.createWallet(commands[1], Double.parseDouble(commands[2]));
+ break;
+ case Constant.TRANSFER_MONEY:
+ if (commands.length != 4) {
+ System.out.println(Constant.INVALID_INPUT);
+ break;
+ }
+ walletService.transferMoney(commands[1], commands[2], Double.parseDouble(commands[3]));
+ break;
+ case Constant.OVERVIEW:
+ if (commands.length != 1) {
+ System.out.println(Constant.INVALID_INPUT);
+ break;
+ }
+ walletService.getOverview();
+ break;
+ case Constant.STATEMENT:
+ if (commands.length != 2) {
+ System.out.println(Constant.INVALID_INPUT);
+ break;
+ }
+ walletService.getStatementByUserName(commands[1]);
+ break;
+ case Constant.OFFER2:
+ if (commands.length != 1) {
+ System.out.println(Constant.INVALID_INPUT);
+ break;
+ }
+ walletService.fireOffer2();
+ break;
+ case Constant.FIXED_DEPOSIT:
+ if (commands.length != 3) {
+ System.out.println(Constant.INVALID_INPUT);
+ break;
+ }
+ walletService.fixedDeposit(commands[1], Double.parseDouble(commands[2]));
+ break;
+ }
+ }
+ }
+}
diff --git a/digital-wallet/src/com/wallet/constants/Constant.java b/digital-wallet/src/com/wallet/constants/Constant.java
new file mode 100644
index 0000000..baa82d4
--- /dev/null
+++ b/digital-wallet/src/com/wallet/constants/Constant.java
@@ -0,0 +1,13 @@
+package com.wallet.constants;
+
+public class Constant {
+ public static final String OFFER1 = "Offer1 credit 10";
+ public static final String EXIT = "EXIT";
+ public static final String CREATE_WALLET = "CreateWallet";
+ public static final String TRANSFER_MONEY = "TransferMoney";
+ public static final String OVERVIEW = "Overview";
+ public static final String STATEMENT = "Statement";
+ public static final String OFFER2 = "Offer2";
+ public static final String INVALID_INPUT = "Invalid Input";
+ public static final String FIXED_DEPOSIT= "FixedDeposit";
+}
diff --git a/digital-wallet/src/com/wallet/models/Account.java b/digital-wallet/src/com/wallet/models/Account.java
new file mode 100644
index 0000000..71c5f1d
--- /dev/null
+++ b/digital-wallet/src/com/wallet/models/Account.java
@@ -0,0 +1,35 @@
+package com.wallet.models;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public @Data class Account {
+ public static final AtomicInteger count = new AtomicInteger(0);
+ private String id;
+ private int number;
+ private double balance;
+ private double fdBalance;
+ private String history;
+ private List statements;
+ private int noOfTransaction;
+ private int noOfTransactionAfterFD;
+
+ public Account(double balance) {
+ this.id = UUID.randomUUID().toString();
+ this.number = count.incrementAndGet();
+ this.balance = balance;
+ this.fdBalance = 0.0;
+ this.history = "";
+ this.statements = new ArrayList<>();
+ this.noOfTransaction = 0;
+ this.noOfTransactionAfterFD = -1;
+ }
+
+ public void addStatement(String statement) {
+ this.statements.add(statement);
+ }
+}
diff --git a/digital-wallet/src/com/wallet/models/User.java b/digital-wallet/src/com/wallet/models/User.java
new file mode 100644
index 0000000..09307ec
--- /dev/null
+++ b/digital-wallet/src/com/wallet/models/User.java
@@ -0,0 +1,19 @@
+package com.wallet.models;
+
+import lombok.Data;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+public @Data
+class User {
+ public static final AtomicInteger count = new AtomicInteger(0);
+ private String userName;
+ private int userId;
+ private int accountNumber;
+
+ public User(String userName, int accountNumber) {
+ this.userName = userName;
+ this.userId = count.incrementAndGet();
+ this.accountNumber = accountNumber;
+ }
+}
diff --git a/digital-wallet/src/com/wallet/models/Wallet.java b/digital-wallet/src/com/wallet/models/Wallet.java
new file mode 100644
index 0000000..422dd2d
--- /dev/null
+++ b/digital-wallet/src/com/wallet/models/Wallet.java
@@ -0,0 +1,23 @@
+package com.wallet.models;
+
+import com.wallet.models.Account;
+import com.wallet.models.User;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public @Data
+class Wallet {
+ private Map users;
+ private Map accounts;
+ private List userList;
+
+ public Wallet() {
+ this.users = new HashMap();
+ this.accounts = new HashMap<>();
+ this.userList = new ArrayList<>();
+ }
+}
diff --git a/digital-wallet/src/com/wallet/service/WalletService.java b/digital-wallet/src/com/wallet/service/WalletService.java
new file mode 100644
index 0000000..c448e49
--- /dev/null
+++ b/digital-wallet/src/com/wallet/service/WalletService.java
@@ -0,0 +1,205 @@
+package com.wallet.service;
+
+import com.wallet.constants.Constant;
+import com.wallet.models.Account;
+import com.wallet.models.User;
+import com.wallet.models.Wallet;
+
+import java.util.List;
+import java.util.ArrayList;
+
+public class WalletService {
+ private final Wallet wallet;
+ private final int topNNumber;
+ public static final double INTEREST_AMOUNT = 10;
+ public static final int NO_OF_TXN = 5;
+
+ public WalletService(int topNNumber) {
+ this.wallet = new Wallet();
+ this.topNNumber = topNNumber;
+ }
+
+ public void createWallet(String userName, double initialBalance) {
+ Account account = new Account(initialBalance);
+ User user = new User(userName, account.getNumber());
+ wallet.getUserList().add(user);
+ wallet.getUsers().put(userName, user);
+ wallet.getAccounts().put(account.getNumber(), account);
+ System.out.println("Account Created for user : " + userName + " with initial balance : " + initialBalance);
+ }
+
+ public void transferMoney(String fromUser, String toUser, double amount) {
+ if (!wallet.getUsers().containsKey(fromUser)) {
+ System.out.println("The sender account is not exist");
+ return;
+ }
+ if (!wallet.getUsers().containsKey(toUser)) {
+ System.out.println("The receiver account is not exist");
+ return;
+ }
+ if (amount < 0.0001) {
+ System.out.println("Transaction is not allowed because the amount is less than 000.1 ");
+ return;
+ }
+ int fromAccountNumber = wallet.getUsers().get(fromUser).getAccountNumber();
+ int toAccountNumber = wallet.getUsers().get(toUser).getAccountNumber();
+ Account fromAccount = wallet.getAccounts().get(fromAccountNumber);
+ Account toAccount = wallet.getAccounts().get(toAccountNumber);
+
+ if (!isAccountHaveSufficientBalance(fromAccountNumber, amount)) {
+ return;
+ }
+
+ if (fromAccount.getBalance() >= amount) {
+ fromAccount.setBalance(fromAccount.getBalance() - amount);
+ if (fromAccount.getNoOfTransactionAfterFD() > -1) {
+ fromAccount.setNoOfTransactionAfterFD(fromAccount.getNoOfTransactionAfterFD() + 1);
+ }
+ } else if ((fromAccount.getBalance() + fromAccount.getFdBalance()) >= amount) {
+ fromAccount.setBalance(fromAccount.getBalance() + fromAccount.getFdBalance() - amount);
+ fromAccount.setFdBalance(0.0);
+ fromAccount.setNoOfTransactionAfterFD(-1);
+ }
+ toAccount.setBalance(toAccount.getBalance() + amount);
+ fromAccount.addStatement(toUser + " debited " + amount);
+ toAccount.addStatement(fromUser + " credited " + amount);
+ fromAccount.setNoOfTransaction(fromAccount.getNoOfTransaction() + 1);
+ toAccount.setNoOfTransaction(toAccount.getNoOfTransaction() + 1);
+
+ if (fromAccount.getBalance() == toAccount.getBalance()) {
+ fireOffer1(fromAccount, toAccount);
+ }
+ if (fromAccount.getNoOfTransactionAfterFD() == NO_OF_TXN && fromAccount.getBalance() > 0) {
+ fromAccount.setBalance(fromAccount.getBalance() + INTEREST_AMOUNT);
+ fromAccount.addStatement("Interest credited" + INTEREST_AMOUNT);
+ }
+ }
+
+ private void fireOffer1(Account from, Account to) {
+ System.out.println("Offer 1 fired");
+ from.setBalance(from.getBalance() + 10);
+ to.setBalance(to.getBalance() + 10);
+ from.addStatement(Constant.OFFER1);
+ to.addStatement(Constant.OFFER1);
+ }
+
+ public void getStatementByUserName(String userName) {
+ if (!wallet.getUsers().containsKey(userName)) {
+ System.out.println("User with name " + userName + " is not exist");
+ return;
+ }
+ Account account = wallet.getAccounts().get(wallet.getUsers().get(userName).getAccountNumber());
+ for (String statement : account.getStatements()) {
+ System.out.println(statement);
+ }
+ }
+
+ public void getOverview() {
+ if (wallet.getUserList().size() == 0) {
+ System.out.println("There is no user");
+ return;
+ }
+ for (User user : wallet.getUserList()) {
+ Account account = wallet.getAccounts().get(wallet.getUsers().get(user.getUserName()).getAccountNumber());
+ System.out.print(user.getUserName() + " " + account.getBalance());
+ if (account.getFdBalance() > 0) {
+ System.out.print(" FD " + account.getFdBalance());
+ }
+ System.out.println();
+ }
+ }
+
+ public void fireOffer2() {
+ List topUserNames = getTopNUserName();
+ if (topUserNames.size() >= 1) {
+ int accountNumber = wallet.getUsers().get(topUserNames.get(0)).getAccountNumber();
+ Account account = wallet.getAccounts().get(accountNumber);
+ account.setBalance(account.getBalance() + 10);
+ }
+ if (topUserNames.size() >= 2) {
+ int accountNumber = wallet.getUsers().get(topUserNames.get(1)).getAccountNumber();
+ Account account = wallet.getAccounts().get(accountNumber);
+ account.setBalance(account.getBalance() + 5);
+ }
+ if (topUserNames.size() >= 3) {
+ int accountNumber = wallet.getUsers().get(topUserNames.get(2)).getAccountNumber();
+ Account account = wallet.getAccounts().get(accountNumber);
+ account.setBalance(account.getBalance() + 2);
+ }
+ System.out.println("Offer 2 fired");
+ }
+
+ private List getTopNUserName() {
+ List users = new ArrayList<>(wallet.getUserList());
+ users.sort((o1, o2) -> {
+ Account accountO1 = wallet.getAccounts().get(o1.getAccountNumber());
+ Account accountO2 = wallet.getAccounts().get(o2.getAccountNumber());
+ int indexOfO1 = wallet.getUserList().indexOf(o1);
+ int indexOfO2 = wallet.getUserList().indexOf(o2);
+ return accountO1.getNoOfTransaction() > accountO2.getNoOfTransaction() ? -1 :
+ accountO1.getNoOfTransaction() == accountO2.getNoOfTransaction() && accountO1.getBalance() > accountO2.getBalance() ? -1 :
+ accountO1.getNoOfTransaction() == accountO2.getNoOfTransaction() && accountO1.getBalance() == accountO2.getBalance() && indexOfO1 < indexOfO2 ? -1 : 0;
+ });
+ List resultList = new ArrayList<>();
+ for (User user : users) {
+ resultList.add(user.getUserName());
+ if (resultList.size() == topNNumber) {
+ break;
+ }
+ }
+ return resultList;
+ }
+
+ public void fixedDeposit(String userName, double amount) {
+ if(isUserExist(userName)) {
+ int accountNumber = wallet.getUsers().get(userName).getAccountNumber();
+ if (isAccountHaveSufficientForFDBalance(accountNumber, amount)) {
+ Account account = wallet.getAccounts().get(accountNumber);
+ account.setFdBalance(amount);
+ account.setBalance(account.getBalance() - amount);
+ account.addStatement("debited for FD " + amount);
+ account.setNoOfTransaction(account.getNoOfTransaction() + 1);
+ account.setNoOfTransactionAfterFD(0);
+ System.out.println("Added Money to FD");
+ }
+ }
+ }
+
+ private boolean isAccountHaveSufficientForFDBalance(int accountNumber, double amount) {
+ if (isAccountExist(accountNumber)) {
+ Account account = wallet.getAccounts().get(accountNumber);
+ if (account.getBalance() < amount) {
+ System.out.println("Account don't have sufficient balance to transfer");
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean isAccountHaveSufficientBalance(int accountNumber, double amount) {
+ if (isAccountExist(accountNumber)) {
+ Account account = wallet.getAccounts().get(accountNumber);
+ if (account.getBalance() + account.getFdBalance() < amount) {
+ System.out.println("Account don't have sufficient balance to transfer");
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean isAccountExist(int accountNumber) {
+ if (!wallet.getAccounts().containsKey(accountNumber)) {
+ System.out.println("Account is not exist");
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isUserExist(String userName) {
+ if (!wallet.getUsers().containsKey(userName)) {
+ System.out.println("User with name " + userName + " is not exist");
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/digital-wallet/test/testCase1.txt b/digital-wallet/test/testCase1.txt
new file mode 100644
index 0000000..a5e5a1a
--- /dev/null
+++ b/digital-wallet/test/testCase1.txt
@@ -0,0 +1,17 @@
+CreateWallet Harry 100
+CreateWallet Ron 95.7
+CreateWallet Hermione 104
+CreateWallet Albus 200
+CreateWallet Draco 500
+Overview
+TransferMoney Albus Draco 30
+TransferMoney Hermione Harry 2
+TransferMoney Albus Ron 5
+Overview
+Statement Harry
+Statement Albus
+Offer2
+Overview
+FixedDeposit Harry 50
+Statement Harry
+Overview
\ No newline at end of file
diff --git a/movie-review/.idea/.gitignore b/movie-review/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/movie-review/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/movie-review/.idea/compiler.xml b/movie-review/.idea/compiler.xml
new file mode 100644
index 0000000..a1757ae
--- /dev/null
+++ b/movie-review/.idea/compiler.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/movie-review/.idea/description.html b/movie-review/.idea/description.html
new file mode 100644
index 0000000..db5f129
--- /dev/null
+++ b/movie-review/.idea/description.html
@@ -0,0 +1 @@
+Simple Java application that includes a class with main() method
\ No newline at end of file
diff --git a/movie-review/.idea/encodings.xml b/movie-review/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/movie-review/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/movie-review/.idea/misc.xml b/movie-review/.idea/misc.xml
new file mode 100644
index 0000000..2fc6c34
--- /dev/null
+++ b/movie-review/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/movie-review/.idea/modules.xml b/movie-review/.idea/modules.xml
new file mode 100644
index 0000000..206191c
--- /dev/null
+++ b/movie-review/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/movie-review/.idea/project-template.xml b/movie-review/.idea/project-template.xml
new file mode 100644
index 0000000..1f08b88
--- /dev/null
+++ b/movie-review/.idea/project-template.xml
@@ -0,0 +1,3 @@
+
+ IJ_BASE_PACKAGE
+
\ No newline at end of file
diff --git a/movie-review/.idea/uiDesigner.xml b/movie-review/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/movie-review/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/movie-review/.idea/vcs.xml b/movie-review/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/movie-review/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/movie-review/movie-review.iml b/movie-review/movie-review.iml
new file mode 100644
index 0000000..6b762ae
--- /dev/null
+++ b/movie-review/movie-review.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/movie-review/out/production/movie-review/com/movie/Main.class b/movie-review/out/production/movie-review/com/movie/Main.class
new file mode 100644
index 0000000..907ccdc
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/Main.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/constants/Constants.class b/movie-review/out/production/movie-review/com/movie/constants/Constants.class
new file mode 100644
index 0000000..2894312
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/constants/Constants.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/enums/CategoryType.class b/movie-review/out/production/movie-review/com/movie/enums/CategoryType.class
new file mode 100644
index 0000000..8cc146c
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/enums/CategoryType.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/models/Application.class b/movie-review/out/production/movie-review/com/movie/models/Application.class
new file mode 100644
index 0000000..ea800ee
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/models/Application.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/models/Movie.class b/movie-review/out/production/movie-review/com/movie/models/Movie.class
new file mode 100644
index 0000000..08a781c
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/models/Movie.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/models/Review.class b/movie-review/out/production/movie-review/com/movie/models/Review.class
new file mode 100644
index 0000000..f4eb8de
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/models/Review.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/models/User.class b/movie-review/out/production/movie-review/com/movie/models/User.class
new file mode 100644
index 0000000..a8e40e9
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/models/User.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/models/UserReview.class b/movie-review/out/production/movie-review/com/movie/models/UserReview.class
new file mode 100644
index 0000000..40b877d
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/models/UserReview.class differ
diff --git a/movie-review/out/production/movie-review/com/movie/services/ApplicationService.class b/movie-review/out/production/movie-review/com/movie/services/ApplicationService.class
new file mode 100644
index 0000000..b93bbab
Binary files /dev/null and b/movie-review/out/production/movie-review/com/movie/services/ApplicationService.class differ
diff --git a/movie-review/src/com/movie/Main.java b/movie-review/src/com/movie/Main.java
new file mode 100644
index 0000000..82ced35
--- /dev/null
+++ b/movie-review/src/com/movie/Main.java
@@ -0,0 +1,61 @@
+package com.movie;
+
+import com.movie.constants.Constants;
+import com.movie.services.ApplicationService;
+
+import java.util.Scanner;
+
+public class Main {
+
+ public static void main(String[] args) {
+ // write your code here
+ System.out.println("Application Started");
+ ApplicationService applicationService = new ApplicationService();
+ Scanner input = new Scanner(System.in);
+ System.out.println("Enter number of movie want to onboard");
+ int numberOfMovie = Integer.parseInt(input.nextLine());
+ for (int i = 0; i < numberOfMovie; i++) {
+ String line = input.nextLine().trim();
+ int addMovieLength = Constants.ADD_MOVIE.length();
+ String movieDetails = line.substring(addMovieLength, line.length() - addMovieLength - 1);
+ applicationService.addMovie(movieDetails);
+ }
+ System.out.println("Enter number of user");
+ int numberOfUser = Integer.parseInt(input.nextLine());
+ for (int i = 0; i < numberOfMovie; i++) {
+ String line = input.nextLine().trim();
+ int addUserLength = Constants.ADD_USER.length();
+ String userDetails = line.substring(addUserLength, line.length() - addUserLength - 1);
+ applicationService.addUser(userDetails);
+ }
+ System.out.println("Add/Update/Delete Review or EXIT");
+ while(true) {
+ String line = input.nextLine().trim();
+ if (line.equalsIgnoreCase(Constants.EXIT)) {
+ break;
+ }
+ String edit = line.substring(0, line.indexOf("\""));
+ switch (edit) {
+ case Constants.ADD_REVIEW:
+ int addReview = line.length() - edit.length() - 1;
+ String reviewDetails = line.substring(edit.length(), addReview);
+ String[] commands = reviewDetails.split(",");
+ applicationService.addReview(commands[0], commands[1], Integer.parseInt(commands[2]));
+ break;
+ case Constants.UPDATE_REVIEW:
+ break;
+ case Constants.DELETE_REVIEW:
+ break;
+ case Constants.LIST_REVIEW:
+ int listReviewLength = line.length() - edit.length() - 1;
+ applicationService.listReview(line.substring(edit.length() + 1, listReviewLength - 1));
+ break;
+ case Constants.LIST_TOP:
+ break;
+ default:
+ System.out.println("Invalid option");
+ }
+ }
+ System.out.println("Application Terminated");
+ }
+}
diff --git a/movie-review/src/com/movie/constants/Constants.java b/movie-review/src/com/movie/constants/Constants.java
new file mode 100644
index 0000000..c5f9f58
--- /dev/null
+++ b/movie-review/src/com/movie/constants/Constants.java
@@ -0,0 +1,14 @@
+package com.movie.constants;
+
+public class Constants {
+ public static final String YEAR = "Year";
+ public static final String GENRE = "Genre";
+ public static final String ADD_MOVIE = "Add Movie(";
+ public static final String ADD_USER = "Add User(";
+ public static final String ADD_REVIEW = "add_review(";
+ public static final String UPDATE_REVIEW = "update_review(";
+ public static final String DELETE_REVIEW = "delete_review(";
+ public static final String LIST_REVIEW = "list_review(";
+ public static final String LIST_TOP = "List Top";
+ public static final String EXIT = "EXIT";
+}
diff --git a/movie-review/src/com/movie/enums/CategoryType.java b/movie-review/src/com/movie/enums/CategoryType.java
new file mode 100644
index 0000000..1fc645c
--- /dev/null
+++ b/movie-review/src/com/movie/enums/CategoryType.java
@@ -0,0 +1,7 @@
+package com.movie.enums;
+
+public enum CategoryType {
+ VIEWER,
+ CRITIC,
+ EXPERT
+}
diff --git a/movie-review/src/com/movie/models/Application.java b/movie-review/src/com/movie/models/Application.java
new file mode 100644
index 0000000..a60547e
--- /dev/null
+++ b/movie-review/src/com/movie/models/Application.java
@@ -0,0 +1,24 @@
+package com.movie.models;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public @Data class Application {
+ Map users;
+ Map movies;
+ Map reviews;
+ Map> userReview;
+ Map movieReview;
+
+ public Application() {
+ this.users = new HashMap();
+ this.movies = new HashMap();
+ this.reviews = new HashMap();
+ this.userReview = new HashMap>();
+ this.movieReview = new HashMap();
+ }
+}
diff --git a/movie-review/src/com/movie/models/Movie.java b/movie-review/src/com/movie/models/Movie.java
new file mode 100644
index 0000000..6398fb7
--- /dev/null
+++ b/movie-review/src/com/movie/models/Movie.java
@@ -0,0 +1,23 @@
+package com.movie.models;
+
+import lombok.Data;
+
+import java.util.UUID;
+
+public @Data class Movie {
+ private String movieId;
+ private String movieName;
+ private String genre;
+ private int releaseYear;
+ private boolean releaseFlag;
+ private double rating;
+
+ public Movie(String movieName, String genre, int releaseYear, boolean releaseFlag) {
+ this.movieId = UUID.randomUUID().toString();
+ this.movieName = movieName;
+ this.genre = genre;
+ this.releaseYear = releaseYear;
+ this.releaseFlag = releaseFlag;
+ this.rating = 0.0;
+ }
+}
diff --git a/movie-review/src/com/movie/models/Review.java b/movie-review/src/com/movie/models/Review.java
new file mode 100644
index 0000000..2d64341
--- /dev/null
+++ b/movie-review/src/com/movie/models/Review.java
@@ -0,0 +1,19 @@
+package com.movie.models;
+
+import lombok.Data;
+
+import java.util.UUID;
+
+public @Data class Review {
+ private String reviewId;
+ private int rate;
+ private String description;
+ private String movieName;
+
+ public Review(int rate, String description, String movieName) {
+ this.reviewId = UUID.randomUUID().toString();
+ this.rate = rate;
+ this.description = description;
+ this.movieName = movieName;
+ }
+}
diff --git a/movie-review/src/com/movie/models/User.java b/movie-review/src/com/movie/models/User.java
new file mode 100644
index 0000000..61fbb1f
--- /dev/null
+++ b/movie-review/src/com/movie/models/User.java
@@ -0,0 +1,18 @@
+package com.movie.models;
+
+import com.movie.enums.CategoryType;
+import lombok.Data;
+
+import java.util.UUID;
+
+public @Data class User {
+ private String userId;
+ private String userName;
+ private CategoryType categoryType;
+
+ public User(String userName) {
+ this.userId = UUID.randomUUID().toString();
+ this.userName = userName;
+ this.categoryType = CategoryType.VIEWER;
+ }
+}
diff --git a/movie-review/src/com/movie/models/UserReview.java b/movie-review/src/com/movie/models/UserReview.java
new file mode 100644
index 0000000..a399860
--- /dev/null
+++ b/movie-review/src/com/movie/models/UserReview.java
@@ -0,0 +1,5 @@
+package com.movie.models;
+
+public class UserReview {
+ private User user;
+}
diff --git a/movie-review/src/com/movie/services/ApplicationService.java b/movie-review/src/com/movie/services/ApplicationService.java
new file mode 100644
index 0000000..b6a1b71
--- /dev/null
+++ b/movie-review/src/com/movie/services/ApplicationService.java
@@ -0,0 +1,144 @@
+package com.movie.services;
+
+import com.movie.constants.Constants;
+import com.movie.enums.CategoryType;
+import com.movie.models.Application;
+import com.movie.models.Movie;
+import com.movie.models.Review;
+import com.movie.models.User;
+
+import java.util.Date;
+import java.util.List;
+
+public class ApplicationService {
+ Application application;
+
+ public ApplicationService() {
+ this.application = new Application();
+ }
+
+ public void addUser(String userName) {
+ if (application.getUsers().containsKey(userName)) {
+ System.out.println("User with name : " + userName + " already exist");
+ return;
+ }
+ User user = new User(userName);
+ application.getUsers().put(userName, user);
+ System.out.println("User Created with name : " + userName);
+ }
+
+ public void addMovie(String movieDetails) {
+ String movieName = movieDetails.substring(1, movieDetails.indexOf("\"", 1));
+ if (application.getMovies().containsKey(movieName)) {
+ System.out.println("Movie with name : " + movieName + " already exist");
+ return;
+ }
+ int releaseYear = Integer.parseInt(movieDetails.substring(movieDetails.indexOf(Constants.YEAR) + 6, 4));
+ String genre = movieDetails.substring(movieDetails.indexOf(Constants.GENRE) + 7);
+ int currentYear = new Date().getYear();
+ Movie movie = new Movie(movieName, genre, releaseYear, releaseYear <= currentYear);
+ application.getMovies().put(movieName, movie);
+ System.out.println("Movie Created with name : " + movieName);
+ }
+
+ public void addReview(String userName, String movieName, int rate) {
+ List userReviewIds = application.getUserReview().get(userName);
+
+ for (String userReviewId : userReviewIds) {
+ if (application.getReviews().get(userReviewId).getMovieName().equalsIgnoreCase(movieName)) {
+ System.out.println("Multiple Review Not Allowed");
+ return;
+ }
+ }
+
+
+ List userReview = application.getUserReview().get(userName);
+ if (userReview.size() + 1 > 2) {
+ updateUserCategory(userName, userReview.size() + 1);
+ }
+ if (application.getUsers().get(userName).getCategoryType().equals(CategoryType.CRITIC)) {
+ rate *= 2;
+ } else if (application.getUsers().get(userName).getCategoryType().equals(CategoryType.EXPERT)) {
+ rate *= 3;
+ }
+ Review review = new Review(rate, "", movieName);
+
+ userReview.add(review.getReviewId());
+ application.getUserReview().put(userName, userReview);
+
+ System.out.println("Added Review for Movie : " + movieName + " By User : " + userName);
+ }
+
+ public void updateReview(String userName, String movieName, int rate) {
+ List userReviewIds = application.getUserReview().get(userName);
+ for (String userReviewId : userReviewIds) {
+ if (application.getReviews().get(userReviewId).getMovieName().equalsIgnoreCase(movieName)) {
+ Review review = application.getReviews().get(userReviewId);
+ review.setRate(rate);
+ application.getReviews().put(review.getReviewId(), review);
+ System.out.println("Review Updated for Move : " + movieName + " by User : " + userName);
+ return;
+ }
+ }
+ System.out.println("Review not found with the user and movie");
+ }
+
+ public void deleteReview(String userName, String movieName) {
+ List userReviewIds = application.getUserReview().get(userName);
+ for (int i = 0; i < userReviewIds.size(); i++) {
+ if (application.getReviews().get(userReviewIds.get(i)).getMovieName().equalsIgnoreCase(movieName)) {
+ userReviewIds.remove(i);
+ application.getUserReview().put(userName, userReviewIds);
+ updateUserCategory(userName, userReviewIds.size());
+
+ System.out.println("Review Deleted for Movie : " + movieName + " By User : " + userName);
+ return;
+ }
+ }
+ System.out.println("Not found any review with Movie : " + movieName + " reviewed by User : " + userName);
+ }
+
+ public void listReview(String userName) {
+ List userReviewIds = application.getUserReview().get(userName);
+ StringBuilder displayReview = new StringBuilder("{");
+ for (int i = 0; i < userReviewIds.size(); i++) {
+ Review review = application.getReviews().get(userReviewIds.get(i));
+ displayReview.append("\n\"");
+ displayReview.append(review.getMovieName());
+ displayReview.append("\":");
+ displayReview.append(review.getRate());
+ if (i < userReviewIds.size() - 1) {
+ displayReview.append(",");
+ }
+ }
+ displayReview.append("\n}");
+ System.out.println(new String(displayReview));
+ }
+
+ public void listTopMovie(String movieDetails) {
+
+ }
+
+ public void listTopMovieByYear(int topNMovie, int year) {
+
+ }
+
+ public void listTopMovieByYearAndGenre(int topNMovie, int year, String genre) {
+
+ }
+
+ public void listTopMovieByYearAndUserCategory(int topNMovie, int year, CategoryType categoryType) {
+
+ }
+
+ private void updateUserCategory(String userName, int numberOfReview) {
+ User user = application.getUsers().get(userName);
+ if (numberOfReview < 3) {
+ user.setCategoryType(CategoryType.VIEWER);
+ } else if (numberOfReview < 5) {
+ user.setCategoryType(CategoryType.CRITIC);
+ } else {
+ user.setCategoryType(CategoryType.EXPERT);
+ }
+ }
+}
diff --git a/tic-tac-toe/.idea/.gitignore b/tic-tac-toe/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/tic-tac-toe/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/tic-tac-toe/.idea/misc.xml b/tic-tac-toe/.idea/misc.xml
new file mode 100644
index 0000000..8ed5f34
--- /dev/null
+++ b/tic-tac-toe/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tic-tac-toe/.idea/modules.xml b/tic-tac-toe/.idea/modules.xml
new file mode 100644
index 0000000..80dbae4
--- /dev/null
+++ b/tic-tac-toe/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tic-tac-toe/.idea/vcs.xml b/tic-tac-toe/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/tic-tac-toe/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tic-tac-toe/out/production/tic-tac-toe/com/game/Main.class b/tic-tac-toe/out/production/tic-tac-toe/com/game/Main.class
new file mode 100644
index 0000000..b9335bd
Binary files /dev/null and b/tic-tac-toe/out/production/tic-tac-toe/com/game/Main.class differ
diff --git a/tic-tac-toe/out/production/tic-tac-toe/com/game/constant/Constant.class b/tic-tac-toe/out/production/tic-tac-toe/com/game/constant/Constant.class
new file mode 100644
index 0000000..cf9d17b
Binary files /dev/null and b/tic-tac-toe/out/production/tic-tac-toe/com/game/constant/Constant.class differ
diff --git a/tic-tac-toe/out/production/tic-tac-toe/com/game/model/Board.class b/tic-tac-toe/out/production/tic-tac-toe/com/game/model/Board.class
new file mode 100644
index 0000000..7d75951
Binary files /dev/null and b/tic-tac-toe/out/production/tic-tac-toe/com/game/model/Board.class differ
diff --git a/tic-tac-toe/out/production/tic-tac-toe/com/game/model/Player.class b/tic-tac-toe/out/production/tic-tac-toe/com/game/model/Player.class
new file mode 100644
index 0000000..5f75cc6
Binary files /dev/null and b/tic-tac-toe/out/production/tic-tac-toe/com/game/model/Player.class differ
diff --git a/tic-tac-toe/out/production/tic-tac-toe/com/game/service/BoardService.class b/tic-tac-toe/out/production/tic-tac-toe/com/game/service/BoardService.class
new file mode 100644
index 0000000..f8910a4
Binary files /dev/null and b/tic-tac-toe/out/production/tic-tac-toe/com/game/service/BoardService.class differ
diff --git a/tic-tac-toe/src/com/game/Main.java b/tic-tac-toe/src/com/game/Main.java
index 5bac1c9..0676fa3 100644
--- a/tic-tac-toe/src/com/game/Main.java
+++ b/tic-tac-toe/src/com/game/Main.java
@@ -4,20 +4,20 @@
import com.game.model.Player;
import com.game.service.BoardService;
+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) {
- // write your code here
+ private static void helper(Scanner scanner) {
+ System.out.println("**********************\n New Game Started\n**********************");
BoardService boardService = new BoardService();
List playerList = new ArrayList<>();
- Scanner scanner = new Scanner(System.in);
-
int numberOfPlayer = 0;
while (numberOfPlayer == 0) {
//System.out.println("Enter Number of player");
@@ -33,7 +33,7 @@ public static void main(String[] args) {
String name = scanner.next();
Player player = new Player(name, choice.toUpperCase().charAt(0));
playerList.add(player);
- System.out.println(player.toString());
+ //System.out.println(player.toString());
}
//System.out.println("Enter Board Size");
@@ -66,4 +66,11 @@ public static void main(String[] args) {
}
System.out.println("Game Over");
}
+
+ public static void main(String[] args) throws FileNotFoundException {
+ // write your code here
+ helper(new Scanner(new File(args[0])));
+ helper(new Scanner(new File(args[1])));
+ helper(new Scanner(new File(args[2])));
+ }
}
diff --git a/tic-tac-toe/test/inputFiles/testCase1.txt b/tic-tac-toe/test/inputFiles/testCase1.txt
new file mode 100644
index 0000000..ca3e664
--- /dev/null
+++ b/tic-tac-toe/test/inputFiles/testCase1.txt
@@ -0,0 +1,11 @@
+2
+X Gaurav
+O Sagar
+3
+2 2
+1 3
+1 1
+1 2
+2 2
+3 3
+exit
\ No newline at end of file
diff --git a/tic-tac-toe/test/inputFiles/testCase2.txt b/tic-tac-toe/test/inputFiles/testCase2.txt
new file mode 100644
index 0000000..e61d46d
--- /dev/null
+++ b/tic-tac-toe/test/inputFiles/testCase2.txt
@@ -0,0 +1,14 @@
+2
+X Gaurav
+O Sagar
+3
+2 3
+1 2
+2 2
+2 1
+1 1
+3 3
+3 2
+3 1
+1 3
+exit
\ No newline at end of file
diff --git a/tic-tac-toe/test/inputFiles/testCase3.txt b/tic-tac-toe/test/inputFiles/testCase3.txt
new file mode 100644
index 0000000..a39d2d5
--- /dev/null
+++ b/tic-tac-toe/test/inputFiles/testCase3.txt
@@ -0,0 +1,5 @@
+2
+X Gaurav
+O Sagar
+4
+exit
\ No newline at end of file
diff --git a/tic-tac-toe/tic-tac-toe.iml b/tic-tac-toe/tic-tac-toe.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/tic-tac-toe/tic-tac-toe.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trello/.idea/.gitignore b/trello/.idea/.gitignore
new file mode 100644
index 0000000..1078b7e
--- /dev/null
+++ b/trello/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+#IDE metadata
+**.idea/**
\ No newline at end of file
diff --git a/trello/.idea/compiler.xml b/trello/.idea/compiler.xml
new file mode 100644
index 0000000..a1757ae
--- /dev/null
+++ b/trello/.idea/compiler.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trello/.idea/description.html b/trello/.idea/description.html
new file mode 100644
index 0000000..db5f129
--- /dev/null
+++ b/trello/.idea/description.html
@@ -0,0 +1 @@
+Simple Java application that includes a class with main() method
\ No newline at end of file
diff --git a/trello/.idea/encodings.xml b/trello/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/trello/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trello/.idea/misc.xml b/trello/.idea/misc.xml
new file mode 100644
index 0000000..2fc6c34
--- /dev/null
+++ b/trello/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trello/.idea/modules.xml b/trello/.idea/modules.xml
new file mode 100644
index 0000000..9c3d3dc
--- /dev/null
+++ b/trello/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trello/.idea/project-template.xml b/trello/.idea/project-template.xml
new file mode 100644
index 0000000..1f08b88
--- /dev/null
+++ b/trello/.idea/project-template.xml
@@ -0,0 +1,3 @@
+
+ IJ_BASE_PACKAGE
+
\ No newline at end of file
diff --git a/trello/.idea/vcs.xml b/trello/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/trello/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trello/README.md b/trello/README.md
new file mode 100644
index 0000000..87d1734
--- /dev/null
+++ b/trello/README.md
@@ -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::
+
+
\ No newline at end of file
diff --git a/trello/img.png b/trello/img.png
new file mode 100644
index 0000000..d07a711
Binary files /dev/null and b/trello/img.png differ
diff --git a/trello/out/production/trello/com/trello/Main.class b/trello/out/production/trello/com/trello/Main.class
new file mode 100644
index 0000000..61fed10
Binary files /dev/null and b/trello/out/production/trello/com/trello/Main.class differ
diff --git a/trello/out/production/trello/com/trello/constants/Constants.class b/trello/out/production/trello/com/trello/constants/Constants.class
new file mode 100644
index 0000000..4592c73
Binary files /dev/null and b/trello/out/production/trello/com/trello/constants/Constants.class differ
diff --git a/trello/out/production/trello/com/trello/enums/Access.class b/trello/out/production/trello/com/trello/enums/Access.class
new file mode 100644
index 0000000..49ef601
Binary files /dev/null and b/trello/out/production/trello/com/trello/enums/Access.class differ
diff --git a/trello/out/production/trello/com/trello/models/Application.class b/trello/out/production/trello/com/trello/models/Application.class
new file mode 100644
index 0000000..5a99ba9
Binary files /dev/null and b/trello/out/production/trello/com/trello/models/Application.class differ
diff --git a/trello/out/production/trello/com/trello/models/Board.class b/trello/out/production/trello/com/trello/models/Board.class
new file mode 100644
index 0000000..fc5d734
Binary files /dev/null and b/trello/out/production/trello/com/trello/models/Board.class differ
diff --git a/trello/out/production/trello/com/trello/models/BoardList.class b/trello/out/production/trello/com/trello/models/BoardList.class
new file mode 100644
index 0000000..eee8fd2
Binary files /dev/null and b/trello/out/production/trello/com/trello/models/BoardList.class differ
diff --git a/trello/out/production/trello/com/trello/models/Card.class b/trello/out/production/trello/com/trello/models/Card.class
new file mode 100644
index 0000000..ea64212
Binary files /dev/null and b/trello/out/production/trello/com/trello/models/Card.class differ
diff --git a/trello/out/production/trello/com/trello/models/User.class b/trello/out/production/trello/com/trello/models/User.class
new file mode 100644
index 0000000..7caf404
Binary files /dev/null and b/trello/out/production/trello/com/trello/models/User.class differ
diff --git a/trello/out/production/trello/com/trello/services/ApplicationService.class b/trello/out/production/trello/com/trello/services/ApplicationService.class
new file mode 100644
index 0000000..3ad17cb
Binary files /dev/null and b/trello/out/production/trello/com/trello/services/ApplicationService.class differ
diff --git a/trello/src/com/trello/Main.java b/trello/src/com/trello/Main.java
new file mode 100644
index 0000000..01ee61e
--- /dev/null
+++ b/trello/src/com/trello/Main.java
@@ -0,0 +1,120 @@
+package com.trello;
+
+import com.trello.constants.Constants;
+import com.trello.services.ApplicationService;
+
+import java.util.Scanner;
+
+public class Main {
+
+ public static void main(String[] args) {
+ // write your code here
+ Scanner input = new Scanner(System.in);
+ ApplicationService applicationService = new ApplicationService();
+
+ while(input.hasNextLine()) {
+ String line = input.nextLine().trim();
+ if (line.equalsIgnoreCase("EXIT")) {
+ break;
+ }
+ String[] commands = line.split(" ");
+ int inputLength = commands.length;
+ switch (commands[0].toUpperCase()) {
+ case Constants.SHOW:
+ if (inputLength == 1) {
+ applicationService.showAll();
+ } else if (inputLength >= 3) {
+ switch (commands[1].toUpperCase()) {
+ case Constants.BOARD:
+ applicationService.showBoard(commands[2]);
+ break;
+ case Constants.LIST:
+ applicationService.showList(commands[2]);
+ break;
+ case Constants.CARD:
+ applicationService.showCard(commands[2]);
+ break;
+ default:
+ System.out.println("Invalid Input");
+ break;
+ }
+ }
+ break;
+ case Constants.BOARD:
+ if (inputLength >= 3) {
+ if (commands[1].equalsIgnoreCase(Constants.CREATE)) {
+ applicationService.createBoard(commands[2]);
+ } else if (commands[1].equalsIgnoreCase(Constants.DELETE)) {
+ applicationService.deleteBoard(commands[2]);
+ } else if (commands[2].equalsIgnoreCase(Constants.NAME)) {
+ applicationService.setBoardName(commands[1], commands[3]);
+ } else if (commands[2].equalsIgnoreCase(Constants.PRIVACY)) {
+ applicationService.changeBoardPrivacy(commands[1], commands[3]);
+ } else if (commands[2].equalsIgnoreCase(Constants.ADD_MEMBER)) {
+ applicationService.addMemberToBard(commands[1], commands[3]);
+ } else if (commands[2].equalsIgnoreCase(Constants.REMOVE_MEMBER)) {
+ applicationService.removeUserFromBoard(commands[1], commands[3]);
+ }
+ } else {
+ System.out.println("Invalid Input");
+ }
+ break;
+ case Constants.LIST:
+ if (inputLength > 1) {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int index = 3; index < inputLength; index++) {
+ stringBuilder.append(commands[index]);
+ if (index < inputLength - 1) {
+ stringBuilder.append(' ');
+ }
+ }
+ if (commands[1].equalsIgnoreCase(Constants.CREATE)) {
+ applicationService.createList(commands[2], new String(stringBuilder));
+ } else if (commands[1].equalsIgnoreCase(Constants.DELETE)) {
+ applicationService.deleteList(commands[2]);
+ } else if (commands[2].equalsIgnoreCase(Constants.NAME)) {
+ applicationService.setListName(commands[1], new String(stringBuilder));
+ }
+ } else {
+ System.out.println("Invalid input");
+ }
+ break;
+ case Constants.CARD:
+ if (inputLength > 1) {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int index = 3; index < inputLength; index++) {
+ stringBuilder.append(commands[index]);
+ if (index < inputLength - 1) {
+ stringBuilder.append(' ');
+ }
+ }
+ if (commands[1].equalsIgnoreCase(Constants.CREATE)) {
+ applicationService.createCard(commands[2], new String(stringBuilder));
+ } else if (commands[1].equalsIgnoreCase(Constants.DELETE)) {
+ applicationService.deleteCard(commands[2]);
+ } else if (commands[2].equalsIgnoreCase(Constants.NAME)) {
+ applicationService.setCardName(commands[1], new String(stringBuilder));
+ } else if (commands[2].equalsIgnoreCase(Constants.DESCRIPTION)) {
+ applicationService.setCardDescription(commands[1], new String(stringBuilder));
+ } else if (commands[2].equalsIgnoreCase(Constants.ASSIGN)) {
+ applicationService.assignCardToMember(commands[1], commands[3]);
+ } else if (commands[2].equalsIgnoreCase(Constants.UN_ASSIGN)) {
+ applicationService.unAssignCardToMember(commands[1]);
+ } else if (commands[2].equalsIgnoreCase(Constants.MOVE)) {
+ applicationService.moveCardToDifferentList(commands[1], commands[3]);
+ }
+ }
+ break;
+ case Constants.USER:
+ if (commands[1].equalsIgnoreCase(Constants.CREATE)) {
+ applicationService.createUser(commands[2], commands[3], commands[4]);
+ } else if (commands[1].equalsIgnoreCase(Constants.DELETE)) {
+ applicationService.deleteUser(commands[2]);
+ }
+ break;
+ }
+ }
+
+ input.close();
+ }
+}
diff --git a/trello/src/com/trello/constants/Constants.java b/trello/src/com/trello/constants/Constants.java
new file mode 100644
index 0000000..d6a0e4c
--- /dev/null
+++ b/trello/src/com/trello/constants/Constants.java
@@ -0,0 +1,21 @@
+package com.trello.constants;
+
+public class Constants {
+ public static final String CREATE = "CREATE";
+ public static final String DELETE = "DELETE";
+ public static final String SHOW = "SHOW";
+ public static final String BOARD = "BOARD";
+ public static final String LIST = "LIST";
+ public static final String CARD = "CARD";
+ public static final String MOVE = "MOVE";
+ public static final String PRIVATE = "PRIVATE";
+ public static final String PUBLIC = "PUBLIC";
+ public static final String NAME = "NAME";
+ public static final String PRIVACY = "PRIVACY";
+ public static final String ADD_MEMBER = "ADD_MEMBER";
+ public static final String DESCRIPTION = "DESCRIPTION";
+ public static final String ASSIGN = "ASSIGN";
+ public static final String UN_ASSIGN = "UN_ASSIGN";
+ public static final String USER = "USER";
+ public static final String REMOVE_MEMBER = "REMOVE_MEMBER";
+}
diff --git a/trello/src/com/trello/enums/Access.java b/trello/src/com/trello/enums/Access.java
new file mode 100644
index 0000000..704b607
--- /dev/null
+++ b/trello/src/com/trello/enums/Access.java
@@ -0,0 +1,6 @@
+package com.trello.enums;
+
+public enum Access {
+ PRIVATE,
+ PUBLIC
+}
diff --git a/trello/src/com/trello/models/Application.java b/trello/src/com/trello/models/Application.java
new file mode 100644
index 0000000..59a89c9
--- /dev/null
+++ b/trello/src/com/trello/models/Application.java
@@ -0,0 +1,20 @@
+package com.trello.models;
+
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public @Data class Application {
+ private Map boards;
+ private Map users;
+ private Map lists;
+ private Map cards;
+
+ public Application() {
+ this.boards = new HashMap<>();
+ this.users = new HashMap<>();
+ this.lists = new HashMap<>();
+ this.cards = new HashMap<>();
+ }
+}
diff --git a/trello/src/com/trello/models/Board.java b/trello/src/com/trello/models/Board.java
new file mode 100644
index 0000000..ac98b4f
--- /dev/null
+++ b/trello/src/com/trello/models/Board.java
@@ -0,0 +1,60 @@
+package com.trello.models;
+
+import com.trello.enums.Access;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public @Data
+class Board {
+ private String boardId;
+ private String boardName;
+ private Access privacy;
+ private List users;
+ private List boardLists;
+
+ public Board(String boardName) {
+ this.boardId = UUID.randomUUID().toString();
+ this.boardName = boardName;
+ this.privacy = Access.PUBLIC;
+ this.users = new ArrayList<>();
+ this.boardLists = new ArrayList<>();
+ }
+
+ public void removeList(BoardList boardList) {
+ this.boardLists.remove(boardList);
+ }
+
+ public void addList(BoardList boardList) {
+ this.boardLists.add(boardList);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder displayString = new StringBuilder("{ id : " + boardId + ", name : " + boardName + ", privacy : " + privacy);
+ if (boardLists.size() > 0) {
+ displayString.append(", lists: [");
+ for (int index = 0; index < boardLists.size(); index++) {
+ displayString.append(boardLists.get(index));
+ if (index < boardLists.size() - 1) {
+ displayString.append(", ");
+ }
+ }
+ displayString.append("]");
+ }
+ if (users.size() > 0) {
+ displayString.append(", members : [");
+ for (int index = 0; index < users.size(); index++) {
+ displayString.append(users.get(index));
+ if (index < users.size() - 1) {
+ displayString.append(", ");
+ }
+ }
+ displayString.append("]");
+ }
+ displayString.append(" }");
+ return new String(displayString);
+ }
+}
diff --git a/trello/src/com/trello/models/BoardList.java b/trello/src/com/trello/models/BoardList.java
new file mode 100644
index 0000000..9d759ff
--- /dev/null
+++ b/trello/src/com/trello/models/BoardList.java
@@ -0,0 +1,45 @@
+package com.trello.models;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public @Data class BoardList {
+ private String boardListId;
+ private String boardListName;
+ private List cards;
+ private Board board;
+
+ public BoardList(String boardListName, Board board) {
+ this.boardListId = UUID.randomUUID().toString();
+ this.boardListName = boardListName;
+ this.cards = new ArrayList<>();
+ this.board = board;
+ }
+
+ public void removeCard(Card card) {
+ this.cards.remove(card);
+ }
+ public void addCard(Card card) {
+ this.cards.add(card);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder displayString = new StringBuilder("{ id : " + boardListId + ", name : " + boardListName);
+ if (cards.size() > 0) {
+ displayString.append(", cards : [");
+ for (int index = 0; index < cards.size(); index++) {
+ displayString.append(cards.get(index));
+ if (index < cards.size() - 1) {
+ displayString.append(", ");
+ }
+ }
+ displayString.append("]");
+ }
+ displayString.append(" }");
+ return new String(displayString);
+ }
+}
diff --git a/trello/src/com/trello/models/Card.java b/trello/src/com/trello/models/Card.java
new file mode 100644
index 0000000..80b91bd
--- /dev/null
+++ b/trello/src/com/trello/models/Card.java
@@ -0,0 +1,32 @@
+package com.trello.models;
+
+import lombok.Data;
+
+import java.util.UUID;
+
+public @Data class Card {
+ private String cardId;
+ private String cardName;
+ private String cardDescription;
+ private User assignee;
+ private BoardList boardList;
+
+ public Card(String cardName, BoardList boardList) {
+ this.cardId = UUID.randomUUID().toString();
+ this.cardName = cardName;
+ this.boardList = boardList;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder displayString = new StringBuilder("{ id : " + cardId + ", name : " + cardName);
+ if (cardDescription != null && cardDescription.length() > 0) {
+ displayString.append(", description : ").append(cardDescription);
+ }
+ if (assignee != null) {
+ displayString.append(", assignTo : ").append(assignee.getUserEmail());
+ }
+ displayString.append(" }");
+ return new String(displayString);
+ }
+}
diff --git a/trello/src/com/trello/models/User.java b/trello/src/com/trello/models/User.java
new file mode 100644
index 0000000..897e7f2
--- /dev/null
+++ b/trello/src/com/trello/models/User.java
@@ -0,0 +1,21 @@
+package com.trello.models;
+
+import lombok.Data;
+
+public @Data
+class User {
+ private String userId;
+ private String userName;
+ private String userEmail;
+
+ public User(String userId, String userName, String userEmail) {
+ this.userId = userId;
+ this.userName = userName;
+ this.userEmail = userEmail;
+ }
+
+ @Override
+ public String toString() {
+ return "{ id : " + userId + ", name : " + userName + ", email: " + userEmail + " }";
+ }
+}
diff --git a/trello/src/com/trello/services/ApplicationService.java b/trello/src/com/trello/services/ApplicationService.java
new file mode 100644
index 0000000..b44c012
--- /dev/null
+++ b/trello/src/com/trello/services/ApplicationService.java
@@ -0,0 +1,245 @@
+package com.trello.services;
+
+import com.trello.constants.Constants;
+import com.trello.enums.Access;
+import com.trello.models.*;
+
+import java.util.Map;
+
+public class ApplicationService {
+ private final Application application;
+
+ public ApplicationService() {
+ this.application = new Application();
+ }
+
+ public void createBoard(String boardName) {
+ Board board = new Board(boardName);
+ application.getBoards().put(board.getBoardId(), board);
+ System.out.println("Created board: " + board.getBoardId());
+ }
+
+ public void deleteBoard(String boardId) {
+ if (!application.getBoards().containsKey(boardId)) {
+ System.out.println("The Board which you are trying to delete doesn't exit");
+ return;
+ }
+ Board boardToDelete = application.getBoards().get(boardId);
+ for (int index = 0; index < boardToDelete.getBoardLists().size(); index++) {
+ deleteList(boardToDelete.getBoardLists().get(index).getBoardListId());
+ }
+ application.getBoards().remove(boardId);
+ }
+
+ public void setBoardName(String boardId, String boardName) {
+ if (!application.getBoards().containsKey(boardId)) {
+ System.out.println("The Board which you are trying to rename doesn't exit");
+ return;
+ }
+ application.getBoards().get(boardId).setBoardName(boardName);
+ }
+
+ public void changeBoardPrivacy(String boardId, String privacy) {
+ if (!application.getBoards().containsKey(boardId)) {
+ System.out.println("The Board which you are trying to edit doesn't exit");
+ return;
+ }
+ if (privacy.equalsIgnoreCase(Constants.PRIVATE)) {
+ application.getBoards().get(boardId).setPrivacy(Access.PRIVATE);
+ } else if (privacy.equalsIgnoreCase(Constants.PUBLIC)) {
+ application.getBoards().get(boardId).setPrivacy(Access.PUBLIC);
+ }
+ }
+
+ public void addMemberToBard(String boardId, String email) {
+ if (!application.getBoards().containsKey(boardId)) {
+ System.out.println("The Board which you are trying to edit doesn't exit");
+ return;
+ }
+ if (!application.getUsers().containsKey(email)) {
+ System.out.println("The User which you are trying to add doesn't exit");
+ return;
+ }
+ User user = application.getUsers().get(email);
+ application.getBoards().get(boardId).getUsers().add(user);
+ }
+
+ public void removeUserFromBoard(String boardId, String email) {
+ if (!application.getBoards().containsKey(boardId)) {
+ System.out.println("The Board which you are trying to edit doesn't exit");
+ return;
+ }
+ if (!application.getUsers().containsKey(email)) {
+ System.out.println("The User which you are trying to add doesn't exit");
+ return;
+ }
+ User user = application.getUsers().get(email);
+ application.getBoards().get(boardId).getUsers().remove(user);
+ }
+
+ public void showBoard(String boardId) {
+ if (!application.getBoards().containsKey(boardId)) {
+ System.out.println("The Board which you are trying to print doesn't exit");
+ return;
+ }
+ System.out.println(application.getBoards().get(boardId));
+ }
+
+ public void createList(String boardId, String name) {
+ if (!application.getBoards().containsKey(boardId)) {
+ System.out.println("The Board where you are trying to add list doesn't exit");
+ return;
+ }
+ BoardList newList = new BoardList(name, application.getBoards().get(boardId));
+
+ application.getBoards().get(boardId).addList(newList);
+ application.getLists().put(newList.getBoardListId(), newList);
+ System.out.println("Created List: " + newList.getBoardListId());
+ }
+
+ public void deleteList(String boardListId) {
+ if (!application.getLists().containsKey(boardListId)) {
+ System.out.println("The List you are trying to delete doesn't exits");
+ return;
+ }
+ BoardList listToDelete = application.getLists().get(boardListId);
+ while (listToDelete.getCards() != null && listToDelete.getCards().size() > 0) {
+ deleteCard(listToDelete.getCards().get(0).getCardId());
+ }
+ application.getBoards().get(listToDelete.getBoard().getBoardId()).removeList(listToDelete);
+ application.getLists().remove(boardListId);
+ }
+
+ public void setListName(String boardListId, String listName) {
+ if (!application.getLists().containsKey(boardListId)) {
+ System.out.println("The List you are trying to edit doesn't exits");
+ return;
+ }
+
+ application.getLists().get(boardListId).setBoardListName(listName);
+ }
+
+ public void showList(String boardListId) {
+ if (!application.getLists().containsKey(boardListId)) {
+ System.out.println("The List you are trying to print doesn't exits");
+ return;
+ }
+ System.out.println(application.getLists().get(boardListId));
+ }
+
+ public void createCard(String boardListId, String cardName) {
+ if (!application.getLists().containsKey(boardListId)) {
+ System.out.println("The List you are trying to add card doesn't exits");
+ return;
+ }
+
+ Card newCard = new Card(cardName, application.getLists().get(boardListId));
+ application.getLists().get(boardListId).addCard(newCard);
+ application.getCards().put(newCard.getCardId(), newCard);
+ System.out.println("Created Card: + " + newCard.getCardId());
+ }
+
+ public void deleteCard(String cardId) {
+ if (!application.getCards().containsKey(cardId)) {
+ System.out.println("The Card you are trying to delete doesn't exist");
+ return;
+ }
+ Card cardToDelete = application.getCards().get(cardId);
+ application.getLists().get(cardToDelete.getBoardList().getBoardListId()).removeCard(cardToDelete);
+ application.getCards().remove(cardId);
+
+ }
+
+ public void assignCardToMember(String cardId, String email) {
+ if (!application.getCards().containsKey(cardId)) {
+ System.out.println("The card which you are trying ot assign doesn't exist");
+ return;
+ }
+ if (!application.getUsers().containsKey(email)) {
+ System.out.println("The user is not exist");
+ return;
+ }
+ application.getCards().get(cardId).setAssignee(application.getUsers().get(email));
+ }
+
+ public void unAssignCardToMember(String cardId) {
+ if (!application.getCards().containsKey(cardId)) {
+ System.out.println("The card which you are trying ot unAssign doesn't exist");
+ return;
+ }
+ application.getCards().get(cardId).setAssignee(null);
+ }
+
+ public void setCardName(String cardId, String cardName) {
+ if (!application.getCards().containsKey(cardId)) {
+ System.out.println("The card which you are trying to edit doesn't exist");
+ return;
+ }
+ application.getCards().get(cardId).setCardName(cardName);
+ }
+
+ public void setCardDescription(String cardId, String cardDescription) {
+ if (!application.getCards().containsKey(cardId)) {
+ System.out.println("The card which you are trying to edit doesn't exist");
+ return;
+ }
+ application.getCards().get(cardId).setCardDescription(cardDescription);
+ }
+
+ public void moveCardToDifferentList(String cardId, String boardListId) {
+ if (!application.getCards().containsKey(cardId)) {
+ System.out.println("The card which you are trying to edit doesn't exist");
+ return;
+ }
+ if (!application.getLists().containsKey(boardListId)) {
+ System.out.println("The board which you are trying to edit doesn't exist");
+ return;
+ }
+ Card card = application.getCards().get(cardId);
+ BoardList parentList = card.getBoardList();
+ if (parentList.getBoard().equals(application.getLists().get(boardListId).getBoard())) {
+ parentList.getCards().remove(card);
+ application.getLists().get(boardListId).addCard(card);
+ card.setBoardList(application.getLists().get(boardListId));
+ } else {
+ System.out.println("The List Id which you provided is not the same board");
+ }
+
+ }
+
+ public void showCard(String cardId) {
+ if (!application.getCards().containsKey(cardId)) {
+ System.out.println("The card which you are trying to print doesn't exist");
+ return;
+ }
+ System.out.println(application.getCards().get(cardId));
+ }
+
+ public void showAll() {
+ if (application.getBoards().isEmpty()) {
+ System.out.println("No Board");
+ return;
+ }
+ StringBuilder displayString = new StringBuilder("[ ");
+ for (Map.Entry board : application.getBoards().entrySet()) {
+ displayString.append(board.getValue());
+ displayString.append(", ");
+ }
+ displayString.deleteCharAt(displayString.length()-2);
+ displayString.append("]");
+ System.out.println(new String(displayString));
+ }
+
+ public void createUser(String userId, String name, String email) {
+ User user = new User(userId, name, email);
+ application.getUsers().put(email, user);
+ System.out.println("Created User: " + user.getUserId());
+ }
+ public void deleteUser(String email) {
+ if (!application.getUsers().containsKey(email)) {
+ System.out.println("The User you trying to delete doesn't exist");
+ return;
+ }
+ application.getUsers().remove(email);
+ }
+}
diff --git a/trello/trello.iml b/trello/trello.iml
new file mode 100644
index 0000000..6b762ae
--- /dev/null
+++ b/trello/trello.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file