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
32 changes: 19 additions & 13 deletions src/edu/androidclub/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,35 @@ private void test() {
ItemBox itemBox = new ProductsBox(itemScheme);

// Протестируем схему - заставим витрину выдавать объекты на заданных координатах
System.out.println( // Напечатать в консоль
itemBox.emit( // Выдать предмет
new Coordinates(1, 1) // Указываем координату
)
.getName() // Получить имя предмета
); // OK
System.out.println(itemBox.emit(new Coordinates(1, 1)).getName()); // OK
System.out.println(itemBox.emit(new Coordinates(1, 1)).getName()); // OK

System.out.println(itemBox.emit(new Coordinates(1, 1)).getName()); // FAIL - предметы кончились в ячейке
}

if (itemBox.IsThereAny(new Coordinates(1, 1)))
ScreenInput.printItemInfo(itemBox.emit(new Coordinates(1, 1)));
if (itemBox.IsThereAny(new Coordinates(1, 1)))
ScreenInput.printItemInfo(itemBox.emit(new Coordinates(1, 1)));
if (itemBox.IsThereAny(new Coordinates(1, 1)))
ScreenInput.printItemInfo(itemBox.emit(new Coordinates(1, 1)));
if (itemBox.IsThereAny(new Coordinates(1, 1)))
ScreenInput.printItemInfo(itemBox.emit(new Coordinates(1, 1)));
}

// Опишем Колу как подкласс Предмета
public static class Cola extends Item {
public Cola() {
super("Cola"); // Вызов конструктора класса-родителя (класса Item)
super(1,"Cola",12); // Вызов конструктора класса-родителя (класса Item)
}
}

// Опишем Спрайт как подкласс Предмета
public static class Sprite extends Item {
public Sprite() {
super("Sprite");
super(2,"Sprite",13);
}
}

// Опишем Закончишийся продукт как подкласс Предмета
public static class Empty extends Item {
public Empty() {
super(0,"Товар закончился", 0);
}
}
}
16 changes: 11 additions & 5 deletions src/edu/androidclub/ProductsBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ public Item emit(Coordinates coordinates) {
Stack<Item> items = scheme.get(coordinates);

// Если пусто - возвращаем пустоту
if (items.empty()) {
return null;
}
if (IsThereAny(coordinates))
{return items.pop();}
else
{return new Application.Empty();}

// Возвращаем верхний элемент и удаляем его с вершины стопки
return items.pop();
}

public boolean IsThereAny(Coordinates coordinates)
{
Stack<Item> items = scheme.get(coordinates);
if (items.empty()) { return false; }
return true;
}
}

Expand Down
42 changes: 42 additions & 0 deletions src/edu/androidclub/ScreenInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package edu.androidclub;

import edu.androidclub.domain.Item;

public class ScreenInput
{
static public void clear()
{
for (int i=0; i<50 ; i++)
System.out.println();
}

static public void printItemInfo(Item item)
{
System.out.print("| № "+item.getNumber());
System.out.println(Spaces(18-Integer.toString(item.getNumber()).length())+'|');
System.out.print("| Товар: "+item.getName());
System.out.println(Spaces(18-item.getName().length())+'|');
System.out.print("| Цена: "+item.getPrice());
System.out.println(Spaces(18-Float.toString(item.getPrice()).length())+'|');
System.out.println("+--------------------------------+");
}

static private String Spaces(int n)
{
String s = new String();
for (int i=0;i<n;i++)
{
s=s+" ";
}
return s;
}
static public void printText(String text)
{
System.out.println(text);
}

static public void printItemsInfo(ItemInfoScheme iis)
{
System.out.println();
};
}
4 changes: 4 additions & 0 deletions src/edu/androidclub/domain/AppScreen.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package edu.androidclub.domain;

import edu.androidclub.ItemInfoScheme;

/*
* Интерфейс, представляющий собой описание функционал экрана аппарата
* */
public interface AppScreen {
void printText(String text);
void printItemInfo(Item item);
void printItemsInfo(ItemInfoScheme iis);
void clear();
}
15 changes: 14 additions & 1 deletion src/edu/androidclub/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
// Он тоже неизменяемый - т.к. все поля final
public abstract class Item {
private final String name;
private final int number;
private final float price;

public Item(String name) {
public Item(int number, String name, float price)
{
this.number = number;
this.name = name;
this.price = price;
}

// Получить имя
public String getName() {
return name;
}

public int getNumber() {
return number;
}

public float getPrice() {
return price;
}
}
3 changes: 3 additions & 0 deletions src/edu/androidclub/domain/ItemBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import edu.androidclub.Coordinates;

import java.util.Stack;

/*
Интерфейс, описывающий функционал (что умеет) нашей витрины (коробки с продуктами)
* */
public interface ItemBox {

/* Выдать предмет по его координатам */
Item emit(Coordinates coordinates);
boolean IsThereAny(Coordinates coordinates);

}