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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions OOP Tasks/OnlineShopping/.gitignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions OOP Tasks/OnlineShopping/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions OOP Tasks/OnlineShopping/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions OOP Tasks/OnlineShopping/.idea/modules.xml

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

6 changes: 6 additions & 0 deletions OOP Tasks/OnlineShopping/.idea/vcs.xml

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

11 changes: 11 additions & 0 deletions OOP Tasks/OnlineShopping/OnlineShopping.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
21 changes: 21 additions & 0 deletions OOP Tasks/OnlineShopping/src/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
8 changes: 8 additions & 0 deletions OOP Tasks/OnlineShopping/src/OrderProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class OrderProcessor{
public OrderProcessor(){
}
public void placeOrder(ShoppingCart cart){
cart.printItems();
cart.calculateTotalCost();
}
}
30 changes: 30 additions & 0 deletions OOP Tasks/OnlineShopping/src/Product.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
29 changes: 29 additions & 0 deletions OOP Tasks/OnlineShopping/src/ShoppingCart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.ArrayList;

public class ShoppingCart {
ArrayList<Product> 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());
}
}
29 changes: 29 additions & 0 deletions OOP Tasks/Word Count/.gitignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions OOP Tasks/Word Count/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions OOP Tasks/Word Count/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions OOP Tasks/Word Count/.idea/modules.xml

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

6 changes: 6 additions & 0 deletions OOP Tasks/Word Count/.idea/vcs.xml

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

4 changes: 4 additions & 0 deletions OOP Tasks/Word Count/Lincoln.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Java is /a -programming ,language.
Java is _easy.
the file contains 8

11 changes: 11 additions & 0 deletions OOP Tasks/Word Count/Task 2-Word Count.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
28 changes: 28 additions & 0 deletions OOP Tasks/Word Count/src/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}