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
34 changes: 33 additions & 1 deletion task-1/com/pizzacompany/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
package com.pizzacompany;


import com.pizzacompany.enums.Size;
import com.pizzacompany.enums.Topping;
import com.pizzacompany.model.Order;
import com.pizzacompany.model.Pizza;

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

public class Main {
public static void main(String[] args) {
System.out.println("Hello Pizza!");
Order order = new Order();

List<Topping> toppingsFirstPizza = new ArrayList<>();
toppingsFirstPizza.add(Topping.CHEESE);
toppingsFirstPizza.add(Topping.MUSHROOMS);

Pizza pizza1 = new Pizza(Size.MEDIUM, toppingsFirstPizza);
order.addPizza(pizza1);

List<Topping> toppingsSecondPizza = new ArrayList<>();
toppingsSecondPizza.add(Topping.PINEAPPLE);
toppingsSecondPizza.add(Topping.OLIVES);
toppingsSecondPizza.add(Topping.CHEESE);

Pizza pizza2 = new Pizza(Size.LARGE, toppingsSecondPizza);
order.addPizza(pizza2);

List<Topping> toppingsThirdPizza = new ArrayList<>();
toppingsThirdPizza.add(Topping.PINEAPPLE);

Pizza pizza3 = new Pizza(Size.SMALL, toppingsThirdPizza);
order.addPizza(pizza3);

order.printReceipt();
}
}
18 changes: 18 additions & 0 deletions task-1/com/pizzacompany/enums/Size.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.pizzacompany.enums;

public enum Size {
SMALL(6),
MEDIUM(9),
LARGE(12)
;

private final Integer price;

Size(int price) {
this.price = price;
}

public Integer getBasePrice(){
return price;
}
}
19 changes: 19 additions & 0 deletions task-1/com/pizzacompany/enums/Topping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pizzacompany.enums;

public enum Topping {
CHEESE(1.00),
MUSHROOMS(1.50),
PEPPERONI(2.00),
OLIVES(1.00),
PINEAPPLE(1.50);

private final double price;

Topping(double price) {
this.price = price;
}

public double getPrice() {
return price;
}
}
35 changes: 35 additions & 0 deletions task-1/com/pizzacompany/model/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.pizzacompany.model;

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

public class Order {
List<Pizza> pizzas;

public Order() {
this.pizzas = new ArrayList<>();
}

public void addPizza(Pizza pizza) {
pizzas.add(pizza);
}

public double getTotalPrice() {
double total = 0;
for (Pizza pizza : pizzas) {
total += pizza.getTotalPrice();
}
return total;
}

public void printReceipt(){
System.out.println("=== Receipt ===");

for (Pizza pizza : pizzas) {
System.out.println(pizza);
}

System.out.println("---------------");
System.out.println("Total: €" + String.format("€%.2f", getTotalPrice()));
}
}
41 changes: 41 additions & 0 deletions task-1/com/pizzacompany/model/Pizza.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.pizzacompany.model;

import com.pizzacompany.enums.Size;
import com.pizzacompany.enums.Topping;

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

public class Pizza {
private final Size size;
private List<Topping> toppingList = new ArrayList<>();

public Pizza(Size size, List<Topping> toppingList) {
this.size = size;
this.toppingList = toppingList;
}

public List<Topping> getToppingList() {
return toppingList;
}

public Size getSize() {
return size;
}

public double getTotalPrice(){
double totalPrice = 0;
for (Topping topping : toppingList) {
totalPrice += topping.getPrice();
}
totalPrice += size.getBasePrice();
return totalPrice;
}

@Override
public String toString() {
// MEDIUM pizza with [CHEESE, MUSHROOMS] - €11.50
return size + " pizza with " + toppingList + " - €" + String.format(" - €%.2f", getTotalPrice());
}

}
16 changes: 11 additions & 5 deletions task-2/src/main/java/org/my/cache/Cache.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package org.my.cache;

import java.util.HashMap;
import java.util.Map;

class Cache<T> {

private Map<String, T> cash = new HashMap<>();

public void put(String key, T value) {
throw new UnsupportedOperationException("Not implemented yet");
cash.put(key, value);
}

public T get(String key) {
throw new UnsupportedOperationException("Not implemented yet");
return cash.get(key);
}

public T remove(String key) {
throw new UnsupportedOperationException("Not implemented yet");
return cash.remove(key);
}

public int size() {
throw new UnsupportedOperationException("Not implemented yet");
return cash.size();
}

public void clear() {
throw new UnsupportedOperationException("Not implemented yet");
cash.clear();
}

}
14 changes: 13 additions & 1 deletion task-2/src/main/java/org/my/cache/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

public class Main {
public static void main(String[] args) {
System.out.println("Hello Cache!");
Cache<String> stringCache = new Cache<String>();
stringCache.put("name", "HackYourFuture");
System.out.println(stringCache.get("name")); // -> "HackYourFuture"
System.out.println(stringCache.get("city")); // -> null

Cache<Double> numberCache = new Cache<Double>();
numberCache.put("c1", 15.25);
numberCache.put("c2", 20.25);
numberCache.put("c3", 31.77);
System.out.println(numberCache.size()); // -> 3
System.out.println(numberCache.get("c1")); // -> 15.25
numberCache.remove("c1");
System.out.println(numberCache.get("c1")); // -> null
}
}
60 changes: 58 additions & 2 deletions task-2/src/test/java/org/my/cache/CacheTests.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
package org.my.cache;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class CacheTests {

// Arrange
private Cache<String> cache;
@BeforeEach
void setUp() {
cache = new Cache<String>();
}


@Test
void putIncreasesSize() {
// Act
cache.put("name", "Salem");

// Assert
assertEquals(1, cache.size());
}


@Test
void simpleTest() {
assertEquals(2, 1 + 1);
void getItemNotExist() {
// Act
cache.put("City", "Amsterdam");

// Assert
assertNull(cache.get("Age"));
}


@Test
void removeItem() {
// Act
cache.put("City", "Amsterdam");
cache.remove("City");

// Assert
assertEquals(0, cache.size());
}


@Test
void returnSizeArray() {
// Act
cache.put("City", "Amsterdam");
cache.put("Name", "Ali");

// Assert
assertEquals(2, cache.size());
}

@Test
void emptyArray() {
// Act
cache.put("City", "Amsterdam");
cache.put("Name", "Ali");
cache.clear();
// Assert
assertEquals(0, cache.size());
}

}