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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<version>1.0-SNAPSHOT</version>

<properties>
<jvm.version>11</jvm.version>
<jvm.version>17</jvm.version>
<junit.jupiter.version>5.8.2</junit.jupiter.version>
<maven.compiler.source>${jvm.version}</maven.compiler.source>
<maven.compiler.target>${jvm.version}</maven.compiler.target>
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/Main/Price.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
39 changes: 39 additions & 0 deletions src/main/java/Main/itemList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package Main;

import java.util.ArrayList;


public class itemList {
private ArrayList<shopItem> list = new ArrayList<shopItem>();



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

}
20 changes: 20 additions & 0 deletions src/main/java/Main/shopItem.java
Original file line number Diff line number Diff line change
@@ -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;}
}


62 changes: 62 additions & 0 deletions src/test/java/test/test.java
Original file line number Diff line number Diff line change
@@ -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());
}

}