diff --git a/pom.xml b/pom.xml index 29ae17c..81384f6 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 1.0-SNAPSHOT - 11 + 17 5.8.2 ${jvm.version} ${jvm.version} diff --git a/src/main/java/Main/Price.java b/src/main/java/Main/Price.java new file mode 100644 index 0000000..00643fb --- /dev/null +++ b/src/main/java/Main/Price.java @@ -0,0 +1,33 @@ +package Main; + +public class Price { + private int rub, kop; + + public Price(int n){ + rub = n/100; + kop = n%100; + } + + public Price(int rub_, int kop_) { + rub = rub_; + kop = kop_; + } + + public int get(){ + return rub*100 + kop; + } + + public int getKop(){return kop;} + public int getRub(){return rub;} + + public Price set(int n) { + rub = n/100; + kop = n%100; + return this; + } + public Price set(int rub_, int kop_) { + rub = rub_; + kop = kop_; + return this; + } +} diff --git a/src/main/java/Main/itemList.java b/src/main/java/Main/itemList.java new file mode 100644 index 0000000..4315f9c --- /dev/null +++ b/src/main/java/Main/itemList.java @@ -0,0 +1,39 @@ +package Main; + +import java.util.ArrayList; + + +public class itemList { + private ArrayList list = new ArrayList(); + + + + public void add(shopItem x){ + list.add(x); + } + + public void add(String name, int price){ + list.add(new shopItem(name, new Price(price))); + } + public void add(String name, Price price){ + list.add(new shopItem(name, price)); + } + + public int priceCount(int code, int count){ + var price=0; + if(list.size()>=code) price = list.get(code).getPrice().get(); + return price*count; + } + + public int count(){return list.size();} + + public void delete(int code){ + list.remove(code); + } + + public String getName(int code){return list.get(code).getName();} + public Price getPrice(int code){return list.get(code).getPrice();} + public void editName(int code, String name){list.get(code).editName(name);} + public void editPrice(int code, Price price){list.get(code).editPrice(price);} + +} diff --git a/src/main/java/Main/shopItem.java b/src/main/java/Main/shopItem.java new file mode 100644 index 0000000..552fd98 --- /dev/null +++ b/src/main/java/Main/shopItem.java @@ -0,0 +1,20 @@ +package Main; + +public class shopItem { + private String name; + private Price price; + + shopItem(){} + + shopItem(String name_, Price price_){ + name = name_; + price = price_; + } + + public void editName(String name) {this.name = name;} + public void editPrice(Price price) {this.price = price;} + public String getName(){return name;} + public Price getPrice(){return price;} +} + + diff --git a/src/test/java/test/test.java b/src/test/java/test/test.java new file mode 100644 index 0000000..48b2965 --- /dev/null +++ b/src/test/java/test/test.java @@ -0,0 +1,62 @@ +package test; + +import Main.Price; +import Main.itemList; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class test { + + private itemList testList(){ + itemList test = new itemList(); + test.add("1", 100); + test.add("2", 200); + test.add("3", 300); + test.add("4", 400); + return test; + } + + @Test + void add(){ + itemList test = testList(); + + assertEquals("1", test.getName(0)); + assertEquals("2", test.getName(1)); + } + + @Test + void priceCount(){ + itemList test = testList(); + + assertEquals(1000, test.priceCount(1, 5)); + assertEquals(900, test.priceCount(2, 3)); + } + + @Test + void editName(){ + itemList test = testList(); + + assertEquals("1", test.getName(0)); + test.editName(0, "first"); + assertEquals("first", test.getName(0)); + } + + @Test + void editPrice(){ + itemList test = testList(); + + assertEquals(100, test.getPrice(0).get()); + test.editPrice(0, new Price(587)); + assertEquals(587, test.getPrice(0).get()); + } + + @Test + void delete(){ + itemList test = testList(); + + assertEquals(4, test.count()); + test.delete(0); + assertEquals(3, test.count()); + } + +}