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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ dist
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

target
target
*.class
19 changes: 18 additions & 1 deletion task-1/com/pizzacompany/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package com.pizzacompany;

import java.util.List;

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

Order myOrder = new Order();

Pizza pizza1 = new Pizza(Size.MEDIUM, List.of(Topping.CHEESE, Topping.MUSHROOMS));
myOrder.addPizza(pizza1);


Pizza pizza2 = new Pizza(Size.LARGE, List.of(Topping.PEPPERONI, Topping.OLIVES, Topping.CHEESE));
myOrder.addPizza(pizza2);


Pizza pizza3 = new Pizza(Size.SMALL, List.of(Topping.PINEAPPLE));
myOrder.addPizza(pizza3);


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

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

public class Order {

private List<Pizza> pizzas = new ArrayList<>();

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

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

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()));
}
}
25 changes: 25 additions & 0 deletions task-1/com/pizzacompany/Pizza.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.pizzacompany;

import java.util.List;

public class Pizza {
private Size size;
private List<Topping> toppings;

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

public double getTotalPrice(){
double total = size.getBasePrice();
for (Topping topping : toppings){
total += topping.getPrice();
}
return total;
}
@Override
public String toString(){
return size + " pizza with " + toppings + " -$" + String.format("%.2f", getTotalPrice());
}
}
14 changes: 14 additions & 0 deletions task-1/com/pizzacompany/Size.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pizzacompany;

public enum Size{
SMALL(6.00), MEDIUM(9.00), LARGE(12.00);
private final double basePrice;

Size(double basePrice){
this.basePrice = basePrice;
}

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

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;
}

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

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

class Cache<T> {
private final Map<String, T> storage = new HashMap<>();

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

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

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

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

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

}
}
24 changes: 23 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,28 @@

public class Main {
public static void main(String[] args) {
System.out.println("Hello Cache!");


System.out.println(" Hello Cache!");

Cache<String> stringCache = new Cache<String>();

stringCache.put("name", "Daniel");
System.out.println(stringCache.get("name"));
System.out.println(stringCache.get("city"));

System.out.println();


Cache<Integer> numberCache = new Cache<Integer>();
numberCache.put("Tata", 6757575);
numberCache.put("Paul", 7878787);

System.out.println(numberCache.size());
numberCache.remove("Tata");
System.out.println(numberCache.get("Tata"));



}
}
43 changes: 42 additions & 1 deletion task-2/src/test/java/org/my/cache/CacheTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,45 @@ class CacheTests {
void simpleTest() {
assertEquals(2, 1 + 1);
}
}

@Test
void putAndGetReturnsValue() {
Cache<String> stringCache = new Cache<>();
stringCache.put("name", "Daniel");
assertEquals("Daniel", stringCache.get("name"));
}

@Test
void getMissingReturnsNull() {
Cache<String> stringCache = new Cache<>();
assertNull(stringCache.get("city"));
}

@Test
void removeReturnValueAndRemoves() {
Cache<Integer> numberCache = new Cache<>();
numberCache.put("Tata", 6757575);

assertEquals(6757575, numberCache.remove("Tata"));
assertNull(numberCache.get("Tata"));
}

@Test
void sizeCountsEntries() {
Cache<Integer> numberCache = new Cache<>();
numberCache.put("Tata", 6757575);
numberCache.put("Paul", 7878787);

assertEquals(2, numberCache.size());
}

@Test
void clearEmptiesCache() {
Cache<String> cache = new Cache<>();
cache.put("name", "Daniel");

assertEquals(1, cache.size());
cache.clear();
assertEquals(0, cache.size());
}
}