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 Java8 Tasks/Product/.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 Java8 Tasks/Product/.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 Java8 Tasks/Product/.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 Java8 Tasks/Product/.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 Java8 Tasks/Product/.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 Java8 Tasks/Product/Products.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>
16 changes: 16 additions & 0 deletions Java8 Tasks/Product/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Main {
public static void main(String[] args) {
Product product = new Product();
// exercise 1
System.out.println(product.getBookCategory());

// exercise 2
System.out.println(product.getBooksWithPriceLessThan100());

// exercise 3
System.out.println(product.getToyCategory());

// exercise 4
System.out.println(product.getCheapestBook());
}
}
136 changes: 136 additions & 0 deletions Java8 Tasks/Product/src/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import javafx.print.Collation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Product {
private int productId;
private String productName, category;
private double productPrice;

public Product() {}
public Product(int productId, String productName, String category, double productPrice) {
this.productId = productId;
this.productPrice = productPrice;
this.productName = productName;
this.category = category;
}

public int getProductId() {
return productId;
}

public void setProductId(int productId) {
this.productId = productId;
}

public String getProductName() {
return productName;
}

public void setProductName(String productName) {
this.productName = productName;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public double getProductPrice() {
return productPrice;
}

public void setProductPrice(double productPrice) {
this.productPrice = productPrice;
}

@Override
public String toString() {
return "Product{" +
"productId=" + productId +
", productName='" + productName + '\'' +
", category='" + category + '\'' +
", productPrice=" + productPrice +
'}';
}
public Product withPrice(int id, String name, String category, double price){
if(price == this.productPrice) return this;
else return new Product(id,name,category, price);
}

public List<Product> addDummyData(){
List<Product> products = new ArrayList<>();
Collections.addAll(products,
new Product(1, "omnis quod consequatur", "Games", 184.83),
new Product(2, "vel libero suscipit", "Toys", 12.66),
new Product(3, "non nemo iure", "Grocery", 498.02),
new Product(4, "voluptatem voluptas aspernatur", "Toys", 536.80),
new Product(5, "animi cum rem", "Games", 458.20),
new Product(6, "dolorem porro debitis", "Toys", 146.52),
new Product(7, "aspernatur rerum qui", "Books", 656.42),
new Product(8, "deleniti earum et", "Baby", 41.46),
new Product(9, "voluptas ut quidem", "Books", 697.57),
new Product(10, "eos sed debitis", "Baby", 366.90),
new Product(11, "laudantium sit nihil", "Toys", 95.50),
new Product(12, "ut perferendis corporis", "Grocery", 302.19),
new Product(13, "sint voluptatem ut", "Toys", 295.37),
new Product(14, "quos sunt ipsam", "Grocery", 534.64),
new Product(15, "qui illo error", "Baby", 623.58),
new Product(16, "aut ex ducimus", "Books", 551.39),
new Product(17, "accusamus repellendus minus", "Books", 240.58),
new Product(18, "aut accusamus quia", "Baby", 881.38),
new Product(19, "doloremque incidunt sed", "Games", 988.49),
new Product(20, "libero omnis velit", "Baby", 177.61),
new Product(21, "consectetur cupiditate sunt", "Toys", 95.46),
new Product(22, "itaque ea qui", "Baby", 677.78),
new Product(23, "non et nulla", "Grocery", 70.49),
new Product(24, "veniam consequatur et", "Books", 893.44),
new Product(25, "magnam adipisci voluptate", "Grocery", 366.13),
new Product(26, "reiciendis consequuntur placeat", "Toys", 359.27),
new Product(27, "dolores ipsum sit", "Toys", 786.99),
new Product(28, "ut hic tempore", "Toys", 316.09),
new Product(29, "quas quis deserunt", "Toys", 772.78),
new Product(30, "excepturi nesciunt accusantium", "Toys", 911.46)
);
return products;
}

public List<Product> getBookCategory(){
List <Product> books = new ArrayList<>();
for(Product p : addDummyData())
if(p.category.equals("Books") )
books.add(p);
return books;
}

public List<Product> getBooksWithPriceLessThan100(){
List <Product> books = new ArrayList<>();
for(Product p : addDummyData())
if(p.productPrice < 100 )
books.add(p);
return books;
}
public List<Product> getToyCategory(){
List <Product> books = new ArrayList<>();
for(Product p : addDummyData())
if(p.category.equals("Toys")){
// apply 10% discount
p.productPrice = p.productPrice * (10/100);
books.add(p);
}
return books;
}

public double getCheapestBook(){
List <Double> prices = new ArrayList<>();
for(Product p : getBookCategory())
prices.add(p.productPrice);
return Collections.min(prices);
}

}