diff --git a/OOP Tasks/OnlineShopping/.gitignore b/OOP Tasks/OnlineShopping/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOP Tasks/OnlineShopping/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOP Tasks/OnlineShopping/.idea/.gitignore b/OOP Tasks/OnlineShopping/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOP Tasks/OnlineShopping/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOP Tasks/OnlineShopping/.idea/misc.xml b/OOP Tasks/OnlineShopping/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/OOP Tasks/OnlineShopping/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOP Tasks/OnlineShopping/.idea/modules.xml b/OOP Tasks/OnlineShopping/.idea/modules.xml new file mode 100644 index 0000000..683b2a9 --- /dev/null +++ b/OOP Tasks/OnlineShopping/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOP Tasks/OnlineShopping/.idea/vcs.xml b/OOP Tasks/OnlineShopping/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/OOP Tasks/OnlineShopping/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOP Tasks/OnlineShopping/OnlineShopping.iml b/OOP Tasks/OnlineShopping/OnlineShopping.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOP Tasks/OnlineShopping/OnlineShopping.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOP Tasks/OnlineShopping/src/Main.java b/OOP Tasks/OnlineShopping/src/Main.java new file mode 100644 index 0000000..9c37ee1 --- /dev/null +++ b/OOP Tasks/OnlineShopping/src/Main.java @@ -0,0 +1,21 @@ +public class Main { + public static void main(String[] args) { + // Add Products + Product product1 = new Product("Shoes",60); // change productPrice to positive number to the make the system works. + Product product2 = new Product(null,1000.6); // change productName to string to the make the system works. + Product product3 = new Product("Dress",1000.33); + Product product4 = new Product("Trousers",1000.5); + + // Add Products to Shopping Cart + ShoppingCart cart1 = new ShoppingCart(); + cart1.addItem(product1); + cart1.addItem(product4); + + // Display Total Cost + cart1.calculateTotalCost(); + + // Print Order + OrderProcessor order = new OrderProcessor(); + order.placeOrder(cart1); + } +} \ No newline at end of file diff --git a/OOP Tasks/OnlineShopping/src/OrderProcessor.java b/OOP Tasks/OnlineShopping/src/OrderProcessor.java new file mode 100644 index 0000000..7a9c114 --- /dev/null +++ b/OOP Tasks/OnlineShopping/src/OrderProcessor.java @@ -0,0 +1,8 @@ +public class OrderProcessor{ + public OrderProcessor(){ + } + public void placeOrder(ShoppingCart cart){ + cart.printItems(); + cart.calculateTotalCost(); + } +} diff --git a/OOP Tasks/OnlineShopping/src/Product.java b/OOP Tasks/OnlineShopping/src/Product.java new file mode 100644 index 0000000..82f9497 --- /dev/null +++ b/OOP Tasks/OnlineShopping/src/Product.java @@ -0,0 +1,30 @@ +public class Product { + private String productName; + private double productPrice; + + public Product(String productName, double productPrice) { + try{ + if (productPrice < 0) throw new RuntimeException(); + } + catch (RuntimeException e) { + System.out.println("Product Price cannot be less than 0"); + System.exit(0); + } + try{ + if (productName.isEmpty() || productName == null) throw new RuntimeException(); + } + catch (RuntimeException e) { + System.out.println("Product Name can't be empty or null"); + System.exit(0); + } + if (!productName.isEmpty() && productName != null) this.productName = productName; + if(productPrice > 0) this.productPrice = productPrice; + } + + public String getProductName() { + return productName; + } + public double getProductPrice() { + return productPrice; + } +} diff --git a/OOP Tasks/OnlineShopping/src/ShoppingCart.java b/OOP Tasks/OnlineShopping/src/ShoppingCart.java new file mode 100644 index 0000000..10744a3 --- /dev/null +++ b/OOP Tasks/OnlineShopping/src/ShoppingCart.java @@ -0,0 +1,29 @@ +import java.util.ArrayList; + +public class ShoppingCart { + ArrayList cart; + public ShoppingCart() { + this.cart = new ArrayList<>(); + } + protected void addItem(Product product){ + cart.add(product); + } + protected void removeItem(Product product){ + cart.remove(product); + } + protected void retrieveItem(){ + + + } + protected void calculateTotalCost(){ + float totalCost = 0; + for (Product p: cart) totalCost += p.getProductPrice(); + System.out.println("The Total Cost is " + totalCost); + + } + protected void printItems(){ + System.out.println("The Order: "); + for(Product c:cart) + System.out.println("product name: " + c.getProductName() + " price: " + c.getProductPrice()); + } +} diff --git a/OOP Tasks/Word Count/.gitignore b/OOP Tasks/Word Count/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOP Tasks/Word Count/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOP Tasks/Word Count/.idea/.gitignore b/OOP Tasks/Word Count/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/OOP Tasks/Word Count/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/OOP Tasks/Word Count/.idea/misc.xml b/OOP Tasks/Word Count/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/OOP Tasks/Word Count/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOP Tasks/Word Count/.idea/modules.xml b/OOP Tasks/Word Count/.idea/modules.xml new file mode 100644 index 0000000..300f29f --- /dev/null +++ b/OOP Tasks/Word Count/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOP Tasks/Word Count/.idea/vcs.xml b/OOP Tasks/Word Count/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/OOP Tasks/Word Count/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOP Tasks/Word Count/Lincoln.txt b/OOP Tasks/Word Count/Lincoln.txt new file mode 100644 index 0000000..e07ecc7 --- /dev/null +++ b/OOP Tasks/Word Count/Lincoln.txt @@ -0,0 +1,4 @@ +Java is /a -programming ,language. +Java is _easy. +the file contains 8 + diff --git a/OOP Tasks/Word Count/Task 2-Word Count.iml b/OOP Tasks/Word Count/Task 2-Word Count.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOP Tasks/Word Count/Task 2-Word Count.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOP Tasks/Word Count/src/Main.java b/OOP Tasks/Word Count/src/Main.java new file mode 100644 index 0000000..6d67607 --- /dev/null +++ b/OOP Tasks/Word Count/src/Main.java @@ -0,0 +1,28 @@ +import java.io.*; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + try { + File file = new File("Lincoln.txt"); + Scanner scanner = new Scanner(file); + int count = 0; + while (scanner.hasNext()) { + scanner.next(); + count++; + } + scanner.close(); + + BufferedWriter writer = new BufferedWriter(new FileWriter(file, true)); + String str = "the file contains " + count + '\n'; + writer.write(str); + writer.newLine(); + writer.close(); + + } catch (FileNotFoundException e) { + System.out.println(e.getMessage()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +}