id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
e8727feb-4588-41dc-9c8b-4fdd8cbdc075 | @Override
public void insertCoin(double coinAmount) {
if (coinAmount != 0.01)
totalAmount += coinAmount;
} |
1502b790-d3b7-411f-9c10-d90d0f4d3f14 | @Override
public double calcTotalAmount() {
return totalAmount;
} |
22cc0810-9364-4d65-b680-e0a64cba2f7c | public VendingMachine() {
coinCalc = new CoinCalculator();
soda = new Soda();
chips = new Chips();
candy = new Candy();
} |
6168da8d-d87d-4ae7-9dad-a7b79448aed1 | public void update() {
setCurrentAmount(coinCalc.calcTotalAmount());
updateDisplay();
} |
ecdfab87-4b6a-4b14-a044-c9ff56ae2f52 | public ArrayList<String> returnCoins() {
setCoinReturnAmount(currentAmount);
returnSlotCoins.addAll(coinList);
coinList.removeAll(coinList);
setCurrentAmount(0.00);
updateDisplay();
return returnSlotCoins;
} |
c531a4f2-55bd-48aa-9d5a-0a7689a01c98 | public void insertCoin(String coin, double coinAmount) {
if (coinIsPenny(coin)) {
pennyFallsToReturnSlot(coin, coinAmount);
} else {
coinAdded(coin, coinAmount);
}
} |
bb385079-4720-4b4c-9c8e-8daaa8701522 | public void sodaButton() {
itemBinList = soda.vend(itemBinList, currentAmount);
updateChangeAmount();
} |
8154edd7-0b5e-4b85-b3bd-0ea23e701bcd | public void chipsButton() {
itemBinList = chips.vend(itemBinList, currentAmount);
updateChangeAmount();
} |
6fb7e9b3-8d19-4b38-8a8c-6a34e669c656 | public void candyButton() {
itemBinList = candy.vend(itemBinList, currentAmount);
updateChangeAmount();
} |
f1b4d417-a1e8-498d-8f2f-0579d508af68 | public Double getCoinReturnAmount() {
return coinReturnAmount;
} |
eba908af-8a38-4f44-b651-0915381df673 | public ArrayList<String> getReturnSlotCoins() {
return returnSlotCoins;
} |
34ce34e3-0f7d-4a40-a855-ad52c5c577ef | public String display() {
return display;
} |
2a804671-142f-4171-be3e-4fd190e41027 | public ArrayList<String> getItemBinList() {
return itemBinList;
} |
982fccbe-04ec-4122-9b07-a046ffd6bebb | private void setDisplay(String display) {
this.display = display;
} |
a661d412-d9b9-4088-9888-3d23a26e4be3 | private void setCurrentAmount(Double currentAmount) {
this.currentAmount = currentAmount;
} |
ab2a931c-45a5-4589-bd1a-9edd85c69eee | private void updateDisplay() {
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
String stringConversion = nf.format(currentAmount);
setDisplay("$" + stringConversion);
} |
874c4d4f-8f5d-465b-9baa-f33f171d718e | private void updateChangeAmount() {
if (currentAmount >= 1.25) {
setCurrentAmount(currentAmount - 1.25);
}
} |
39fc8e6f-7e6b-4df8-9897-be73a544da9d | private void setCoinReturnAmount(Double coinReturnAmount) {
this.coinReturnAmount = coinReturnAmount;
} |
3d82b2ff-c69b-4476-842a-d9860227bca8 | private void coinAdded(String coin, double coinAmount) {
coinList.add(coin);
coinCalc.insertCoin(coinAmount);
} |
e63f3e25-380f-4d9d-95c4-5aa9a9a69d31 | private void pennyFallsToReturnSlot(String coin, double coinAmount) {
returnSlotCoins.add(coin);
setCoinReturnAmount(coinAmount);
} |
dee497ca-9e08-48cb-bd40-a4f54c99073a | private boolean coinIsPenny(String coin) {
return coin.equals("Penny");
} |
651343be-46c3-48b2-aa96-c6b5474c545f | @Override
public ArrayList<String> vend(ArrayList<String> itemBinList, double currentAmount) {
if (currentAmount >= 0.75) {
itemBinList.add("Chips");
}
return itemBinList;
} |
482b1a37-2417-4f1d-afe3-2c6b37283739 | @Override
public ArrayList<String> vend(ArrayList<String> itemBinList, double currentAmount) {
if (currentAmount >= 1.25) {
itemBinList.add("Soda");
}
return itemBinList;
} |
01b52e6b-7092-4d65-a640-02b3045b57ab | @Override
public ArrayList<String> vend(ArrayList<String> itemBinList, double currentAmount) {
if (currentAmount >= 0.50) {
itemBinList.add("Candy");
}
return itemBinList;
} |
58b2e405-ce9b-493d-a078-60aaee48733d | public void insertCoin(double coinAmount); |
3169232e-3286-4607-8e60-b46c8ce2ed0e | public double calcTotalAmount(); |
e6dca977-30b9-4d87-81cc-b14119ed5b4f | public String say(String msg) throws RemoteException; |
9c88ed21-b6c6-4800-825e-f3a1b633d519 | public void set_chances(float[][] chances) throws RemoteException; |
d5c9ed76-1c9a-4471-840f-f82db4f6b952 | public boolean is_done() throws RemoteException; |
fd9080dc-3295-4e14-acc5-a9834987c867 | public boolean sent_results() throws RemoteException; |
78f55857-0edd-4aa9-9605-c35380cea40a | public void start() throws RemoteException; |
717552bb-350c-43ba-912a-042af966be41 | public int[][] get_results() throws RemoteException; |
9cc854f5-fe91-4935-9ce5-f18756c4f8dd | public static void main(String[] argv) {
try {
log("Localhost ip address: " + java.net.InetAddress.getLocalHost());
TrafficCircleSimulationManager trafficCircleSimulationManager = new TrafficCircleSimulationManager();
float[][] chances = trafficCircleSimulationManager
.load_data("params.txt");
Lis... |
528984cb-0848-42ac-a9ea-eb7f8e381641 | private static void log(String msg) {
System.out.println(((DateFormat) new SimpleDateFormat("HH:mm:ss"))
.format(new Date()) + "| " + msg);
} |
0783718d-01ee-4cb5-8abd-e578fee402d4 | private static String[][] load_servers(String filename) {
String[][] array = null;
try {
FileReader fr = new FileReader(filename);
BufferedReader fp = new BufferedReader(fr);
List<String> ip_addresses = new ArrayList<String>();
List<String> names = new ArrayList<String>();
String line;
while ((l... |
ba47f9b9-ca6e-4dc5-8daa-15f7cfcf06d5 | public static void main(String[] argv) {
try {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
log("Server is ready.");
Naming.rebind(argv[0], new TrafficCircleSimulation(argv[0]));
log("Zarejestrowany jako: " + argv[0]);
} catch (Exception e) {
... |
c7b87e81-c6df-4026-be3f-d76b0bb118b1 | private static void log(String msg) {
System.out.println(((DateFormat) new SimpleDateFormat("HH:mm:ss"))
.format(new Date()) + "| " + msg);
} |
fde57b1d-013d-4f1a-87df-a5f9fbb1d7f6 | public float[][] load_data(String filename) {
float array[][] = new float[4][4];
FileReader fr;
try {
fr = new FileReader(filename);
BufferedReader fp = new BufferedReader(fr);
int i, j;
int line_cnt = 0;
String line;
while ((line = fp.readLine()) != null) {
String[] numbers = line.split... |
f3562716-fc81-444c-9eb3-fae68c04e074 | private void log(String msg) {
System.out.println(((DateFormat) new SimpleDateFormat("HH:mm:ss"))
.format(new Date()) + "| " + msg);
} |
d703cf1c-cebd-42ce-8b0e-b40f6ce79208 | public void start() {
log("start()");
int i = 0;
int iteration = 0;
for (i = 0; i <= 15; ++i) {
circle[i] = -1;
}
for (iteration = 0; iteration <= REQUESTED_ITERATIONS; iteration++) {
// int k;
// Przyjeżdżają nowe samochody
for (i = 0; i <= 3; ++i) {
final double u = Math.random();
... |
95080875-d26c-4ad2-ac0a-ab3125b1dc63 | int choose_exit(Entrance entrance_number) {
float dist_n, dist_w, dist_s;
Entrance exit_no;
final float RANDOM = (float) Math.random();
dist_n = CHANCES[entrance_number.ordinal()][0];
dist_w = dist_n + CHANCES[entrance_number.ordinal()][1];
dist_s = dist_w + CHANCES[entrance_number.ordinal()][2];
if (R... |
627a6dd6-1d7b-497e-ba06-90c5381b5011 | public TrafficCircleSimulation(String msg) throws RemoteException {
message = msg;
} |
6ffd3ed1-0dab-485c-b53d-d191dc614a46 | public String say(String msg) throws RemoteException {
return message + " | Argument: " + msg;
} |
92b70cdd-f9d5-4b0d-80b8-05f6c50e55c5 | @Override
public void set_chances(float[][] chances) throws RemoteException {
log("set_chances()");
CHANCES = chances;
} |
d0ab82ca-69f8-4fa4-993a-90462dc72d27 | @Override
public boolean is_done() throws RemoteException {
log("is_done()");
return _isDone;
} |
e842cdb7-4ad4-465c-a867-50a8e1a78ff7 | @Override
public boolean sent_results() throws RemoteException {
return _sentResults;
} |
aeb59e1a-cce2-4df4-a1f8-1a98ce663398 | @Override
public int[][] get_results() throws RemoteException {
log("get_results()");
int results[][] = new int[3][4];
results[0] = arrival_cnt;
results[1] = wait_cnt;
results[2] = queue_accum;
for (int result[] : results) {
for (int field : result) {
System.out.print(field + " ");
}
System.o... |
f4edf39d-be0d-4240-8d85-20631aa8cba7 | public PreviewPanel(Tetris initTetris) {
tetris = initTetris;
panels = new TetrominoPanel[PREVIEW];
for (int i = 0; i < PREVIEW; i++) {
panels[i] = new TetrominoPanel(initTetris, Tetromino.Type.X);
this.add(panels[i]);
}
} |
11812b89-fb82-4909-905a-1fca02bc73f0 | public Dimension getPreferredSize() {
return new Dimension(WIDTH, HEIGHT);
} |
10478107-433f-47fe-91f9-6b86c863acb3 | public void paintComponent(Graphics g) {
super.paintComponent(g);
TetrominoRandom rng = tetris.getRNG();
for (int i = 0; i < PREVIEW; i++) {
panels[i].setType(rng.elementAt(rng.size() - (i + 1)));
}
} |
a297e041-b8c8-4ddd-9b34-82f774df3fa0 | public TetrisBoard() {
board = new Tetromino.Type[HEIGHT][WIDTH];
this.resetBoard();
} |
e30aa0dc-80b4-4c2a-9605-0430cbe2eaba | public Tetromino.Type get(TetrisPoint point) {
return board[point.getY()][point.getX()];
} |
7e6788ca-fdb9-45ea-8ac9-37d85f6ae5e2 | public Tetromino.Type get(int x, int y) {
return board[y][x];
} |
98985be0-de56-4b21-b3d9-fc641e356b59 | public void set(TetrisPoint point, Tetromino.Type type) {
board[point.getY()][point.getX()] = type;
} |
45d4e177-9b3c-4760-80d4-45630cdd170f | public void set(int x, int y, Tetromino.Type type) {
board[y][x] = type;
} |
cc08a7ff-8603-456f-9711-02b213a13c6b | public static boolean inBounds(TetrisPoint point) {
return (0 <= point.getX() && point.getX() < WIDTH) &&
(0 <= point.getY() && point.getY() < HEIGHT);
} |
3bdcdeb9-c439-497a-a139-bb7f06863fd0 | public int clearLines() {
int lines_cleared = 0;
for (int y = 1; y < HEIGHT; y++) {
boolean clear_row = true;
for (int x = 0; x < WIDTH; x++) {
if (this.get(x, y) == Tetromino.Type.X) {
clear_row = false;
break;
}
}
if (clear_row) {
lines_clea... |
484d8e01-fa66-49fd-8794-60a49a86a2df | public void resetBoard() {
for (int y = 0; y < HEIGHT; y++)
for (int x = 0; x < WIDTH; x++)
board[y][x] = Tetromino.Type.X;
} |
0e4ce224-985a-4f6e-9d29-2f7151407d36 | public TetrisPanel(Tetris initTetris) {
tetris = initTetris;
} |
59bdb06d-8e9e-4cc4-8686-ebb1f6396d0d | public Dimension getPreferredSize() {
return new Dimension(TetrisBoard.WIDTH * BLOCK_SIZE, (TetrisBoard.HEIGHT - 2) * BLOCK_SIZE);
} |
57de356a-e76b-425a-8a21-e7ee5ba49b4d | public void paintComponent(Graphics g) {
super.paintComponent(g);
/* Game Over Screen */
if (tetris.isGameOver()) {
for (int y = 2; y < TetrisBoard.HEIGHT; y++) {
for (int x = 0; x < TetrisBoard.WIDTH; x++) {
Tetromino.Type type = tetris.getBoard().get(x, y);
Color color =... |
dbfb1e4b-7fad-4f9d-aa9a-3a1bc5b98182 | public TetrominoPanel(Tetris initTetris, Tetromino.Type initType) {
this.tetris = initTetris;
this.type = initType;
} |
8f906386-1dd2-4ea6-be41-2bf8a21c060a | public Tetromino.Type getType() {
return this.type;
} |
841fee03-fe3b-42ef-8056-05f64c5b9107 | public void setType(Tetromino.Type type) {
this.type = type;
} |
a28484a3-b0fc-431f-90de-3f51cf236c81 | public Dimension getPreferredSize() {
return new Dimension(WIDTH, HEIGHT);
} |
370284e8-90d2-45b2-bc2b-b4c69aa9240d | public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.black);
g.fillRect(0, 0, WIDTH, HEIGHT);
if (this.type == Tetromino.Type.X) return;
for (TetrisPoint point : new Tetromino(type).getBlocks()) {
Color color = TetrisBoard.colors[type.getValue()];
g.setColor... |
00e4df09-e196-4ca1-b577-595bbdd27ddd | public TetrisPoint() {
x = 0;
y = 0;
} |
32d53d28-26c1-4d40-962a-cc2482ad1c12 | public TetrisPoint(int x, int y) {
this.x = x;
this.y = y;
} |
565eeb0d-81f2-4f51-a58f-ea82e9ac3505 | public int getX() { return x; } |
053b6e8e-ce6a-4afc-86dc-380531479fa7 | public int getY() { return y; } |
8c3dc47c-ad41-468f-b35e-8c8736e58d19 | public TetrisPoint add(TetrisPoint point) {
return new TetrisPoint(this.x + point.getX(),
this.y + point.getY());
} |
44daf935-623d-4b28-a6e3-42c0b4de9496 | public TetrisPoint subtract(TetrisPoint point) {
return new TetrisPoint(this.x - point.getX(),
this.y - point.getY());
} |
b3350ddf-c2a2-4278-98de-2bc22b2d0f18 | public boolean equals(TetrisPoint point) {
return x == point.getX() && y == point.getY();
} |
51d50339-5767-420c-933e-b8b49f64dcc8 | public TetrisPoint multiply(int scalar) {
return new TetrisPoint(this.x * scalar, this.y * scalar);
} |
0109ca94-04b0-450b-afda-e063e2159e20 | private TetrominoBlock() {
block = new ImageIcon(this.getClass().getClassLoader().getResource("images/block.png"));
cache = new HashMap<Color, ImageIcon>();
} |
dc85dade-0ee6-4210-ae49-20c41dcc3c24 | public static TetrominoBlock instance() {
if (instance == null) return (instance = new TetrominoBlock());
else return instance;
} |
d6a570a5-08dd-4c86-83d7-7552afe7dda4 | public ImageIcon getIconForColor(Color color) {
if (cache.containsKey(color)) return cache.get(color);
else {
BufferedImage bimage = toBufferedImage(block.getImage());
colorize(bimage, color);
ImageIcon out = new ImageIcon(bimage);
cache.put(color, out);
return out;
}
} |
f5ed0d97-5a3e-4db1-a2f9-db047dfd9196 | public static BufferedImage toBufferedImage(Image image) {
if (image instanceof BufferedImage)
return (BufferedImage)image;
BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bimage.createGraphics();
g.drawImage(image,... |
5e491834-666b-45e8-83cc-e4b73fefd78c | public static void colorize(BufferedImage texture, Color color) {
for (int y = 0; y < texture.getHeight(); y++) {
for (int x = 0; x < texture.getWidth(); x++) {
int pixel = texture.getRGB(x, y);
int red = ((pixel & 0xFF0000) >> 16);
int green = ((pixel & 0x00FF00) >> 8);
int... |
c12ab67e-af33-4438-bf74-11ebdc248763 | public TetrominoRandom() {
stack = new Stack<Tetromino.Type>();
refreshStack();
} |
13e82353-ec7b-4362-99c7-509e5a669e59 | private void refreshStack() {
Stack<Tetromino.Type> tmp = new Stack<Tetromino.Type>();
for (int i = 1; i <= Tetromino.TETROMINOES; i++)
tmp.push(Tetromino.Type.values()[i]);
Collections.shuffle(tmp);
for (Tetromino.Type tetromino : tmp) {
stack.add(0, tetromino);
}
} |
da88c2b0-cfed-49f2-a1e2-726c5043f2f8 | public Tetromino.Type get() {
if (stack.size() == PreviewPanel.PREVIEW + 1) {
refreshStack();
}
return stack.pop();
} |
e0354e84-8991-4cbf-89cb-00d7b5044d4d | public int size() {
return stack.size();
} |
71b8fdd5-4bc3-460f-a8d6-720f7a052af5 | public Tetromino.Type elementAt(int i) {
return stack.elementAt(i);
} |
13d490de-0259-4d5d-ba04-1d3e20fdb1d9 | public Stack<Tetromino.Type> getStack() {
return stack;
} |
5fcbd501-19ad-418a-846e-aaf3310b450c | public ScorePanel(Tetris initTetris) {
tetris = initTetris;
} |
e2dcf37c-c754-4892-bb39-c6e0999af023 | public Dimension getPreferredSize() {
return new Dimension(WIDTH, HEIGHT);
} |
c48d20e5-5c31-4c70-9057-fccfbda8e16d | public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString(String.format("Lines: %d", tetris.getLines()), this.getSize().width / 2 - 32, 40);
} |
266d012f-fefa-4c8b-a1ea-4f7af7062df4 | public TetrisFrame(Tetris initTetris, String title) {
super(title);
setResizable(false);
this.addKeyListener(this);
tetris = initTetris;
} |
2dd80b52-c1c5-4a1b-b439-6ec182d37a72 | public void keyPressed(KeyEvent event) {
if (tetris.isGameOver()) return;
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.VK_LEFT: if (tetris.isRunning() && !tetris.getActiveTetromino().isLocked()) tetris.getActiveTetromino().shift(tetris.getBoard(), new TetrisPoint(-1, 0)); break... |
b0fd9986-d846-4c43-8c6e-fb681efb0176 | public void keyTyped(KeyEvent event) {
} |
980f41c9-3c2c-4496-a69d-8aa3c826b2ac | public void keyReleased(KeyEvent event) {
} |
d22f3968-37e3-44d9-8611-49c2fabd1567 | private Type(int value) {
this.value = value;
} |
73afb1be-53b7-41b5-a2cd-6567128eac63 | public int getValue() {
return this.value;
} |
368a2ae8-886f-492e-8527-2f169d967173 | private Rotation(int value) {
this.value = value;
} |
b1f198ea-b2af-49b0-ada7-7ac5cda76ddb | public int getValue() {
return this.value;
} |
0f1fe2f5-49be-4e46-8f64-adc571061c79 | private RotationPair(int value) {
this.value = value;
} |
e8a582bd-8c29-4997-aed1-cf8e5e5e12a4 | public int getValue() {
return this.value;
} |
91ac1c8a-359d-4a79-92da-30458d22c990 | public static RotationPair get(Rotation from, Rotation to) {
switch (from) {
case East:
switch(to) {
case North:
return RotationPair.EastToNorth;
case South:
return RotationPair.EastToSouth;
}
case North:
switch(to) ... |
8428f2d0-fe8a-4399-ac8e-eac2e4deec4b | public Tetromino(Type type, Rotation rotation, TetrisPoint point) {
this.type = type;
this.rotation = rotation;
this.point = point;
this.blocks = TETROMINO[this.type.getValue() - 1][this.rotation.getValue()];
this.lock = 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.