├── Lab2 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── Lab2.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── TestBook.java │ └── Book.java ├── Lab3 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── Lab3.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── FurnitureShopTest.java │ ├── Table.java │ ├── FurnitureShop.java │ ├── Chair.java │ ├── Bed.java │ └── Furniture.java ├── Lab4 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── Priceable.java │ │ ├── TestInterface.java │ │ ├── Good.java │ │ ├── Laptop.java │ │ ├── Mouth.java │ │ └── Excursion.java └── Lab4.iml ├── Lab5 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── 1.jpeg │ │ ├── 2.jpeg │ │ ├── 3.jpeg │ │ ├── 4.jpeg │ │ ├── 5.jpeg │ │ └── MainFrame.java └── Lab5.iml ├── lab1 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── lab1.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ └── Laba1.java ├── lab6 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── lab6.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── gracev │ └── lab6.java ├── lab7 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── lab7.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ └── lab7.java ├── lab8 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── lab8.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ └── Lab8.java ├── Pract16 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── menu │ │ ├── Alcoholable.java │ │ ├── Dish.java │ │ ├── DrinkTypeEnum.java │ │ ├── Drink.java │ │ └── MenuItem.java │ │ ├── exceptons │ │ ├── EmptyOrderListException.java │ │ ├── NoFreeTablesException.java │ │ ├── NoOrderForTableException.java │ │ ├── TableAlreadyOrderedException.java │ │ ├── OrderOnAddressAlreadyExistsException.java │ │ ├── IllegalTableNumberException.java │ │ ├── AddingAlcoholForNotMatureCustomerException.java │ │ ├── CustomerChangedToNotMatureException.java │ │ └── AlcoholForNotMatureCustomerException.java │ │ ├── orders │ │ ├── managers │ │ │ └── OrderManager.java │ │ └── Order.java │ │ └── customers │ │ ├── Customer.java │ │ └── Address.java └── Pract16.iml ├── pract1 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── ex2 │ │ ├── TestBall.java │ │ └── Ball.java │ │ ├── ex1 │ │ ├── DogTest.java │ │ └── Dog.java │ │ └── ex3 │ │ ├── TestBook.java │ │ └── Book.java └── Practis1.iml ├── pract2 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── ex1 │ │ ├── TestAuthor.java │ │ └── Author.java │ │ └── ex2 │ │ ├── TestBall.java │ │ └── Ball.java └── Practice2.iml ├── pract3 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── exs45 │ │ ├── Movable.java │ │ ├── MovableCircle.java │ │ ├── MovablePoint.java │ │ ├── MovableTest.java │ │ └── MovableRectangle.java │ │ └── exs123 │ │ ├── Shape.java │ │ ├── Square.java │ │ ├── Circle.java │ │ ├── Rectangle.java │ │ └── ShapeTest.java └── pract3.iml ├── pract4 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── pract4.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── Practice4.java │ └── Practice4.form ├── pract5 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ └── pract5.iml ├── pract6 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── misc.xml │ ├── modules.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── Laboratornaya6.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── StudentComp.java │ └── Student.java ├── pract7 ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── pract6.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── ex4 │ └── Game.java │ ├── ex2 │ └── Game.java │ ├── ex3 │ └── Game.java │ ├── ex1 │ └── Game.java │ └── ex5 │ └── GameInterface.java ├── Lab16 ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── gui │ │ ├── img │ │ │ └── hasOrder.png │ │ ├── parts │ │ │ ├── GeneralMenu.java │ │ │ └── OrderUI.java │ │ ├── InternetUserWindow.java │ │ └── WaitersWindow.java │ │ ├── menu │ │ ├── Alcoholable.java │ │ ├── Dish.java │ │ ├── DrinkTypeEnum.java │ │ ├── Drink.java │ │ └── MenuItem.java │ │ ├── exceptons │ │ ├── EmptyOrderListException.java │ │ ├── NoFreeTablesException.java │ │ ├── NoOrderForTableException.java │ │ ├── TableAlreadyOrderedException.java │ │ ├── OrderOnAddressAlreadyExistsException.java │ │ ├── IllegalTableNumberException.java │ │ ├── AddingAlcoholForNotMatureCustomerException.java │ │ ├── CustomerChangedToNotMatureException.java │ │ └── AlcoholForNotMatureCustomerException.java │ │ ├── orders │ │ ├── managers │ │ │ └── OrderManager.java │ │ └── Order.java │ │ └── customers │ │ ├── Customer.java │ │ └── Address.java └── Lab16.iml ├── Lab12 ├── .idea │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── Lab12.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ └── ex1 │ └── StringSplitter.java ├── Pract8 ├── .idea │ ├── vcs.xml │ ├── modules.xml │ ├── $PRODUCT_WORKSPACE_FILE$ │ └── misc.xml ├── Pract8.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── IWaitList.java │ ├── Main.java │ ├── UnfairWaitList.java │ └── BoundedWaitList.java ├── Pract9 ├── .idea │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── ex2 │ │ ├── EmptyStringException.java │ │ ├── StudentNotFoundException.java │ │ ├── AgeComparator.java │ │ ├── AvgComparator.java │ │ ├── GroupComparator.java │ │ ├── Starter.java │ │ └── Student.java │ │ └── ex1 │ │ ├── InnNotValidException.java │ │ └── InnChecker.java └── Pract9.iml ├── Pract11 ├── .idea │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── src │ └── ru │ │ └── mirea │ │ └── ikbo1218 │ │ └── grachev │ │ ├── ex3 │ │ ├── Const.java │ │ ├── Operand.java │ │ ├── Variable.java │ │ ├── Add.java │ │ ├── Divide.java │ │ ├── Multiply.java │ │ ├── Subtract.java │ │ ├── Tester.java │ │ └── Operator.java │ │ ├── ex2 │ │ ├── AbstractQueue.java │ │ ├── Queue.java │ │ └── LinkedQueue.java │ │ ├── ex4 │ │ ├── VariableNotFoundException.java │ │ └── Tester.java │ │ └── ex1 │ │ ├── QueueTest.java │ │ ├── ArrayQueue.java │ │ ├── ArrayQueueADT.java │ │ └── ArrayQueueModule.java └── Pract11.iml ├── Pract12 ├── .idea │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── Pract12.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── ex4 │ └── PhoneParser.java │ ├── ex1 │ └── Person.java │ ├── ex3 │ └── Shirt.java │ ├── ex5 │ └── WordConcatenator.java │ └── ex2 │ └── Address.java ├── Lab9 ├── .idea │ ├── modules.xml │ ├── misc.xml │ └── $PRODUCT_WORKSPACE_FILE$ ├── Lab9.iml └── src │ └── ru │ └── mirea │ └── ikbo1218 │ └── grachev │ ├── ex1 │ └── Exception1.java │ ├── ex6 │ └── ThrowsDemo.java │ ├── ex7 │ └── ThrowsDemo.java │ ├── ex2 │ └── Exception2.java │ ├── ex4 │ └── Exception2.java │ ├── ex5 │ └── ThrowsDemo.java │ ├── ex8 │ └── ThrowsDemo.java │ └── ex3 │ └── Exception2.java └── Lab10 ├── .idea ├── modules.xml ├── misc.xml ├── $PRODUCT_WORKSPACE_FILE$ └── workspace.xml └── Lab10.iml /Lab2/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /Lab3/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /Lab4/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /Lab5/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /lab1/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /lab6/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /lab7/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /lab8/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /Pract16/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /pract1/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /pract2/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /pract3/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /pract4/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /pract5/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /pract6/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /pract7/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /Lab5/src/ru/mirea/ikbo1218/grachev/1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grachev-A-A/JavaLabs/HEAD/Lab5/src/ru/mirea/ikbo1218/grachev/1.jpeg -------------------------------------------------------------------------------- /Lab5/src/ru/mirea/ikbo1218/grachev/2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grachev-A-A/JavaLabs/HEAD/Lab5/src/ru/mirea/ikbo1218/grachev/2.jpeg -------------------------------------------------------------------------------- /Lab5/src/ru/mirea/ikbo1218/grachev/3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grachev-A-A/JavaLabs/HEAD/Lab5/src/ru/mirea/ikbo1218/grachev/3.jpeg -------------------------------------------------------------------------------- /Lab5/src/ru/mirea/ikbo1218/grachev/4.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grachev-A-A/JavaLabs/HEAD/Lab5/src/ru/mirea/ikbo1218/grachev/4.jpeg -------------------------------------------------------------------------------- /Lab5/src/ru/mirea/ikbo1218/grachev/5.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grachev-A-A/JavaLabs/HEAD/Lab5/src/ru/mirea/ikbo1218/grachev/5.jpeg -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/gui/img/hasOrder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grachev-A-A/JavaLabs/HEAD/Lab16/src/ru/mirea/ikbo1218/grachev/gui/img/hasOrder.png -------------------------------------------------------------------------------- /Lab4/src/ru/mirea/ikbo1218/grachev/Priceable.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public interface Priceable { 4 | 5 | double getPrice(); 6 | } 7 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/menu/Alcoholable.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public interface Alcoholable { 4 | boolean isAlcoholDrink(); 5 | double getAlcoholVol(); 6 | } 7 | -------------------------------------------------------------------------------- /Lab2/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab3/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab4/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/menu/Alcoholable.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public interface Alcoholable { 4 | boolean isAlcoholDrink(); 5 | double getAlcoholVol(); 6 | } 7 | -------------------------------------------------------------------------------- /lab1/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab6/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab7/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab8/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab12/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract8/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract9/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract11/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Const.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | public class Const extends Operand { 4 | public Const(double value){ 5 | this.value = value; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Pract12/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract16/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs45/Movable.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs45; 2 | 3 | public interface Movable { 4 | void moveUp(); 5 | void moveDown(); 6 | void moveLeft(); 7 | void moveRight(); 8 | } 9 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Operand.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | public abstract class Operand { 4 | protected double value; 5 | 6 | public double getValue() { 7 | return value; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/menu/Dish.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public class Dish extends MenuItem { 4 | public Dish(String name, String description, double cost) { 5 | super(name, description, cost); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex2/AbstractQueue.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public abstract class AbstractQueue implements Queue { 4 | protected int head, tail; 5 | protected static final int START_CAPACITY = 16; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/menu/Dish.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public class Dish extends MenuItem { 4 | public Dish(String name, String description, double cost) { 5 | super(name, description, cost); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Lab5/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex2/Queue.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public interface Queue { 4 | Object dequeue(); 5 | Object element(); 6 | void enqueue(Object o); 7 | boolean isEmpty(); 8 | boolean clear(); 9 | } 10 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex4/VariableNotFoundException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex4; 2 | 3 | public class VariableNotFoundException extends IllegalArgumentException{ 4 | VariableNotFoundException(String msg){ 5 | super(msg); 6 | } 7 | } -------------------------------------------------------------------------------- /pract1/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pract2/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pract3/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pract4/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pract5/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pract6/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pract7/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex2/EmptyStringException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public class EmptyStringException extends IllegalArgumentException { 4 | public EmptyStringException() { 5 | super("Передана пустая строка!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Lab2/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab3/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab4/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab5/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab9/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lab1/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lab6/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lab7/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lab8/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pract2/src/ru/mirea/ikbo1218/grachev/ex1/TestAuthor.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | public class TestAuthor { 4 | public static void main(String[] args) { 5 | Author a = new Author("Иван", "ivan@ivan.ru", 'm'); 6 | System.out.println(a); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lab10/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab12/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/EmptyOrderListException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class EmptyOrderListException extends NullPointerException { 4 | public EmptyOrderListException(){ 5 | super("Нет ни одного заказа!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Pract11/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Pract12/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Pract16/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/EmptyOrderListException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class EmptyOrderListException extends NullPointerException { 4 | public EmptyOrderListException(){ 5 | super("Нет ни одного заказа!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Pract8/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Pract9/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pract1/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pract3/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pract4/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pract5/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pract7/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab10/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab12/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab9/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract11/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract12/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract16/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract9/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex2/StudentNotFoundException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public class StudentNotFoundException extends Exception { 4 | public StudentNotFoundException(String name) { 5 | super("Студент с ФИО "+ name + " не найден!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /pract2/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lab2/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab3/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab4/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lab5/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab1/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab6/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab7/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab8/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract1/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract2/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract3/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract4/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract5/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract6/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract7/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pract6/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex2/AgeComparator.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.Comparator; 4 | 5 | public class AgeComparator implements Comparator { 6 | @Override 7 | public int compare(Student o1, Student o2) { 8 | return o1.getAge() - o2.getAge(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex2/AvgComparator.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.Comparator; 4 | 5 | public class AvgComparator implements Comparator { 6 | @Override 7 | public int compare(Student o1, Student o2) { 8 | return o1.getAvgPoint() - o2.getAvgPoint(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex2/GroupComparator.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.Comparator; 4 | 5 | public class GroupComparator implements Comparator { 6 | @Override 7 | public int compare(Student o1, Student o2) { 8 | return o1.getGroupNum() - o2.getGroupNum(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/menu/DrinkTypeEnum.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public enum DrinkTypeEnum { 4 | BEER, 5 | WINE, 6 | VODKA, 7 | CHAMPAGNE, 8 | WHISKEY, 9 | COFFEE, 10 | BLACK_TEA, 11 | GREEN_TEA, 12 | APPLE_JUICE, 13 | TOMATO_JUICE, 14 | MILK, 15 | WATER, 16 | COLA, 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/menu/DrinkTypeEnum.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public enum DrinkTypeEnum { 4 | BEER, 5 | WINE, 6 | VODKA, 7 | CHAMPAGNE, 8 | WHISKEY, 9 | COFFEE, 10 | BLACK_TEA, 11 | GREEN_TEA, 12 | APPLE_JUICE, 13 | TOMATO_JUICE, 14 | MILK, 15 | WATER, 16 | COLA, 17 | 18 | } 19 | -------------------------------------------------------------------------------- /pract2/src/ru/mirea/ikbo1218/grachev/ex2/TestBall.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public class TestBall { 4 | public static void main(String[] args) { 5 | Ball b = new Ball(); 6 | System.out.println(b); 7 | b.setXY(2.6, 4.9); 8 | System.out.println(b); 9 | b.move(12, -4); 10 | System.out.println(b); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /pract1/src/ru/mirea/ikbo1218/grachev/ex2/TestBall.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public class TestBall { 4 | public static void main(String[] args) { 5 | Ball b1 = new Ball(); 6 | System.out.println(b1); 7 | b1 = new Ball(2, "Жельый"); 8 | System.out.println(b1); 9 | System.out.println("Диаметр шара = " + b1.getDiametr()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/NoFreeTablesException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class NoFreeTablesException extends Exception { 4 | private int count; 5 | 6 | public NoFreeTablesException(int count){ 7 | super("Все столики заняты! Всего столов: "+count); 8 | this.count = count; 9 | } 10 | 11 | public int getCount() { 12 | return count; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/NoFreeTablesException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class NoFreeTablesException extends Exception { 4 | private int count; 5 | 6 | public NoFreeTablesException(int count){ 7 | super("Все столики заняты! Всего столов: "+count); 8 | this.count = count; 9 | } 10 | 11 | public int getCount() { 12 | return count; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/orders/managers/OrderManager.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.orders.managers; 2 | 3 | import ru.mirea.ikbo1218.grachev.menu.MenuItem; 4 | import ru.mirea.ikbo1218.grachev.orders.Order; 5 | 6 | public interface OrderManager { 7 | int itemsQuantity(String itemName); 8 | int itemsQuantity(MenuItem item); 9 | Order[] getOrders(); 10 | double ordersCostSummary(); 11 | int ordersQuantity(); 12 | } 13 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/NoOrderForTableException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class NoOrderForTableException extends IllegalArgumentException { 4 | private int tNum; 5 | 6 | public int gettNum() { 7 | return tNum; 8 | } 9 | public NoOrderForTableException(int tNum){ 10 | super("Для столика №"+(tNum+1)+" нет заказа!"); 11 | this.tNum = tNum; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/TableAlreadyOrderedException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class TableAlreadyOrderedException extends IllegalArgumentException { 4 | private int tNum; 5 | 6 | public int gettNum() { 7 | return tNum; 8 | } 9 | 10 | public TableAlreadyOrderedException(int tNum){ 11 | super("Столик №"+tNum+" занят!"); 12 | this.tNum = tNum; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/NoOrderForTableException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class NoOrderForTableException extends IllegalArgumentException { 4 | private int tNum; 5 | 6 | public int gettNum() { 7 | return tNum; 8 | } 9 | public NoOrderForTableException(int tNum){ 10 | super("Для столика №"+(tNum+1)+" нет заказа!"); 11 | this.tNum = tNum; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/orders/managers/OrderManager.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.orders.managers; 2 | 3 | import ru.mirea.ikbo1218.grachev.menu.MenuItem; 4 | import ru.mirea.ikbo1218.grachev.orders.Order; 5 | 6 | public interface OrderManager { 7 | int itemsQuantity(String itemName); 8 | int itemsQuantity(MenuItem item); 9 | Order[] getOrders(); 10 | double ordersCostSummary(); 11 | int ordersQuantity(); 12 | } 13 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/TableAlreadyOrderedException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class TableAlreadyOrderedException extends IllegalArgumentException { 4 | private int tNum; 5 | 6 | public int gettNum() { 7 | return tNum; 8 | } 9 | 10 | public TableAlreadyOrderedException(int tNum){ 11 | super("Столик №"+tNum+" занят!"); 12 | this.tNum = tNum; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lab2/Lab2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab3/Lab3.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab4/Lab4.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab5/Lab5.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab9/Lab9.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /lab1/lab1.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /lab6/lab6.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /lab8/lab8.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab10/Lab10.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab12/Lab12.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab16/Lab16.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Pract11/Pract11.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Pract12/Pract12.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Pract16/Pract16.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Pract8/Pract8.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Pract9/Pract9.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pract1/Practis1.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pract3/pract3.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pract4/pract4.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pract5/pract5.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pract7/pract6.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/OrderOnAddressAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Address; 4 | 5 | public class OrderOnAddressAlreadyExistsException extends IllegalArgumentException { 6 | Address address; 7 | public OrderOnAddressAlreadyExistsException(Address address) { 8 | super("Заказ на адрес "+address.toString()+" уже обрабатывается!"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/OrderOnAddressAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Address; 4 | 5 | public class OrderOnAddressAlreadyExistsException extends IllegalArgumentException { 6 | Address address; 7 | public OrderOnAddressAlreadyExistsException(Address address) { 8 | super("Заказ на адрес "+address.toString()+" уже обрабатывается!"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /pract2/Practice2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pract6/Laboratornaya6.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex1/InnNotValidException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | import java.math.BigInteger; 4 | 5 | public class InnNotValidException extends Exception { 6 | 7 | private BigInteger innNum; 8 | 9 | public InnNotValidException(BigInteger inn){ 10 | super("ИНН с номером "+ inn + " не действителен!"); 11 | innNum = inn; 12 | } 13 | 14 | public BigInteger getInnNum() { 15 | return innNum; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pract6/src/ru/mirea/ikbo1218/grachev/StudentComp.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import java.util.Comparator; 4 | 5 | public class StudentComp implements Comparator { 6 | @Override 7 | public int compare(Object o1, Object o2) { 8 | if(!(o1 instanceof Student && o2 instanceof Student)) 9 | throw new IllegalArgumentException("Объекты не являются студентами!"); 10 | 11 | return ((Student) o1).getGPA() - ((Student) o2).getGPA(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lab4/src/ru/mirea/ikbo1218/grachev/TestInterface.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | 4 | public class TestInterface { 5 | public static void main(String[] args) { 6 | Priceable p = new Excursion("Путевка в Мексику", 55400, 1.205); 7 | System.out.println(p); 8 | System.out.println(p.getPrice()); 9 | p = new Laptop(12000, "Какая-то модель"); 10 | System.out.println(p); 11 | p = new Mouth(800, 1800, "Черный"); 12 | System.out.println(p); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /pract1/src/ru/mirea/ikbo1218/grachev/ex1/DogTest.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | public class DogTest { 4 | public static void main(String[] args) { 5 | Dog d1 = new Dog("Mike", 2); 6 | Dog d2 = new Dog("Helen", 7); 7 | Dog d3 = new Dog("Bob"); 8 | d3.setAge(1); 9 | System.out.println(d1); 10 | System.out.println(d1.intoHumanAge()); 11 | System.out.println(d2.intoHumanAge()); 12 | System.out.println(d3.intoHumanAge()); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lab4/src/ru/mirea/ikbo1218/grachev/Good.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public abstract class Good implements Priceable { 4 | private double price; 5 | 6 | public Good(double price) { 7 | this.price = price; 8 | } 9 | 10 | public void setPrice(double price) { 11 | this.price = price; 12 | } 13 | 14 | @Override 15 | public double getPrice() { 16 | return price; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "price=" + price; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lab12/src/ru/mirea/ikbo1218/grachev/ex1/StringSplitter.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class StringSplitter { 7 | public static void main(String[] args) { 8 | System.out.println("Введите строку:"); 9 | Scanner sc = new Scanner(System.in); 10 | String str = sc.nextLine(); 11 | System.out.println("Введитк паттерн:"); 12 | String p = sc.nextLine(); 13 | System.out.println(Arrays.toString(str.split(p))); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex2/Starter.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Starter { 6 | public static void main(String[] args) { 7 | ArrayList s = new ArrayList<>(); 8 | s.add(new Student("ФИО", 67, 12, 18)); 9 | s.add(new Student("ФИО2", 57, 12, 18)); 10 | s.add(new Student("ФИО3", 93, 12, 19)); 11 | s.add(new Student("ФИО4", 24, 2, 18)); 12 | s.add(new Student("ФИО5", 66, 12, 18)); 13 | 14 | new LabClassUI(s); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Lab10/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Lab12/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Lab2/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Lab3/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Lab4/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Lab5/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Lab9/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Pract11/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Variable.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | public class Variable { 4 | private String name; 5 | private int pow; 6 | 7 | public Variable(String name){ 8 | this.name = name; 9 | pow = 1; 10 | } 11 | 12 | public Variable(String name, int pow) { 13 | this.name = name; 14 | this.pow = pow; 15 | } 16 | 17 | public Const toConst(double v){ 18 | return new Const(Math.pow(v, pow)); 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Pract12/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Pract16/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Pract8/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Pract9/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /lab1/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /lab6/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /lab7/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /lab8/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pract1/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pract2/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pract3/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pract4/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pract5/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pract6/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pract7/.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.6 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex1/QueueTest.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | public class QueueTest { 4 | public static void main(String[] args) { 5 | ArrayQueueModule aqm = ArrayQueueModule.getInstance(); 6 | aqm.enqueue("Text1"); 7 | aqm.enqueue("Text2"); 8 | aqm.enqueue("Text3"); 9 | System.out.println(aqm.dequeue()); 10 | 11 | ArrayQueueADT adt = new ArrayQueueADT(aqm); 12 | System.out.println(adt.dequeue()); 13 | 14 | ArrayQueue aq = new ArrayQueue(); 15 | System.out.println(aq.dequeue()); } 16 | } 17 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/IllegalTableNumberException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class IllegalTableNumberException extends IllegalArgumentException { 4 | private int tNum, max; 5 | 6 | public int gettNum() { 7 | return tNum; 8 | } 9 | 10 | public int getMax() { 11 | return max; 12 | } 13 | 14 | public IllegalTableNumberException(int tNum, int max){ 15 | super("Стола с номером "+tNum+" не существует! Максимальный номер стола = "+max); 16 | this.max = max; 17 | this.tNum = tNum; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/IllegalTableNumberException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | public class IllegalTableNumberException extends IllegalArgumentException { 4 | private int tNum, max; 5 | 6 | public int gettNum() { 7 | return tNum; 8 | } 9 | 10 | public int getMax() { 11 | return max; 12 | } 13 | 14 | public IllegalTableNumberException(int tNum, int max){ 15 | super("Стола с номером "+tNum+" не существует! Максимальный номер стола = "+max); 16 | this.max = max; 17 | this.tNum = tNum; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Pract8/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex1/Exception1.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | public class Exception1 { 4 | public void exceptionDemo(){ 5 | System.out.println(2/0); 6 | } 7 | public void exceptionDemo2(){ 8 | try{ 9 | System.out.println( 2 / 0 ); 10 | } catch ( ArithmeticException e ) { 11 | System.out.println("Attempted division by zero"); 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | Exception1 e1 = new Exception1(); 17 | e1.exceptionDemo2(); 18 | e1.exceptionDemo(); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Lab3/src/ru/mirea/ikbo1218/grachev/FurnitureShopTest.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class FurnitureShopTest { 4 | public static void main(String[] args) { 5 | FurnitureShop shop = new FurnitureShop(5); 6 | shop.add(new Table( 7 | "Металлический стол", 2, 1.3, 2, 2, 5930, "Металл+стекло", 0 8 | )); 9 | System.out.println(shop.getPrices()); 10 | System.out.println("Куплено: "+ shop.buy(3)); 11 | System.out.println(shop.getPrices()); 12 | 13 | for (Furniture f : 14 | shop.getGoods()) { 15 | f.jumpOn(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lab4/src/ru/mirea/ikbo1218/grachev/Laptop.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Laptop extends Good{ 4 | private String model; 5 | 6 | public Laptop(double price, String model) { 7 | super(price); 8 | this.model = model; 9 | } 10 | 11 | public String getModel() { 12 | return model; 13 | } 14 | 15 | public void setModel(String model) { 16 | this.model = model; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "Laptop{" + 22 | "model='" + model + '\'' + ", " + super.toString() + 23 | '}'; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Add.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | 4 | public class Add extends Operator { 5 | public Add(Operand left, Operand right) { 6 | super(left, right); 7 | } 8 | 9 | public Add(Operand left, Variable vRight) { 10 | super(left, vRight); 11 | } 12 | 13 | public Add(Variable vLeft, Variable vRight) { 14 | super(vLeft, vRight); 15 | } 16 | 17 | public Add(Variable vLeft, Operand right) { 18 | super(vLeft, right); 19 | } 20 | 21 | @Override 22 | public double getValue() { 23 | return left.getValue() + right.getValue(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Divide.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | 4 | public class Divide extends Operator { 5 | public Divide(Operand left, Variable vRight) { 6 | super(left, vRight); 7 | } 8 | 9 | public Divide(Variable vLeft, Variable vRight) { 10 | super(vLeft, vRight); 11 | } 12 | 13 | public Divide(Variable vLeft, Operand right) { 14 | super(vLeft, right); 15 | } 16 | 17 | public Divide(Operand left, Operand right) { 18 | super(left, right); 19 | } 20 | 21 | @Override 22 | public double getValue() { 23 | return left.getValue() / right.getValue(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/AddingAlcoholForNotMatureCustomerException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.menu.Alcoholable; 5 | import ru.mirea.ikbo1218.grachev.menu.Drink; 6 | 7 | public class AddingAlcoholForNotMatureCustomerException extends AlcoholForNotMatureCustomerException { 8 | public AddingAlcoholForNotMatureCustomerException(Customer c, Drink alcoholable) { 9 | super(c, alcoholable); 10 | } 11 | 12 | @Override 13 | public String getMessage() { 14 | return super.getMessage() + "Элемент не добавлен в заказ."; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/CustomerChangedToNotMatureException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.menu.Alcoholable; 5 | import ru.mirea.ikbo1218.grachev.menu.Drink; 6 | 7 | public class CustomerChangedToNotMatureException extends AlcoholForNotMatureCustomerException{ 8 | 9 | public CustomerChangedToNotMatureException(Customer c, Drink[] alcoholables) { 10 | super(c, alcoholables); 11 | } 12 | 13 | @Override 14 | public String getMessage() { 15 | return super.getMessage()+"Вся алкогольная продукция удалена из заказа."; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Multiply.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | 4 | public class Multiply extends Operator { 5 | public Multiply(Operand left, Operand right) { 6 | super(left, right); 7 | } 8 | 9 | public Multiply(Operand left, Variable vRight) { 10 | super(left, vRight); 11 | } 12 | 13 | public Multiply(Variable vLeft, Variable vRight) { 14 | super(vLeft, vRight); 15 | } 16 | 17 | public Multiply(Variable vLeft, Operand right) { 18 | super(vLeft, right); 19 | } 20 | 21 | @Override 22 | public double getValue() { 23 | return left.getValue() * right.getValue(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Subtract.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | 4 | public class Subtract extends Operator { 5 | public Subtract(Operand left, Operand right) { 6 | super(left, right); 7 | } 8 | 9 | public Subtract(Operand left, Variable vRight) { 10 | super(left, vRight); 11 | } 12 | 13 | public Subtract(Variable vLeft, Variable vRight) { 14 | super(vLeft, vRight); 15 | } 16 | 17 | public Subtract(Variable vLeft, Operand right) { 18 | super(vLeft, right); 19 | } 20 | 21 | @Override 22 | public double getValue() { 23 | return left.getValue() - right.getValue(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/AddingAlcoholForNotMatureCustomerException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.menu.Alcoholable; 5 | import ru.mirea.ikbo1218.grachev.menu.Drink; 6 | 7 | public class AddingAlcoholForNotMatureCustomerException extends AlcoholForNotMatureCustomerException { 8 | public AddingAlcoholForNotMatureCustomerException(Customer c, Drink alcoholable) { 9 | super(c, alcoholable); 10 | } 11 | 12 | @Override 13 | public String getMessage() { 14 | return super.getMessage() + "Элемент не добавлен в заказ."; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/CustomerChangedToNotMatureException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.menu.Alcoholable; 5 | import ru.mirea.ikbo1218.grachev.menu.Drink; 6 | 7 | public class CustomerChangedToNotMatureException extends AlcoholForNotMatureCustomerException{ 8 | 9 | public CustomerChangedToNotMatureException(Customer c, Drink[] alcoholables) { 10 | super(c, alcoholables); 11 | } 12 | 13 | @Override 14 | public String getMessage() { 15 | return super.getMessage()+"Вся алкогольная продукция удалена из заказа."; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lab1/src/ru/mirea/ikbo1218/grachev/Laba1.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import java.util.Arrays; 4 | import java.util.Random; 5 | 6 | public class Laba1 { 7 | public static void main(String[] args) { 8 | Random r = new Random(System.currentTimeMillis()); 9 | int[] arr = new int[10]; 10 | System.out.println("Изначальный массив:"); 11 | for (int i = 0; i < arr.length; i++) { 12 | arr[i] = r.nextInt(); 13 | System.out.println("Arr["+i+"] = " + arr[i]); 14 | } 15 | Arrays.sort(arr); 16 | System.out.println("Отсортированный массив: "); 17 | for (int i = 0; i < arr.length; i++) { 18 | System.out.println("Arr["+i+"] = "+arr[i]); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lab7/lab7.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex6/ThrowsDemo.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex6; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ThrowsDemo { 6 | public void getKey() { 7 | Scanner myScanner = new Scanner( System.in ); 8 | String key = myScanner.next(); 9 | printDetails( key ); 10 | } 11 | public void printDetails(String key) { 12 | try { String message = getDetails(key); 13 | System.out.println( message ); 14 | }catch ( Exception e){ 15 | throw e; 16 | } 17 | } 18 | private String getDetails(String key){ 19 | if(key == "") { 20 | //throw new Exception( "Key set to empty string" ); 21 | } 22 | return "data for " + key; 23 | } 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/gui/parts/GeneralMenu.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.gui.parts; 2 | 3 | import ru.mirea.ikbo1218.grachev.gui.Controller; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | 8 | public class GeneralMenu extends JMenuBar { 9 | 10 | public GeneralMenu(Component parent, JMenu[] others){ 11 | JMenu fileMenu = new JMenu("Файл"); 12 | 13 | JMenuItem showAll = new JMenuItem("Показать все окна"); 14 | showAll.addActionListener(e-> Controller.getInstance().showAll()); 15 | fileMenu.add(showAll); 16 | 17 | var exit = new JMenuItem("Выход"); 18 | exit.addActionListener(e->System.exit(0)); 19 | fileMenu.add(exit); 20 | 21 | this.add(fileMenu); 22 | 23 | for(var m: others){ 24 | this.add(m); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Lab4/src/ru/mirea/ikbo1218/grachev/Mouth.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Mouth extends Good{ 4 | private int dpi; 5 | private String color; 6 | 7 | public Mouth(double price, int dpi, String color) { 8 | super(price); 9 | this.dpi = dpi; 10 | this.color = color; 11 | } 12 | 13 | public int getDpi() { 14 | return dpi; 15 | } 16 | 17 | public void setDpi(int dpi) { 18 | this.dpi = dpi; 19 | } 20 | 21 | public String getColor() { 22 | return color; 23 | } 24 | 25 | public void setColor(String color) { 26 | this.color = color; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Mouth{" + 32 | "dpi=" + dpi + 33 | ", color='" + color + '\'' + ", " + super.toString() + 34 | '}'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/orders/Order.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.orders; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.exceptons.AlcoholForNotMatureCustomerException; 5 | import ru.mirea.ikbo1218.grachev.menu.MenuItem; 6 | 7 | public interface Order { 8 | boolean add(MenuItem item) throws AlcoholForNotMatureCustomerException; 9 | String[] itemsNames(); 10 | int itemsQuantity(); 11 | int itemQuantity(String itemName); 12 | int itemQuantity(MenuItem item); 13 | MenuItem[] getItems(); 14 | boolean remove(String itemName); 15 | boolean remove(MenuItem item); 16 | int removeAll(String itemName); 17 | int removeAll(MenuItem item); 18 | MenuItem[] sortedItemsByCostDesc(); 19 | double costTotal(); 20 | Customer getCustomer(); 21 | void setCustomer(Customer newCustomer) throws AlcoholForNotMatureCustomerException; 22 | } 23 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/orders/Order.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.orders; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.exceptons.AlcoholForNotMatureCustomerException; 5 | import ru.mirea.ikbo1218.grachev.menu.MenuItem; 6 | 7 | public interface Order { 8 | boolean add(MenuItem item) throws AlcoholForNotMatureCustomerException; 9 | String[] itemsNames(); 10 | int itemsQuantity(); 11 | int itemQuantity(String itemName); 12 | int itemQuantity(MenuItem item); 13 | MenuItem[] getItems(); 14 | boolean remove(String itemName); 15 | boolean remove(MenuItem item); 16 | int removeAll(String itemName); 17 | int removeAll(MenuItem item); 18 | MenuItem[] sortedItemsByCostDesc(); 19 | double costTotal(); 20 | Customer getCustomer(); 21 | void setCustomer(Customer newCustomer) throws AlcoholForNotMatureCustomerException; 22 | } 23 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/gui/parts/OrderUI.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.gui.parts; 2 | 3 | import ru.mirea.ikbo1218.grachev.menu.Drink; 4 | import ru.mirea.ikbo1218.grachev.orders.Order; 5 | 6 | import javax.swing.*; 7 | 8 | public class OrderUI extends JPanel { 9 | public OrderUI(Order order){ 10 | this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 11 | var items = order.getItems(); 12 | for (var item : items) { 13 | JLabel l = new JLabel(item.getName() + "\t: " + order.itemQuantity(item)); 14 | StringBuilder sb = new StringBuilder(); 15 | if (item instanceof Drink) { 16 | sb.append("Тип: ").append(((Drink) item).getType()).append("\nАлкоголя: ").append(((Drink) item).getAlcoholVol()).append("\n"); 17 | } 18 | sb.append(item.getDescription()); 19 | l.setToolTipText(sb.toString()); 20 | add(l); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/menu/Drink.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public class Drink extends MenuItem implements Alcoholable{ 4 | 5 | private double alcoholVol; 6 | private DrinkTypeEnum type; 7 | 8 | public Drink(String name, String description, double cost, double alcoholVol, DrinkTypeEnum type) { 9 | super(name, description, cost); 10 | this.alcoholVol = alcoholVol; 11 | this.type = type; 12 | } 13 | 14 | public DrinkTypeEnum getType() { 15 | return type; 16 | } 17 | 18 | @Override 19 | public boolean isAlcoholDrink() { 20 | return Double.compare(alcoholVol, 0) > 0; 21 | } 22 | 23 | @Override 24 | public double getAlcoholVol() { 25 | return alcoholVol; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object obj) { 30 | return super.equals(obj) && obj instanceof Drink && type == ((Drink) obj).type && alcoholVol == ((Drink) obj).alcoholVol; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/menu/Drink.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public class Drink extends MenuItem implements Alcoholable{ 4 | 5 | private double alcoholVol; 6 | private DrinkTypeEnum type; 7 | 8 | public Drink(String name, String description, double cost, double alcoholVol, DrinkTypeEnum type) { 9 | super(name, description, cost); 10 | this.alcoholVol = alcoholVol; 11 | this.type = type; 12 | } 13 | 14 | public DrinkTypeEnum getType() { 15 | return type; 16 | } 17 | 18 | @Override 19 | public boolean isAlcoholDrink() { 20 | return Double.compare(alcoholVol, 0) > 0; 21 | } 22 | 23 | @Override 24 | public double getAlcoholVol() { 25 | return alcoholVol; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object obj) { 30 | return super.equals(obj) && obj instanceof Drink && type == ((Drink) obj).type && alcoholVol == ((Drink) obj).alcoholVol; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pract2/src/ru/mirea/ikbo1218/grachev/ex2/Ball.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public class Ball { 4 | double x = 0.0, y = 0.0; 5 | 6 | public Ball(double x, double y) { 7 | this.x = x; 8 | this.y = y; 9 | } 10 | 11 | public Ball() { } 12 | 13 | public double getX() { 14 | return x; 15 | } 16 | 17 | public void setX(double x) { 18 | this.x = x; 19 | } 20 | 21 | public double getY() { 22 | return y; 23 | } 24 | 25 | public void setY(double y) { 26 | this.y = y; 27 | } 28 | 29 | public void setXY(double x, double y){ 30 | setX(x); 31 | setY(y); 32 | } 33 | 34 | public void move(double xDisp, double yDisp){ 35 | setX(x+xDisp); 36 | setY(y+yDisp); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "Ball{" + 42 | "x=" + x + 43 | ", y=" + y + 44 | '}'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex4/Tester.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex4; 2 | 3 | import java.util.HashMap; 4 | import java.util.Scanner; 5 | import java.util.regex.Pattern; 6 | 7 | public class Tester { 8 | public static void main(String[] args) { 9 | System.out.println("Enter a string:"); 10 | Scanner sc = new Scanner(System.in); 11 | String s = sc.nextLine(); 12 | Parser p = new Parser(s); 13 | System.out.println(p.getPrefix()); 14 | System.out.println("ВВодите построчно значения:\nИмя переменной\nЗначение\n...\nend - конец ввода"); 15 | HashMap m = new HashMap<>(); 16 | while(!(s = sc.nextLine()).equals("end")){ 17 | m.putIfAbsent(s, sc.nextDouble()); 18 | sc.nextLine(); 19 | } 20 | try{ 21 | System.out.println(p.calc(m)); 22 | 23 | }catch (VariableNotFoundException e){ 24 | System.out.println(e.getMessage()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs45/MovableCircle.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs45; 2 | 3 | public class MovableCircle implements Movable { 4 | 5 | int radius; 6 | MovablePoint center; 7 | 8 | public MovableCircle(int x, int y, int xSpeed, int ySpeed, int radius) { 9 | this.center = new MovablePoint(x, y, xSpeed, ySpeed); 10 | this.radius = radius; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return "MovableCircle{" + 16 | "radius=" + radius + 17 | ", center=" + center.toString() + 18 | '}'; 19 | } 20 | 21 | @Override 22 | public void moveUp() { 23 | center.moveUp(); 24 | } 25 | 26 | @Override 27 | public void moveDown() { 28 | center.moveDown(); 29 | } 30 | 31 | @Override 32 | public void moveLeft() { 33 | center.moveLeft(); 34 | } 35 | 36 | @Override 37 | public void moveRight() { 38 | center.moveRight(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex7/ThrowsDemo.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex7; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ThrowsDemo { 6 | public void getKey() throws Exception { 7 | Scanner myScanner = new Scanner( System.in ); 8 | System.out.print("Enter Key "); 9 | String key = myScanner.nextLine(); 10 | printDetails( key ); 11 | } 12 | 13 | public void printDetails(String key) throws Exception { 14 | String message = getDetails(key); 15 | System.out.println( message ); 16 | } 17 | private String getDetails(String key) throws Exception { 18 | if(key.equals("")) { 19 | throw new Exception( "Key set to empty string" ); 20 | } 21 | return "data for " + key; 22 | } 23 | 24 | public static void main(String[] args) { 25 | ThrowsDemo td = new ThrowsDemo(); 26 | try { 27 | td.getKey(); 28 | }catch (Exception e){ 29 | e.printStackTrace(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs45/MovablePoint.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs45; 2 | 3 | public class MovablePoint implements Movable { 4 | int x, y, xSpeed, ySpeed; 5 | 6 | public MovablePoint(int x, int y, int xSpeed, int ySpeed) { 7 | this.x = x; 8 | this.y = y; 9 | this.xSpeed = xSpeed; 10 | this.ySpeed = ySpeed; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return "MovablePoint{" + 16 | "x=" + x + 17 | ", y=" + y + 18 | ", xSpeed=" + xSpeed + 19 | ", ySpeed=" + ySpeed + 20 | '}'; 21 | } 22 | 23 | @Override 24 | public void moveUp() { 25 | x += xSpeed; 26 | } 27 | 28 | @Override 29 | public void moveDown() { 30 | x -= xSpeed; 31 | } 32 | 33 | @Override 34 | public void moveLeft() { 35 | y -= ySpeed; 36 | } 37 | 38 | @Override 39 | public void moveRight() { 40 | y += ySpeed; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Pract12/src/ru/mirea/ikbo1218/grachev/ex4/PhoneParser.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex4; 2 | 3 | public class PhoneParser { 4 | private String code, city, triplet, quadruple; 5 | 6 | public PhoneParser(String phone){ 7 | if(phone.startsWith("8")){ 8 | code = "+7"; 9 | }else{ 10 | code = phone.substring(0, phone.length()-10); 11 | } 12 | city = phone.substring(phone.length()-10, phone.length()-7); 13 | triplet = phone.substring(phone.length()-7, phone.length()-4); 14 | quadruple = phone.substring(phone.length()-4); 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return code + city + "-" + triplet + "-" + quadruple; 20 | } 21 | 22 | public static void main(String[] args) { 23 | System.out.println(new PhoneParser("88005553535")); 24 | System.out.println(new PhoneParser("+78005553535")); 25 | System.out.println(new PhoneParser("+1238005553535")); 26 | System.out.println(new PhoneParser("+118005553535")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex2/Exception2.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.Scanner; 4 | 5 | 6 | public class Exception2 { 7 | public void exceptionDemo() { 8 | Scanner myScanner = new Scanner( System.in ); 9 | System.out.print( "Enter an integer "); 10 | String intString = myScanner.next(); 11 | int i = Integer.parseInt(intString); System.out.println( 2 / i ); 12 | } 13 | 14 | public void exceptionDemo2(){ 15 | try { 16 | Scanner myScanner = new Scanner(System.in); 17 | System.out.print("Enter an integer "); 18 | String intString = myScanner.next(); 19 | int i = Integer.parseInt(intString); 20 | System.out.println(2 / i); 21 | }catch (NumberFormatException e){ 22 | System.out.println("Not correct number"); 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | Exception2 e2 = new Exception2(); 28 | e2.exceptionDemo2(); 29 | e2.exceptionDemo(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pract2/src/ru/mirea/ikbo1218/grachev/ex1/Author.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | public class Author { 4 | private String name, email; 5 | private char gender; 6 | 7 | public Author(String name, String email, char gender) { 8 | this.name = name; 9 | this.email = email; 10 | if(gender != 'm' && gender != 'f') 11 | throw new IllegalArgumentException("Недопустимый пол: "+ gender); 12 | this.gender = gender; } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | 19 | public String getEmail() { 20 | return email; 21 | } 22 | 23 | public void setEmail(String email) { 24 | this.email = email; 25 | } 26 | 27 | public char getGender() { 28 | return gender; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "Author{" + 34 | "name='" + name + '\'' + 35 | ", email='" + email + '\'' + 36 | ", gender=" + gender + 37 | '}'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs123/Shape.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs123; 2 | 3 | public abstract class Shape { 4 | protected String color; 5 | protected boolean filled; 6 | 7 | public Shape(String color, boolean filled) { 8 | this.color = color; 9 | this.filled = filled; 10 | } 11 | 12 | public Shape() { 13 | color = "Белый"; 14 | filled = false; 15 | } 16 | 17 | public String getColor() { 18 | return color; 19 | } 20 | 21 | public void setColor(String color) { 22 | this.color = color; 23 | } 24 | 25 | public boolean isFilled() { 26 | return filled; 27 | } 28 | 29 | public void setFilled(boolean filled) { 30 | this.filled = filled; 31 | } 32 | public abstract double getArea(); 33 | public abstract double getPerimeter(); 34 | 35 | @Override 36 | public String toString() { 37 | return "Shape{" + 38 | "colour='" + color + '\'' + 39 | ", filled=" + filled + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pract1/src/ru/mirea/ikbo1218/grachev/ex1/Dog.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | public class Dog { 4 | private String name; 5 | private int age; 6 | 7 | public Dog(String name, int age) { 8 | this.name = name; 9 | this.age = age; 10 | } 11 | public Dog(String n){ 12 | name = n; 13 | age = 0; 14 | } 15 | public Dog(){ 16 | name = "Pup"; 17 | age = 0; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public int getAge() { 29 | return age; 30 | } 31 | 32 | public void setAge(int age) { 33 | this.age = age; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "Dog{" + 39 | "name='" + name + '\'' + 40 | ", age=" + age + 41 | '}'; 42 | } 43 | public String intoHumanAge(){ 44 | return name + "'s age in human years is " + age*7 + " years."; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex2/LinkedQueue.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class LinkedQueue extends AbstractQueue { 6 | 7 | private LinkedList q; 8 | 9 | 10 | public LinkedQueue(){ 11 | q = new LinkedList<>(); 12 | head = tail = 0; 13 | } 14 | 15 | @Override 16 | public Object dequeue() { 17 | if(isEmpty()) throw new IndexOutOfBoundsException("Queue is empty!"); 18 | return q.remove(head); 19 | } 20 | 21 | @Override 22 | public Object element() { 23 | if(isEmpty()) throw new IndexOutOfBoundsException("Queue is empty!"); 24 | return q.get(head); } 25 | 26 | @Override 27 | public void enqueue(Object o) { 28 | q.add(o); 29 | tail++; 30 | } 31 | 32 | @Override 33 | public boolean isEmpty() { 34 | return tail == head; 35 | } 36 | 37 | @Override 38 | public boolean clear() { 39 | boolean r = ! isEmpty(); 40 | q.clear(); 41 | head = tail = 0; 42 | return r; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Lab4/src/ru/mirea/ikbo1218/grachev/Excursion.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Excursion implements Priceable{ 4 | private String name; 5 | private double price; 6 | private double percent; 7 | 8 | public Excursion(String name, double price, double percent) { 9 | this.name = name; 10 | this.price = price; 11 | this.percent = percent; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | @Override 23 | public double getPrice() { 24 | return price*percent; 25 | } 26 | 27 | public void setPrice(double price) { 28 | this.price = price; 29 | } 30 | 31 | public void setPercent(double percent) { 32 | this.percent = percent; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Excursion{" + 38 | "name='" + name + '\'' + 39 | ", price=" + price + 40 | ", percent=" + percent + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Tester.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Tester { 6 | public static void main(String[] args) { 7 | System.out.println( 8 | new Subtract( 9 | new Multiply( 10 | new Const(2), 11 | new Variable("x") 12 | ), 13 | new Const(3) 14 | ).evaluate(5) 15 | ); 16 | 17 | Scanner sc = new Scanner(System.in); 18 | double v = sc.nextDouble(); 19 | 20 | System.out.println( 21 | new Add( 22 | new Subtract( 23 | new Variable("x", 2), 24 | new Multiply( 25 | new Const(2), 26 | new Variable("x") 27 | ) 28 | ), 29 | new Const(1) 30 | ).evaluate(v) 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pract6/src/ru/mirea/ikbo1218/grachev/Student.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Student implements Comparable { 4 | 5 | private int idNum; 6 | private int GPA; 7 | 8 | public Student(int idNum, int GPA) { 9 | this.idNum = idNum; 10 | this.GPA = GPA; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return "Student{" + 16 | "idNum=" + idNum + 17 | ", GPA=" + GPA + 18 | '}'; 19 | } 20 | 21 | public int getIdNum() { 22 | return idNum; 23 | } 24 | 25 | public void setIdNum(int idNum) { 26 | this.idNum = idNum; 27 | } 28 | 29 | public int getGPA() { 30 | return GPA; 31 | } 32 | 33 | public void setGPA(int GPA) { 34 | this.GPA = GPA; 35 | } 36 | 37 | @Override 38 | public int compareTo(Object o) { 39 | if(!(o instanceof Student)) 40 | throw new IllegalArgumentException("Объект не является студентом!"); 41 | // < 0 -> o, 0 -> ==, >0 -> this; 42 | return this.idNum - ((Student) o).idNum; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Lab5/src/ru/mirea/ikbo1218/grachev/MainFrame.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import javax.swing.ImageIcon; 4 | import javax.swing.JFrame; 5 | import javax.swing.JLabel; 6 | import javax.swing.SwingConstants; 7 | import javax.swing.Timer; 8 | import javax.swing.WindowConstants; 9 | 10 | 11 | public class MainFrame extends JFrame { 12 | 13 | private JLabel imgLabel; 14 | private int imgNum = 1; 15 | 16 | private MainFrame(){ 17 | this.setSize(1200, 1200); 18 | imgLabel = new JLabel("", new ImageIcon(getClass().getResource("1.jpeg")), SwingConstants.CENTER); 19 | 20 | getContentPane().add(imgLabel); 21 | 22 | Timer timer = new Timer(2000, e -> nextImg()); 23 | timer.start(); 24 | } 25 | private void nextImg(){ 26 | imgLabel.setIcon(new ImageIcon(getClass().getResource((++imgNum)+".jpeg"))); 27 | if(imgNum == 5) imgNum = 0; 28 | 29 | } 30 | 31 | public static void main(String[] args) { 32 | MainFrame mf = new MainFrame(); 33 | mf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 34 | mf.setVisible(true); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs123/Square.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs123; 2 | 3 | public class Square extends Rectangle { 4 | public Square() { 5 | super(); 6 | } 7 | public Square(double side){ 8 | super(side, side); 9 | } 10 | public Square(double side, String colour, boolean filled){ 11 | super(colour, filled, side, side); 12 | } 13 | 14 | public double getSide() {return width;} 15 | public void setSide(double side){ 16 | width = side; 17 | length = side; 18 | } 19 | 20 | @Override 21 | public void setWidth(double width) { 22 | super.setWidth(width); 23 | super.setLength(length); 24 | } 25 | 26 | @Override 27 | public void setLength(double length) { 28 | super.setLength(length); 29 | super.setWidth(width); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Square{" + 35 | "width=" + width + 36 | ", length=" + length + 37 | ", colour='" + color + '\'' + 38 | ", filled=" + filled + 39 | '}'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex3/Operator.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | public abstract class Operator extends Operand{ 4 | protected Operand left, right; 5 | protected Variable vLeft, vRight; 6 | public Operator(Operand left, Operand right){ 7 | this.left = left; 8 | this.right = right; 9 | } 10 | 11 | public Operator(Operand left, Variable vRight) { 12 | this.left = left; 13 | this.vRight = vRight; 14 | } 15 | 16 | public Operator(Variable vLeft, Variable vRight) { 17 | this.vLeft = vLeft; 18 | this.vRight = vRight; 19 | } 20 | public Operator (Variable vLeft, Operand right){ 21 | this.vLeft = vLeft; 22 | this.right = right; 23 | } 24 | 25 | @Override 26 | public abstract double getValue(); 27 | 28 | public double evaluate(double v){ 29 | if(right == null) right = vRight.toConst(v); 30 | if(left == null) left = vLeft.toConst(v); 31 | if(left instanceof Operator) ((Operator) left).evaluate(v); 32 | if(right instanceof Operator)((Operator) right).evaluate(v); 33 | return getValue(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Pract12/src/ru/mirea/ikbo1218/grachev/ex1/Person.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | public class Person { 4 | private String name, surname, patronymic; 5 | 6 | public Person(String surname) { 7 | this.surname = surname; 8 | } 9 | 10 | public Person(String name, String surname, String patronymic) { 11 | this.name = name; 12 | this.surname = surname; 13 | this.patronymic = patronymic; 14 | } 15 | public String getFio(){ 16 | StringBuilder sb = new StringBuilder(surname); 17 | if(name != null && ! name.equals("")) 18 | sb.append(" ").append(name); 19 | if(patronymic != null && ! patronymic.equals("")) 20 | sb.append(" ").append(patronymic); 21 | return sb.toString(); 22 | } 23 | 24 | public static void main(String[] args) { 25 | Person p1 = new Person("Cоловьёв"); 26 | Person p2 = new Person("", "Бобров", ""); 27 | Person p3 = new Person("Николай", "Романов", "Александрович"); 28 | 29 | System.out.println(p1.getFio()); 30 | System.out.println(p2.getFio()); 31 | System.out.println(p3.getFio()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex4/Exception2.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex4; 2 | 3 | 4 | import java.util.Scanner; 5 | 6 | /* 7 | И наконец добавьте блок finally к решению Задания №2. 8 | Повторно запустите программу, чтобы проверить ее поведение. Объясните новое поведение программы 9 | 10 | */ 11 | public class Exception2 { 12 | public void exceptionDemo() { 13 | try { 14 | Scanner myScanner = new Scanner(System.in); 15 | System.out.print("Enter an integer "); 16 | String intString = myScanner.next(); 17 | int i = Integer.parseInt(intString); 18 | System.out.println(2 / i); 19 | }catch(Exception e) { 20 | System.out.println("Exception happened!"); 21 | } 22 | // catch (NumberFormatException e){ // Compile error: NumberFormatException already catched 23 | // System.out.println("Not correct number"); 24 | // } 25 | finally { 26 | System.out.println("finally"); 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | Exception2 e2 = new Exception2(); 32 | e2.exceptionDemo(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs123/Circle.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs123; 2 | 3 | public class Circle extends Shape { 4 | 5 | protected double radius; 6 | 7 | public Circle(String colour, boolean filled, double radius) { 8 | super(colour, filled); 9 | this.radius = radius; 10 | } 11 | 12 | public Circle(double radius) { 13 | super(); 14 | this.radius = radius; 15 | } 16 | 17 | public Circle() { 18 | super(); 19 | radius = 0; 20 | } 21 | 22 | public double getRadius() { 23 | return radius; 24 | } 25 | 26 | public void setRadius(double radius) { 27 | this.radius = radius; 28 | } 29 | 30 | @Override 31 | public double getArea() { 32 | return Math.PI * radius * radius; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Circle{" + 38 | "radius=" + radius + 39 | ", colour='" + color + '\'' + 40 | ", filled=" + filled + 41 | '}'; 42 | } 43 | 44 | @Override 45 | public double getPerimeter() { 46 | return Math.PI * radius * 2; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex1/InnChecker.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Scanner; 5 | 6 | public class InnChecker { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | while(true){ 11 | System.out.println("Введите номер ИНН"); 12 | try{ 13 | BigInteger inn = new BigInteger(sc.nextLine()); 14 | checkInn(inn); 15 | break; 16 | }catch (InnNotValidException e){ 17 | System.out.println(e.getLocalizedMessage()); 18 | } 19 | } 20 | System.out.println("ИНН действителен!"); 21 | } 22 | 23 | public static boolean checkInn(BigInteger inn) throws InnNotValidException{ 24 | int i = 0; 25 | BigInteger cInn = new BigInteger(inn.toByteArray()); 26 | while (!cInn.equals(new BigInteger("0"))){ 27 | i++; 28 | cInn = new BigInteger(cInn.divide(new BigInteger("10")).toByteArray()); 29 | } 30 | if(i != 10 && i != 12) throw new InnNotValidException(inn); 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lab7/src/ru/mirea/ikbo1218/grachev/lab7.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class lab7 { 4 | public static void main(String[] args) { 5 | MyArrayList ints = new MyArrayList<>(8); 6 | for(int i = 0; i<20;i++) 7 | ints.add(i); 8 | System.out.println(ints); 9 | for(int i = 5; i < 13; i++) 10 | ints.remove(i); 11 | System.out.println(ints); 12 | System.out.println(ints.get(5)); 13 | System.out.println(); 14 | 15 | MyArrayList strs = new MyArrayList<>(); 16 | System.out.println(strs); 17 | for (int i = 0; i < 10; i++) { 18 | strs.add("String number " + (i+1)); 19 | } 20 | System.out.println(strs); 21 | System.out.println(); 22 | 23 | MyArrayList strs2 = new MyArrayList<>(strs); 24 | System.out.println(strs2); 25 | strs2.remove(5); 26 | System.out.println(strs2.get(5)); 27 | System.out.println(strs.get(5)); 28 | strs2.addAll(strs2.getCount(), strs.subList(4, 8)); 29 | System.out.println(strs2); 30 | strs2.sort(String::compareTo); 31 | System.out.println(strs2); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex5/ThrowsDemo.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex5; 2 | 3 | public class ThrowsDemo { 4 | 5 | public void printMessage(String key) { 6 | String message = getDetails(key); System.out.println( message ); 7 | } 8 | 9 | public String getDetails(String key) { 10 | if(key == null) { 11 | throw new NullPointerException( "null key in getDetails" ); 12 | } 13 | return "data for " + key; 14 | } 15 | 16 | public void printMessageSafe(String key) { 17 | String message = getDetailsSafe(key); System.out.println( message ); 18 | } 19 | 20 | public String getDetailsSafe(String key) { 21 | try { 22 | if (key == null) { 23 | throw new NullPointerException("null key in getDetails"); 24 | } 25 | }catch (NullPointerException e){ 26 | key = "default"; 27 | } 28 | return "data for " + key; 29 | } 30 | 31 | public static void main(String[] args) { 32 | ThrowsDemo td = new ThrowsDemo(); 33 | 34 | td.printMessageSafe("Key"); 35 | td.printMessageSafe(null); 36 | 37 | td.printMessage("Key"); 38 | td.printMessage(null); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex8/ThrowsDemo.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex8; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ThrowsDemo { 6 | public void getKey() { 7 | Scanner myScanner = new Scanner(System.in); 8 | 9 | boolean incor = false; 10 | do { 11 | incor = false; 12 | System.out.print("Enter Key "); 13 | String key = myScanner.nextLine(); 14 | try{ 15 | printDetails(key); 16 | }catch (Exception e){ 17 | incor = true; 18 | } 19 | }while (incor); 20 | } 21 | 22 | public void printDetails(String key) throws Exception { 23 | String message = getDetails(key); 24 | System.out.println( message ); } 25 | private String getDetails(String key) throws Exception { 26 | if(key.equals("")) { 27 | throw new Exception( "Key set to empty string" ); 28 | } 29 | return "data for " + key; 30 | } 31 | 32 | public static void main(String[] args) { 33 | ThrowsDemo td = new ThrowsDemo(); 34 | try { 35 | td.getKey(); 36 | }catch (Exception e){ 37 | e.printStackTrace(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs45/MovableTest.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs45; 2 | 3 | public class MovableTest { 4 | public static void main(String[] args) { 5 | Movable m = new MovablePoint(0, 0, 1, 4); 6 | System.out.println("Point:\n"); 7 | System.out.println(m); 8 | m.moveUp(); 9 | m.moveRight(); 10 | System.out.println("Up+Right -> " + m); 11 | 12 | System.out.println("\nCircle:\n"); 13 | m = new MovableCircle(0, 0, 2, 4, 6); 14 | System.out.println(m); 15 | m.moveDown(); 16 | m.moveLeft(); 17 | System.out.println("Down+Left -> " + m); 18 | 19 | System.out.println("\nRectangle:\n"); 20 | m = new MovableRectangle(0, 0, 4, 4, 2,4); 21 | System.out.println(m); 22 | m.moveRight(); 23 | m.moveDown(); 24 | System.out.println("Right+Down -> " + m); 25 | 26 | System.out.println("\nChanging speed for rectangle:"); 27 | MovableRectangle r = (MovableRectangle)m; 28 | r.setSpeed(10, 0); // change speed of topLeft point only! 29 | try{ 30 | r.moveDown(); 31 | }catch (IllegalStateException e){ 32 | System.out.println(e); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pract1/src/ru/mirea/ikbo1218/grachev/ex2/Ball.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public class Ball { 4 | private int radius; 5 | private String color; 6 | 7 | public Ball(int radius, String color) { 8 | this.radius = radius; 9 | this.color = color; 10 | } 11 | 12 | public Ball(int radius) { 13 | this.radius = radius; 14 | this.color = "Красный"; 15 | } 16 | 17 | public Ball(String color) { 18 | this.radius = 1; 19 | this.color = color; 20 | } 21 | 22 | public Ball() { 23 | this.radius = 1; 24 | this.color = "Красный"; 25 | } 26 | 27 | public int getRadius() { 28 | return radius; 29 | } 30 | 31 | public void setRadius(int radius) { 32 | this.radius = radius; 33 | } 34 | 35 | public String getColor() { 36 | return color; 37 | } 38 | 39 | public void setColor(String color) { 40 | this.color = color; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Ball{" + 46 | "radius=" + radius + 47 | ", color='" + color + '\'' + 48 | '}'; 49 | } 50 | 51 | public int getDiametr(){ 52 | return 2*radius; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Lab3/src/ru/mirea/ikbo1218/grachev/Table.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Table extends Furniture { 4 | private String material; 5 | private int drawerCount; 6 | 7 | public Table(String modelName, int legCount, double height, double width, double depth, int price, String material, int drawerCount) { 8 | super(legCount, height, width, depth, false, price, modelName); 9 | this.material = material; 10 | this.drawerCount = drawerCount; 11 | } 12 | 13 | public String getMaterial() { 14 | return material; 15 | } 16 | 17 | public void setMaterial(String material) { 18 | this.material = material; 19 | } 20 | 21 | public int getDrawerCount() { 22 | return drawerCount; 23 | } 24 | 25 | public void setDrawerCount(int drawerCount) { 26 | this.drawerCount = drawerCount; 27 | } 28 | 29 | @Override 30 | public void jumpOn() { 31 | System.out.println("Ouch! Вы прыгаете на столе и ударяетесь головой о потолок..."); 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Table{" + 37 | "material='" + material + '\'' + 38 | ", drawerCount=" + drawerCount + ", " + super.toString() + 39 | '}'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex1/ArrayQueue.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | 4 | // INV: FIFO (First in - first out) 5 | // 0 <= size 6 | // queue[head]..queue[tail] - queue 7 | public class ArrayQueue { 8 | private ArrayQueueModule queue; 9 | 10 | public ArrayQueue(){ 11 | this.queue = ArrayQueueModule.getInstance(); 12 | } 13 | 14 | // PRE: size > 0 15 | // POST: R = queue[head] 16 | // queue[head] = queue[head+1] 17 | // queue[head+1]..queue[tail] - immutable 18 | public Object dequeue() { 19 | return queue.dequeue(); 20 | } 21 | 22 | // PRE: size > 0 23 | // POST: R = queue[head] 24 | // queue - immutable 25 | public Object element() { 26 | return queue.element(); 27 | } 28 | 29 | // PRE: None 30 | // POST: queue[tail] = element 31 | // queue[head]..queue[tail-1] - immutable 32 | public void enqueue(Object o) { 33 | queue.enqueue(o); 34 | } 35 | 36 | // PRE: None 37 | // POST: queue - immutable 38 | // R = (head == tale) 39 | public boolean isEmpty() { 40 | return queue.isEmpty(); 41 | } 42 | 43 | // PRE: None 44 | // POST: size == 0 45 | public boolean clear() { 46 | return queue.clear(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex1/ArrayQueueADT.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | // INV: FIFO (First in - first out) 4 | // 0 <= size 5 | // queue[head]..queue[tail] - queue 6 | public class ArrayQueueADT { 7 | 8 | private ArrayQueueModule queue; 9 | 10 | public ArrayQueueADT(ArrayQueueModule queue){ 11 | this.queue = queue; 12 | } 13 | 14 | // PRE: size > 0 15 | // POST: R = queue[head] 16 | // queue[head] = queue[head+1] 17 | // queue[head+1]..queue[tail] - immutable 18 | public Object dequeue() { 19 | return queue.dequeue(); 20 | } 21 | 22 | // PRE: size > 0 23 | // POST: R = queue[head] 24 | // queue - immutable 25 | public Object element() { 26 | return queue.element(); 27 | } 28 | 29 | // PRE: None 30 | // POST: queue[tail] = element 31 | // queue[head]..queue[tail-1] - immutable 32 | public void enqueue(Object o) { 33 | queue.enqueue(o); 34 | } 35 | 36 | // PRE: None 37 | // POST: queue - immutable 38 | // R = (head == tale) 39 | public boolean isEmpty() { 40 | return queue.isEmpty(); 41 | } 42 | 43 | // PRE: None 44 | // POST: size == 0 45 | public boolean clear() { 46 | return queue.clear(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Lab9/src/ru/mirea/ikbo1218/grachev/ex3/Exception2.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | import java.util.Scanner; 4 | 5 | /* 6 | С помощью перехватывания исключений можно оказывать влияние на поведение программы. 7 | В вашем решении в предыдущем упражнении вы можете добавить новый пункт - catch в начале списка пунктов catch. 8 | Выполите это, чтобы поймать общее исключение класса Exception. 9 | Перезапустите программу с приведенными выше данными и обратите внимание на ее поведение. Объясните новое поведение программы 10 | 11 | */ 12 | 13 | public class Exception2 { 14 | public void exceptionDemo() { 15 | try { 16 | Scanner myScanner = new Scanner(System.in); 17 | System.out.print("Enter an integer "); 18 | String intString = myScanner.next(); 19 | int i = Integer.parseInt(intString); 20 | System.out.println(2 / i); 21 | } 22 | catch (NumberFormatException e){ // Compile error: NumberFormatException already catched 23 | System.out.println("Not correct number"); 24 | } 25 | catch(Exception e) { 26 | System.out.println("Exception happened!"); 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | Exception2 e2 = new Exception2(); 32 | e2.exceptionDemo(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pract4/src/ru/mirea/ikbo1218/grachev/Practice4.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import javax.swing.*; 4 | 5 | public class Practice4 extends JFrame{ 6 | private JPanel panel1; 7 | private JButton ACMilanButton; 8 | private JButton realMadridButton; 9 | private JLabel lastScoreLabel; 10 | private JLabel resLabel; 11 | private JLabel winLabel; 12 | 13 | private int mil = 0, rea = 0; 14 | 15 | private Practice4(){ 16 | setContentPane(panel1); 17 | setSize(430, 100); 18 | setLocationRelativeTo(null); 19 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 20 | setVisible(true); 21 | ACMilanButton.addActionListener(e->{ 22 | mil++; 23 | upd("AC Milan"); 24 | }); 25 | realMadridButton.addActionListener(e->{ 26 | rea++; 27 | upd("Real Madrid"); 28 | }); 29 | } 30 | 31 | private void upd(String last){ 32 | lastScoreLabel.setText("Last Score: " + last); 33 | resLabel.setText("Result: " + mil + " X " + rea); 34 | String w = "DRAW"; 35 | if(mil > rea) 36 | w = "AC Milan"; 37 | else if (rea > mil) 38 | w = "Real Madrid"; 39 | winLabel.setText("Winner: " + w); 40 | } 41 | 42 | public static void main(String[] args) { 43 | new Practice4(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Pract8/src/ru/mirea/ikbo1218/grachev/IWaitList.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * Interface IWaitList with methods for implementors. 7 | * @param Type of elements to store in WaitList. 8 | * @author aleksandrgracev 9 | * * @version 1.0 10 | */ 11 | public interface IWaitList { 12 | /** 13 | * Method to add element into end of queue. 14 | * @param element Value to be added. 15 | */ 16 | void add(E element); 17 | 18 | /** 19 | * Method to remove first element of queue. 20 | * @return Removed element. 21 | */ 22 | E remove(); 23 | 24 | /** 25 | * Method to check, is equal element included in queue or not. 26 | * @param element Value for search. 27 | * @return Is (true) element in list or not (false). 28 | */ 29 | boolean contains(E element); 30 | 31 | /** 32 | * Method to check, are all elements of collection included in queue or not. 33 | * @param collection Collection with values for search. 34 | * @return Are (true) all elements in list or not (false). 35 | */ 36 | boolean containsAll(Collection collection); 37 | 38 | /** 39 | * Method to check, are there any elements in list or not. 40 | * @return True - no elements, false - any elements in list. 41 | */ 42 | boolean isEmpty(); 43 | } 44 | -------------------------------------------------------------------------------- /pract7/src/ru/mirea/ikbo1218/grachev/ex4/Game.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex4; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class Game { 6 | LinkedList fp, sp; 7 | 8 | public Game(String fp, String sp) { 9 | this.fp = new LinkedList<>(); 10 | this.sp = new LinkedList<>(); 11 | for(int i = 0; i < 5; i ++){ 12 | this.fp.add(Integer.parseInt(fp.substring(i, i+1))); 13 | this.sp.add(Integer.parseInt(sp.substring(i, i+1))); 14 | } 15 | } 16 | 17 | 18 | public String play(){ 19 | int count = 0; 20 | while(!fp.isEmpty() && !sp.isEmpty() && count <= 106){ 21 | if(fp.peek() > sp.peek() 22 | && sp.peek() != 0){ 23 | fp.add(fp.remove()); 24 | fp.add(sp.remove()); 25 | 26 | }else{ 27 | sp.add(fp.remove()); 28 | sp.add(sp.remove()); 29 | } 30 | count++; 31 | } 32 | String res = ""; 33 | if(fp.isEmpty()) res += "second "; 34 | else res += "first "; 35 | res += count; 36 | if(count >= 106) res += " botva"; 37 | return res; 38 | } 39 | 40 | public static void main(String[] args) { 41 | System.out.println(new Game("13579", "24680").play()); 42 | System.out.println(new Game("12345", "67890").play()); 43 | System.out.println(new Game("13029", "42685").play()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/menu/MenuItem.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public abstract class MenuItem implements Comparable{ 4 | private String name, description; 5 | private double cost; 6 | 7 | public MenuItem(String name, String description, double cost) throws IllegalArgumentException { 8 | if(!name.equals("")) 9 | this.name = name; 10 | else throw new IllegalArgumentException("Передано некорректное название элемента меню!"); 11 | if(!description.equals("")) 12 | this.description = description; 13 | else throw new IllegalArgumentException("Передано некорректное описание элемента меню!"); 14 | if(cost > 0) 15 | this.cost = cost; 16 | else throw new IllegalArgumentException("Передана некорректная цена для элемента меню!"); 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public String getDescription() { 24 | return description; 25 | } 26 | 27 | public double getCost() { 28 | return cost; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | return obj instanceof MenuItem && name.equals(((MenuItem) obj).name) && description.equals(((MenuItem) obj).description) 34 | && cost == ((MenuItem) obj).cost; 35 | } 36 | 37 | @Override 38 | public int compareTo(MenuItem o) { 39 | return (int)Math.round(cost - o.cost); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/menu/MenuItem.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.menu; 2 | 3 | public abstract class MenuItem implements Comparable{ 4 | private String name, description; 5 | private double cost; 6 | 7 | public MenuItem(String name, String description, double cost) throws IllegalArgumentException { 8 | if(!name.equals("")) 9 | this.name = name; 10 | else throw new IllegalArgumentException("Передано некорректное название элемента меню!"); 11 | if(!description.equals("")) 12 | this.description = description; 13 | else throw new IllegalArgumentException("Передано некорректное описание элемента меню!"); 14 | if(cost > 0) 15 | this.cost = cost; 16 | else throw new IllegalArgumentException("Передана некорректная цена для элемента меню!"); 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public String getDescription() { 24 | return description; 25 | } 26 | 27 | public double getCost() { 28 | return cost; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | return obj instanceof MenuItem && name.equals(((MenuItem) obj).name) && description.equals(((MenuItem) obj).description) 34 | && cost == ((MenuItem) obj).cost; 35 | } 36 | 37 | @Override 38 | public int compareTo(MenuItem o) { 39 | return (int)Math.round(cost - o.cost); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pract7/src/ru/mirea/ikbo1218/grachev/ex2/Game.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.ArrayDeque; 4 | import java.util.Queue; 5 | 6 | public class Game { 7 | Queue fp, sp; 8 | 9 | public Game(String fp, String sp) { 10 | this.fp = new ArrayDeque<>(); 11 | this.sp = new ArrayDeque<>(); 12 | for(int i = 0; i < 5; i ++){ 13 | this.fp.add(Integer.parseInt(fp.substring(i, i+1))); 14 | this.sp.add(Integer.parseInt(sp.substring(i, i+1))); 15 | } 16 | } 17 | 18 | public String play(){ 19 | int count = 0; 20 | while(!fp.isEmpty() && !sp.isEmpty() && count < 106){ 21 | if(fp.peek() > sp.peek() 22 | && sp.peek() != 0){ 23 | fp.add(fp.remove()); 24 | fp.add(sp.remove()); 25 | 26 | }else{ 27 | sp.add(fp.remove()); 28 | sp.add(sp.remove()); 29 | } 30 | count++; 31 | } 32 | String res = ""; 33 | if(fp.isEmpty()) res += "second "; 34 | else if (sp.isEmpty()) res += "first "; 35 | res += count; 36 | if(count >= 106) res += " botva"; 37 | return res; 38 | } 39 | 40 | public static void main(String[] args) { 41 | System.out.println(new Game("13579", "24680").play()); 42 | System.out.println(new Game("12345", "67890").play()); 43 | System.out.println(new Game("13029", "42685").play()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs123/Rectangle.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs123; 2 | 3 | public class Rectangle extends Shape { 4 | 5 | protected double width, length; 6 | 7 | public Rectangle() { 8 | super(); 9 | length = 0; 10 | width = 0; 11 | } 12 | 13 | public Rectangle(String colour, boolean filled, double width, double length) { 14 | super(colour, filled); 15 | this.width = width; 16 | this.length = length; 17 | } 18 | 19 | public Rectangle(double width, double length) { 20 | super(); 21 | this.width = width; 22 | this.length = length; 23 | } 24 | 25 | public double getWidth() { 26 | return width; 27 | } 28 | 29 | public void setWidth(double width) { 30 | this.width = width; 31 | } 32 | 33 | public double getLength() { 34 | return length; 35 | } 36 | 37 | public void setLength(double length) { 38 | this.length = length; 39 | } 40 | 41 | @Override 42 | public double getArea() { 43 | return width * length; 44 | } 45 | 46 | @Override 47 | public double getPerimeter() { 48 | return 2 * (width + length); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "Rectangle{" + 54 | "width=" + width + 55 | ", length=" + length + 56 | ", colour='" + color + '\'' + 57 | ", filled=" + filled + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pract7/src/ru/mirea/ikbo1218/grachev/ex3/Game.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | import java.util.ArrayDeque; 4 | import java.util.Deque; 5 | import java.util.Queue; 6 | 7 | public class Game { 8 | Deque fp, sp; 9 | 10 | public Game(String fp, String sp) { 11 | this.fp = new ArrayDeque<>(); 12 | this.sp = new ArrayDeque<>(); 13 | for(int i = 0; i < 5; i ++){ 14 | this.fp.add(Integer.parseInt(fp.substring(i, i+1))); 15 | this.sp.add(Integer.parseInt(sp.substring(i, i+1))); 16 | } 17 | } 18 | 19 | public String play(){ 20 | int count = 0; 21 | while(!fp.isEmpty() && !sp.isEmpty() && count < 106){ 22 | if(fp.peek() > sp.peek() 23 | && sp.peek() != 0){ 24 | fp.add(fp.remove()); 25 | fp.add(sp.remove()); 26 | 27 | }else{ 28 | sp.add(fp.remove()); 29 | sp.add(sp.remove()); 30 | } 31 | count++; 32 | } 33 | String res = ""; 34 | if(fp.isEmpty()) res += "second "; 35 | else if (sp.isEmpty()) res += "first "; 36 | res += count; 37 | if(count >= 106) res += " botva"; 38 | return res; 39 | } 40 | 41 | public static void main(String[] args) { 42 | System.out.println(new Game("13579", "24680").play()); 43 | System.out.println(new Game("12345", "67890").play()); 44 | System.out.println(new Game("13029", "42685").play()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Lab2/src/ru/mirea/ikbo1218/grachev/TestBook.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class TestBook { 4 | public static void main(String[] args) { 5 | Book b1 = new Book(); 6 | System.out.println("Книга, созданная конструктором по умолчанию:"); 7 | System.out.println(b1); 8 | Book b2 = new Book("Война и мир", "Лев Николаевич Толстой"); 9 | System.out.println("Книга, созданная конструктором с частичной инициализацией:"); 10 | System.out.println(b2); 11 | Book b3 = new Book("Длинное название", "Известный Автор", "Большое издательство", 15000, 1865); 12 | System.out.println("Книга, созданная консруктором со всеми полями:"); 13 | System.out.println(b3); 14 | try{ 15 | System.out.println("Попытка изменить количество экземпляров на отрицательное число:"); 16 | b3.setEdition(-12); 17 | }catch (IllegalArgumentException e){ 18 | System.out.println(e.toString()); 19 | } 20 | System.out.println("Изменение количества экземпляров на 0:"); 21 | b3.setEdition(0); 22 | System.out.println(b3); 23 | System.out.println("Publisher = " + b3.getPublisher()); 24 | System.out.println("Publish Year = " + b3.getPublishYear()); 25 | System.out.println("Изменение количества экземпляров на 100:"); 26 | b3.setEdition(100); 27 | System.out.println(b3); 28 | System.out.println("Publisher = " + b3.getPublisher()); 29 | System.out.println("Publish Year = " + b3.getPublishYear()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/exceptons/AlcoholForNotMatureCustomerException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.menu.Alcoholable; 5 | import ru.mirea.ikbo1218.grachev.menu.Drink; 6 | 7 | public abstract class AlcoholForNotMatureCustomerException extends IllegalArgumentException{ 8 | private Customer c; 9 | private Drink[] alcoholables; 10 | 11 | public AlcoholForNotMatureCustomerException(Customer c, Drink alcoholable){ 12 | this(c, new Drink[]{alcoholable}); 13 | } 14 | 15 | public AlcoholForNotMatureCustomerException(Customer c, Drink[] alcoholables){ 16 | this.c = c; 17 | this.alcoholables = alcoholables; 18 | } 19 | 20 | @Override 21 | public String getMessage(){ 22 | StringBuilder sb = new StringBuilder("Покупатель "); 23 | sb.append(c.toString()).append(" попытался заказть "); 24 | if(alcoholables.length > 1){ 25 | sb.append("следующие позиции меню, содержащие алкоголь:\n"); 26 | }else sb.append("следующий элемент меню, содержащий алкоголь: "); 27 | for (Drink drink: alcoholables) { 28 | sb.append(drink.getType()).append(", градус = ").append(drink.getAlcoholVol()).append(".\n"); 29 | } 30 | sb.append("Продажа алкогольной продукции несовершеннолетним запрещена!\n"); 31 | return sb.toString(); 32 | } 33 | @Override 34 | public String getLocalizedMessage(){ 35 | return this.getMessage(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/exceptons/AlcoholForNotMatureCustomerException.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exceptons; 2 | 3 | import ru.mirea.ikbo1218.grachev.customers.Customer; 4 | import ru.mirea.ikbo1218.grachev.menu.Alcoholable; 5 | import ru.mirea.ikbo1218.grachev.menu.Drink; 6 | 7 | public abstract class AlcoholForNotMatureCustomerException extends IllegalArgumentException{ 8 | private Customer c; 9 | private Drink[] alcoholables; 10 | 11 | public AlcoholForNotMatureCustomerException(Customer c, Drink alcoholable){ 12 | this(c, new Drink[]{alcoholable}); 13 | } 14 | 15 | public AlcoholForNotMatureCustomerException(Customer c, Drink[] alcoholables){ 16 | this.c = c; 17 | this.alcoholables = alcoholables; 18 | } 19 | 20 | @Override 21 | public String getMessage(){ 22 | StringBuilder sb = new StringBuilder("Покупатель "); 23 | sb.append(c.toString()).append(" попытался заказть "); 24 | if(alcoholables.length > 1){ 25 | sb.append("следующие позиции меню, содержащие алкоголь:\n"); 26 | }else sb.append("следующий элемент меню, содержащий алкоголь: "); 27 | for (Drink drink: alcoholables) { 28 | sb.append(drink.getType()).append(", градус = ").append(drink.getAlcoholVol()).append(".\n"); 29 | } 30 | sb.append("Продажа алкогольной продукции несовершеннолетним запрещена!\n"); 31 | return sb.toString(); 32 | } 33 | @Override 34 | public String getLocalizedMessage(){ 35 | return this.getMessage(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /pract1/src/ru/mirea/ikbo1218/grachev/ex3/TestBook.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | public class TestBook { 4 | public static void main(String[] args) { 5 | Book b1 = new Book(); 6 | System.out.println("Книга, созданная конструктором по умолчанию:"); 7 | System.out.println(b1); 8 | Book b2 = new Book("Война и мир", "Лев Николаевич Толстой"); 9 | System.out.println("Книга, созданная конструктором с частичной инициализацией:"); 10 | System.out.println(b2); 11 | Book b3 = new Book("Длинное название", "Известный Автор", "Большое издательство", 15000, 1865); 12 | System.out.println("Книга, созданная консруктором со всеми полями:"); 13 | System.out.println(b3); 14 | try{ 15 | System.out.println("Попытка изменить количество экземпляров на отрицательное число:"); 16 | b3.setEdition(-12); 17 | }catch (IllegalArgumentException e){ 18 | System.out.println(e.toString()); 19 | } 20 | System.out.println("Изменение количества экземпляров на 0:"); 21 | b3.setEdition(0); 22 | System.out.println(b3); 23 | System.out.println("Publisher = " + b3.getPublisher()); 24 | System.out.println("Publish Year = " + b3.getPublishYear()); 25 | System.out.println("Изменение количества экземпляров на 100:"); 26 | b3.setEdition(100); 27 | System.out.println(b3); 28 | System.out.println("Publisher = " + b3.getPublisher()); 29 | System.out.println("Publish Year = " + b3.getPublishYear()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Pract12/src/ru/mirea/ikbo1218/grachev/ex3/Shirt.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | public class Shirt { 4 | private String article, fullName, color, size; 5 | 6 | public Shirt(String stringToParse){ 7 | String[] s = stringToParse.split(","); 8 | article = s[0]; 9 | fullName = s[1]; 10 | color = s[2]; 11 | size = s[3]; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return "Shirt:\n" + 17 | "\tarticle='" + article + '\'' + 18 | "\n\tfullName='" + fullName + '\'' + 19 | "\n\tcolor='" + color + '\'' + 20 | "\n\tsize='" + size + '\''; 21 | } 22 | 23 | public static void main(String[] args) { 24 | String[] strs = new String[]{ 25 | "S001,Black Polo Shirt,Black,XL", 26 | "S002,Black Polo Shirt,Black,L", 27 | "S003,Blue Polo Shirt,Blue,XL", 28 | "S004,Blue Polo Shirt,Blue,M", 29 | "S005,Tan Polo Shirt,Tan,XL", 30 | "S006,Black T-Shirt,Black,XL", 31 | "S007,White T-Shirt,White,XL", 32 | "S008,White T-Shirt,White,L", 33 | "S009,Green T-Shirt,Green,S", 34 | "S010,Orange T-Shirt,Orange,S", 35 | "S011,Maroon Polo Shirt,Maroon,S" 36 | }; 37 | Shirt[] shirts = new Shirt[strs.length]; 38 | for (int i = 0; i < strs.length; i++) { 39 | shirts[i] = new Shirt(strs[i]); 40 | System.out.println(shirts[i]); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Lab3/src/ru/mirea/ikbo1218/grachev/FurnitureShop.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class FurnitureShop { 4 | private Furniture[] goods; 5 | 6 | public FurnitureShop(int count) { 7 | goods = new Furniture[count]; 8 | for (int i = 0; i < count; ) { 9 | goods[i++] = new Chair("Стандартная модель", 1.7, 0.4, 0.4, "Ткань", "Дерево", true, 1300); 10 | if(i >= count) break; 11 | goods[i++] = new Table("Стандартная модель", 4, 1.65, 3.1, 1.9, 2700, "Дерево", 3); 12 | if (i >= count)break; 13 | goods[i++] = new Bed("Стандартная модель", 0.8, 2, 3, 7400, 2, 14 | 230, "Дерево", "Овечья шерсть"); 15 | } 16 | } 17 | 18 | public Furniture[] getGoods() { 19 | return goods; 20 | } 21 | 22 | public void add(Furniture f){ 23 | Furniture[] tmp = new Furniture[goods.length+1]; 24 | System.arraycopy(goods, 0, tmp, 0, goods.length); 25 | tmp[goods.length] = f; 26 | goods = tmp; 27 | } 28 | 29 | public Furniture buy(int number){ 30 | Furniture f = goods[number]; 31 | Furniture[] tmp = new Furniture[goods.length-1]; 32 | for (int i = 0; i < goods.length; i++){ 33 | if(i < number) tmp[i] = goods[i]; 34 | if (i > number) tmp[i-1] = goods[i]; 35 | } 36 | goods = tmp; 37 | return f; 38 | } 39 | 40 | public String getPrices(){ 41 | String res = "Магазин продаёт следующие товары:\n\n"; 42 | for (Furniture f : goods) { 43 | res += f.toString() + "\n"; 44 | } 45 | 46 | return res; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Lab3/src/ru/mirea/ikbo1218/grachev/Chair.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Chair extends Furniture { 4 | 5 | private String backseatMaterial, mainMaterial; 6 | private boolean isCircle; 7 | 8 | public Chair(String modelName, double height, double width, double depth, String backseatMaterial, String mainMaterial, boolean isCircle, int price) { 9 | super(4, height, width, depth, true, price, modelName); 10 | this.backseatMaterial = backseatMaterial; 11 | this.mainMaterial = mainMaterial; 12 | this.isCircle = isCircle; 13 | } 14 | 15 | public String getBackseatMaterial() { 16 | return backseatMaterial; 17 | } 18 | 19 | public void setBackseatMaterial(String backseatMaterial) { 20 | this.backseatMaterial = backseatMaterial; 21 | } 22 | 23 | public String getMainMaterial() { 24 | return mainMaterial; 25 | } 26 | 27 | public void setMainMaterial(String mainMaterial) { 28 | this.mainMaterial = mainMaterial; 29 | } 30 | 31 | public boolean isCircle() { 32 | return isCircle; 33 | } 34 | 35 | public void setCircle(boolean circle) { 36 | isCircle = circle; 37 | } 38 | 39 | @Override 40 | public void jumpOn() { 41 | System.out.println("Ouch! Стул сломался, когда вы попытались на нём прыгать!"); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "Chair{" + 47 | "backseatMaterial='" + backseatMaterial + '\'' + 48 | ", mainMaterial='" + mainMaterial + '\'' + 49 | ", isCircle=" + isCircle + 50 | ", " + super.toString() + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /pract7/src/ru/mirea/ikbo1218/grachev/ex1/Game.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | import java.util.Stack; 4 | 5 | public class Game { 6 | Stack fp, sp; 7 | 8 | public Game(String fp, String sp) { 9 | this.fp = new Stack<>(); 10 | this.sp = new Stack<>(); 11 | for(int i = 4; i >= 0; i --){ 12 | this.fp.push(Integer.parseInt(fp.substring(i, i+1))); 13 | this.sp.push(Integer.parseInt(sp.substring(i, i+1))); 14 | } 15 | } 16 | 17 | private void pushBack(Stack s, Integer item){ 18 | Stack ns = new Stack<>(); 19 | while (!s.isEmpty()) 20 | ns.push(s.pop()); 21 | s.push(item); 22 | while (!ns.isEmpty()) 23 | s.push(ns.pop()); 24 | } 25 | 26 | public String play(){ 27 | int count = 0; 28 | while(!fp.isEmpty() && !sp.isEmpty() && count <= 106){ 29 | if(fp.peek() > sp.peek() 30 | && sp.peek() != 0){ 31 | pushBack(fp, fp.pop()); 32 | pushBack(fp, sp.pop()); 33 | }else{ 34 | pushBack(sp, fp.pop()); 35 | pushBack(sp, sp.pop()); 36 | } 37 | count++; 38 | } 39 | String res = ""; 40 | if(fp.isEmpty()) res += "second "; 41 | else res += "first "; 42 | res += count; 43 | if(count >= 106) res += " botva"; 44 | return res; 45 | } 46 | 47 | public static void main(String[] args) { 48 | System.out.println(new Game("13579", "24680").play()); 49 | System.out.println(new Game("12345", "67890").play()); 50 | System.out.println(new Game("13029", "42685").play()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /lab6/src/ru/mirea/ikbo1218/gracev/lab6.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.gracev; 2 | 3 | import javax.swing.JComboBox; 4 | import javax.swing.JFrame; 5 | import javax.swing.JTextArea; 6 | import javax.swing.WindowConstants; 7 | import java.awt.BorderLayout; 8 | import java.awt.Color; 9 | import java.awt.Font; 10 | 11 | public class lab6 extends JFrame { 12 | 13 | private lab6(){ 14 | setSize(720, 480); 15 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 16 | 17 | JTextArea ta = new JTextArea(); 18 | ta.setFont(new Font("Times New Roman", Font.PLAIN, 12)); 19 | 20 | String[] colors = {"Черный", "Красный", "Синий"}; 21 | JComboBox cols = new JComboBox<>(colors); 22 | cols.setSelectedIndex(0); 23 | 24 | String[] f = {"Times New Roman", "MS Sans Serif", "Courier New"}; 25 | JComboBox fonts = new JComboBox<>(f); 26 | fonts.setSelectedIndex(0); 27 | 28 | fonts.addItemListener(e -> ta.setFont(new Font(f[fonts.getSelectedIndex()], Font.PLAIN, 12))); 29 | 30 | cols.addItemListener(e -> { 31 | Color c; 32 | switch (cols.getSelectedIndex()){ 33 | case 1: 34 | c = Color.RED; 35 | break; 36 | case 2: 37 | c = Color.BLUE; 38 | break; 39 | default: c = Color.BLACK; 40 | } 41 | ta.setForeground(c); 42 | }); 43 | 44 | getContentPane().add(cols, BorderLayout.NORTH); 45 | getContentPane().add(fonts, BorderLayout.SOUTH); 46 | getContentPane().add(ta); 47 | 48 | } 49 | 50 | public static void main(String[] args) { 51 | new lab6().setVisible(true); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Pract9/src/ru/mirea/ikbo1218/grachev/ex2/Student.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | public class Student implements Comparable{ 4 | private String fio; 5 | private int avgPoint, groupNum, age; 6 | 7 | public static final AgeComparator AGE_COMP = new AgeComparator(); 8 | public static final AvgComparator AVG_COMP = new AvgComparator(); 9 | public static final GroupComparator GROUP_COMP = new GroupComparator(); 10 | 11 | public Student(String fio, int avgPoint, int groupNum, int age) { 12 | this.fio = fio; 13 | this.avgPoint = avgPoint; 14 | this.groupNum = groupNum; 15 | this.age = age; 16 | } 17 | 18 | public String getFio() { 19 | return fio; 20 | } 21 | 22 | public void setFio(String fio) { 23 | if(fio.equals("")) 24 | throw new EmptyStringException(); 25 | this.fio = fio; 26 | } 27 | 28 | public int getAvgPoint() { 29 | return avgPoint; 30 | } 31 | 32 | public void setAvgPoint(int avgPoint) { 33 | this.avgPoint = avgPoint; 34 | } 35 | 36 | public int getGroupNum() { 37 | return groupNum; 38 | } 39 | 40 | public void setGroupNum(int groupNum) { 41 | this.groupNum = groupNum; 42 | } 43 | 44 | public int getAge() { 45 | return age; 46 | } 47 | 48 | public void setAge(int age) { 49 | this.age = age; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Student{" + 55 | "fio='" + fio + '\'' + 56 | ", avgPoint=" + avgPoint + 57 | ", groupNum=" + groupNum + 58 | ", age=" + age + 59 | '}'; 60 | } 61 | 62 | @Override 63 | public int compareTo(Student o) { 64 | return this.fio.compareTo(o.fio); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/customers/Customer.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.customers; 2 | 3 | public class Customer { 4 | private String firstName, secondName; 5 | private int age; 6 | private Address address; 7 | 8 | private static final int MATURE_AGE = 18; 9 | 10 | public static final Customer MATURE_UNKNOWN_CUSTOMER = new Customer("", "", MATURE_AGE, Address.EMPTY_ADDRESS); 11 | public static final Customer NOT_MATURE_UNKNOWN_CUSTOMER = new Customer("", "", MATURE_AGE-1, Address.EMPTY_ADDRESS); 12 | 13 | public Customer(int age) { 14 | this("", "", age, Address.EMPTY_ADDRESS); 15 | } 16 | 17 | public Customer(String firstName, String secondName, int age, Address address) { 18 | this.firstName = firstName; 19 | this.secondName = secondName; 20 | this.age = age; 21 | this.address = address; 22 | } 23 | 24 | public String getFirstName() { 25 | return firstName; 26 | } 27 | 28 | public String getSecondName() { 29 | return secondName; 30 | } 31 | 32 | public int getAge() { 33 | return age; 34 | } 35 | 36 | public Address getAddress() { 37 | return address; 38 | } 39 | 40 | public boolean isMature(){ 41 | return age >= MATURE_AGE; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | StringBuilder sb = new StringBuilder(); 47 | if(!this.firstName.equals(MATURE_UNKNOWN_CUSTOMER.firstName)) sb.append(this.firstName).append(" "); 48 | if(!this.secondName.equals(MATURE_UNKNOWN_CUSTOMER.secondName)) sb.append(this.secondName).append(" "); 49 | if(sb.length() != 0) sb.replace(sb.length()-1, sb.length()-1, ", возраст: ").append(age); 50 | else sb.append("Неизвестный покупатель, возраст: ").append(age); 51 | return sb.toString(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/customers/Customer.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.customers; 2 | 3 | public class Customer { 4 | private String firstName, secondName; 5 | private int age; 6 | private Address address; 7 | 8 | private static final int MATURE_AGE = 18; 9 | 10 | public static final Customer MATURE_UNKNOWN_CUSTOMER = new Customer("", "", MATURE_AGE, Address.EMPTY_ADDRESS); 11 | public static final Customer NOT_MATURE_UNKNOWN_CUSTOMER = new Customer("", "", MATURE_AGE-1, Address.EMPTY_ADDRESS); 12 | 13 | public Customer(int age) { 14 | this("", "", age, Address.EMPTY_ADDRESS); 15 | } 16 | 17 | public Customer(String firstName, String secondName, int age, Address address) { 18 | this.firstName = firstName; 19 | this.secondName = secondName; 20 | this.age = age; 21 | this.address = address; 22 | } 23 | 24 | public String getFirstName() { 25 | return firstName; 26 | } 27 | 28 | public String getSecondName() { 29 | return secondName; 30 | } 31 | 32 | public int getAge() { 33 | return age; 34 | } 35 | 36 | public Address getAddress() { 37 | return address; 38 | } 39 | 40 | public boolean isMature(){ 41 | return age >= MATURE_AGE; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | StringBuilder sb = new StringBuilder(); 47 | if(!this.firstName.equals(MATURE_UNKNOWN_CUSTOMER.firstName)) sb.append(this.firstName).append(" "); 48 | if(!this.secondName.equals(MATURE_UNKNOWN_CUSTOMER.secondName)) sb.append(this.secondName).append(" "); 49 | if(sb.length() != 0) sb.replace(sb.length()-1, sb.length()-1, ", возраст: ").append(age); 50 | else sb.append("Неизвестный покупатель, возраст: ").append(age); 51 | return sb.toString(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/gui/InternetUserWindow.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.gui; 2 | 3 | import ru.mirea.ikbo1218.grachev.gui.parts.GeneralMenu; 4 | import ru.mirea.ikbo1218.grachev.gui.parts.OrderPane; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | public class InternetUserWindow extends JFrame { 10 | 11 | public InternetUserWindow(){ 12 | setSize(640, 480); 13 | setDefaultCloseOperation(HIDE_ON_CLOSE); 14 | 15 | var op = new OrderPane(-1); 16 | getContentPane().add(op, BorderLayout.CENTER); 17 | var save = new JButton("Сохранить"); 18 | save.addActionListener(e->{ 19 | String [][] ord = new String[op.getTabCount()-1][]; 20 | for(int i = 0; i < op.getTabCount()-1; i++){ 21 | ord[i] = ((OrderPane.MenuItemPanel)op.getComponentAt(i)).getData(); 22 | } 23 | Controller.getInstance().addOrder(ord); 24 | }); 25 | getContentPane().add(save, BorderLayout.SOUTH); 26 | 27 | setJMenuBar(new GeneralMenu(this, new JMenu[0])); 28 | } 29 | 30 | public String[] askCustomer(){ 31 | String [] res = new String[9]; 32 | res[0] = JOptionPane.showInputDialog("Ваше имя: "); 33 | res[1] = JOptionPane.showInputDialog("Ваша фамилия: "); 34 | res[2] = JOptionPane.showInputDialog("Ваш возраст: "); 35 | res[3] = JOptionPane.showInputDialog("Город вашего проживания: "); 36 | res[4] = JOptionPane.showInputDialog("ZipCode вашего проживания: "); 37 | res[5] = JOptionPane.showInputDialog("Улица вашего проживания: "); 38 | res[6] = JOptionPane.showInputDialog("Дом вашего проживания: "); 39 | res[7] = JOptionPane.showInputDialog("Буква дома вашего проживания: "); 40 | res[8] = JOptionPane.showInputDialog("Квартира вашего проживания: "); 41 | return res; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Pract8/src/ru/mirea/ikbo1218/grachev/Main.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * Main class for starting program and tests. 7 | */ 8 | public class Main { 9 | 10 | public static void main(String[] args) { 11 | ArrayList al = new ArrayList<>(); 12 | al.add("Hi2"); 13 | al.add("Hi3"); 14 | 15 | WaitList wl = new WaitList<>(); 16 | wl.add("Hi"); 17 | wl.add("Hi2"); 18 | wl.add("Hi3"); 19 | System.out.println(wl); 20 | System.out.println(wl.remove()); 21 | System.out.println(wl); 22 | System.out.println(wl.isEmpty()); 23 | System.out.println(wl.contains("Hi")); 24 | System.out.println(wl.containsAll(al)); 25 | 26 | System.out.println(); 27 | 28 | BoundedWaitList bwl = new BoundedWaitList<>(3); 29 | bwl.add("foo"); 30 | bwl.add("foo2"); 31 | bwl.add("bar"); 32 | System.out.println(bwl); 33 | try{ 34 | bwl.add("bar2"); 35 | }catch (Exception e){ 36 | e.printStackTrace(); 37 | } 38 | System.out.println(); 39 | System.out.println(bwl); 40 | System.out.println(bwl.getCapacity()); 41 | 42 | System.out.println(); 43 | bwl = new BoundedWaitList(al); 44 | System.out.println(bwl.getCapacity()); 45 | try{ 46 | bwl.add("bar2"); 47 | }catch (Exception e){ 48 | e.printStackTrace(); 49 | } 50 | 51 | System.out.println(); 52 | 53 | UnfairWaitList uwl = new UnfairWaitList<>(); 54 | uwl.add(1); 55 | uwl.add(2); 56 | uwl.add(23); 57 | uwl.add(5); 58 | uwl.add(5); 59 | uwl.add(6); 60 | System.out.println(uwl); 61 | uwl.remove(5); 62 | System.out.println(uwl); 63 | uwl.moveToBack(23); 64 | System.out.println(uwl); 65 | 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Pract8/src/ru/mirea/ikbo1218/grachev/UnfairWaitList.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | /** 4 | * Class of queue with added functionality:
5 | *
    6 | *
  • Removing element from any place of queue by its value;
  • 7 | *
  • Moving element (find in queue by value) to the end of queue.
  • 8 | *

9 | * At all other sides it is simply {@link WaitList}. 10 | * @param Type of stored data. 11 | * @see WaitList 12 | * @author aleksandrgracev 13 | * @version 1.0 14 | */ 15 | public class UnfairWaitList extends WaitList { 16 | 17 | /** 18 | * Constructor - creates empty queue. 19 | * @see WaitList#WaitList() 20 | */ 21 | public UnfairWaitList() { 22 | super(); 23 | } 24 | 25 | /** 26 | * Method for removing element from queue by its value.
27 | * Difficulty - O(n). 28 | * @param element Value for search and removing. 29 | * @see WaitList#remove() 30 | */ 31 | public void remove (E element){ 32 | // components.remove(element) 33 | boolean removed = false; 34 | for(int i = 0; i < components.size(); i++){ 35 | E el = components.remove(); 36 | if(!removed && el.equals(element)){ 37 | removed = true; // i-- 38 | }else{ 39 | components.add(el); 40 | } 41 | } 42 | if(removed){ 43 | components.add(components.remove()); 44 | } 45 | } 46 | 47 | /** 48 | * Method for moving element to the end of queue.
49 | * Uses {@link UnfairWaitList#remove(Object)} and (if something was removed) {@link WaitList#add(Object)}. 50 | * @param element Value to move. 51 | */ 52 | public void moveToBack(E element){ 53 | int prevSize = components.size(); 54 | remove(element); 55 | if(components.size() < prevSize){ 56 | components.add(element); 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Pract12/src/ru/mirea/ikbo1218/grachev/ex5/WordConcatenator.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex5; 2 | 3 | import java.io.FileReader; 4 | import java.io.IOException; 5 | import java.util.*; 6 | 7 | public class WordConcatenator { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String path = sc.nextLine(); 11 | StringBuilder s = new StringBuilder(); 12 | try(FileReader fr = new FileReader(path)){ 13 | int c; 14 | while((c=fr.read())!=-1){ 15 | s.append((char) c); 16 | } 17 | }catch (IOException e){ 18 | e.printStackTrace(); 19 | } 20 | System.out.println(getLine(s.toString())); 21 | } 22 | 23 | private static String getLine(String s) { 24 | Queue toAdd = new ArrayDeque<>(Arrays.asList(s.split(" "))); 25 | Set added = new HashSet<>(); 26 | added.add(toAdd.peek()); 27 | StringBuilder sb = new StringBuilder(toAdd.remove()); 28 | boolean wasAdded = true; 29 | 30 | while(!toAdd.isEmpty() && wasAdded){ 31 | wasAdded = false; 32 | int i = 0; 33 | for (; i < toAdd.size(); i++) { 34 | String cur = toAdd.remove(); 35 | if(added.contains(cur)) continue; 36 | if(cur.startsWith(sb.substring(sb.length()-1).toLowerCase()) || 37 | cur.startsWith(sb.substring(sb.length()-1).toUpperCase())){ 38 | sb.append(" ").append(cur); 39 | wasAdded = true; 40 | added.add(cur); 41 | break; 42 | } 43 | toAdd.add(cur); 44 | } 45 | for(; i< toAdd.size(); i++){ 46 | String cur = toAdd.remove(); 47 | if(added.contains(cur)) continue; 48 | toAdd.add(cur); 49 | } 50 | } 51 | return sb.toString(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Lab3/src/ru/mirea/ikbo1218/grachev/Bed.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Bed extends Furniture { 4 | private int personCount, maxWeight; 5 | private String mainMaterial, mattressMaterial; 6 | 7 | public Bed(String modelName, double height, double width, double depth, int price, 8 | int personCount, int maxWeight, String mainMaterial, String mattressMaterial) { 9 | super(4, height, width, depth, true, price, modelName); 10 | if(personCount <= 0 || personCount >=4) 11 | throw new IllegalArgumentException("Невозможное число спальных мест для кровати: " + personCount); 12 | this.personCount = personCount; 13 | this.maxWeight = maxWeight; 14 | this.mainMaterial = mainMaterial; 15 | this.mattressMaterial = mattressMaterial; 16 | } 17 | 18 | public int getPersonCount() { 19 | return personCount; 20 | } 21 | 22 | public void setPersonCount(int personCount) { 23 | this.personCount = personCount; 24 | } 25 | 26 | public int getMaxWeight() { 27 | return maxWeight; 28 | } 29 | 30 | public void setMaxWeight(int maxWeight) { 31 | this.maxWeight = maxWeight; 32 | } 33 | 34 | public String getMainMaterial() { 35 | return mainMaterial; 36 | } 37 | 38 | public void setMainMaterial(String mainMaterial) { 39 | this.mainMaterial = mainMaterial; 40 | } 41 | 42 | public String getMattressMaterial() { 43 | return mattressMaterial; 44 | } 45 | 46 | public void setMattressMaterial(String mattressMaterial) { 47 | this.mattressMaterial = mattressMaterial; 48 | } 49 | 50 | @Override 51 | public void jumpOn() { 52 | System.out.println("Прыгать на кровати весело! Но долго ли она выдержит?"); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "Bed{" + 58 | "personCount=" + personCount + 59 | ", maxWeight=" + maxWeight + 60 | ", mainMaterial='" + mainMaterial + '\'' + 61 | ", mattressMaterial='" + mattressMaterial + '\'' + 62 | ", " + super.toString() + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Pract12/src/ru/mirea/ikbo1218/grachev/ex2/Address.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex2; 2 | 3 | import java.util.StringTokenizer; 4 | 5 | public class Address { 6 | private String country, region, city, street, house, housing, flat; 7 | 8 | public Address(String stringToParse, boolean multiDivider){ 9 | if(stringToParse == null) throw new NullPointerException(); 10 | String[] s; 11 | if(multiDivider){ 12 | StringTokenizer st = new StringTokenizer(stringToParse, ",.;"); 13 | s = new String[st.countTokens()]; 14 | int i = 0; 15 | while(st.hasMoreTokens()) s[i++] = st.nextToken(); 16 | }else{ 17 | s = stringToParse.split(","); 18 | } 19 | 20 | if(s.length < 7) throw new IllegalArgumentException("Строка содержит недостаточно данных!"); 21 | country = s[0].trim(); 22 | region = s[1].trim(); 23 | city = s[2].trim(); 24 | street = s[3].trim(); 25 | house = s[4].trim(); 26 | housing = s[5].trim(); 27 | flat = s[6].trim(); 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "Address{" + 33 | "country='" + country + '\'' + 34 | ", region='" + region + '\'' + 35 | ", city='" + city + '\'' + 36 | ", street='" + street + '\'' + 37 | ", house='" + house + '\'' + 38 | ", housing='" + housing + '\'' + 39 | ", flat='" + flat + '\'' + 40 | '}'; 41 | } 42 | 43 | public static void main(String[] args) { 44 | Address a1 = new Address("Россия, МО , Москва, проспект Вернадского, 78, 7, Г-226-1", false); 45 | Address a2 = new Address("USSR, Leningradskaya oblast', Leningrad. Nevskiy prospect; 234;1;23", true); 46 | Address a3 = new Address("UK, London, London, Trafalgar square, 2, 3, 4, other string,,,", false); 47 | Address a4 = new Address("Страна; регион; город . Улица, дом, корпус. Квартира", true); 48 | 49 | System.out.println(a1); 50 | System.out.println(a2); 51 | System.out.println(a3); 52 | System.out.println(a4); 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/gui/WaitersWindow.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.gui; 2 | 3 | import ru.mirea.ikbo1218.grachev.exceptons.NoFreeTablesException; 4 | import ru.mirea.ikbo1218.grachev.gui.parts.GeneralMenu; 5 | import ru.mirea.ikbo1218.grachev.gui.parts.OrderPane; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | public class WaitersWindow extends JFrame { 11 | 12 | private JTabbedPane wTables; 13 | 14 | public WaitersWindow(){ 15 | setSize(860, 320); 16 | setDefaultCloseOperation(HIDE_ON_CLOSE); 17 | 18 | wTables = new JTabbedPane(); 19 | wTables.setTabPlacement(SwingConstants.RIGHT); 20 | var newGuest = new JButton("Обслужить гостя"); 21 | newGuest.addActionListener(e->{ 22 | int[] tn; 23 | try{ 24 | tn = Controller.getInstance().getFreeNums(); 25 | }catch (NoFreeTablesException ex){ 26 | JOptionPane.showMessageDialog(this, ex.getMessage()); 27 | return; 28 | } 29 | Integer[] tno = new Integer[tn.length]; 30 | for (int i = 0; i < tn.length; i++) { 31 | tno[i] = tn[i]+1; 32 | } 33 | Integer t = (Integer) JOptionPane.showInputDialog(this, "Укажите столик: ", "Начать обработку заказа", JOptionPane.INFORMATION_MESSAGE, null, tno, tno[0]); 34 | try{ 35 | Controller.getInstance().addOrder(t-1, JOptionPane.showConfirmDialog(this, "Гость - совершеннолетний?", "Начало работы с клиентом", JOptionPane.YES_NO_OPTION) == 0); 36 | }catch (NullPointerException ignored){} 37 | 38 | wTables.addTab("Столик № "+t, new OrderPane(t-1)); 39 | 40 | }); 41 | 42 | getContentPane().add(newGuest, BorderLayout.NORTH); 43 | getContentPane().add(wTables, BorderLayout.CENTER); 44 | 45 | setJMenuBar(new GeneralMenu(this, new JMenu[0])); 46 | } 47 | 48 | public void onRemovedOrder(int tNum){ 49 | for(int i = 0; i < wTables.getTabCount(); i++){ 50 | if(Integer.parseInt(wTables.getTitleAt(i).substring(9)) - 1 == tNum){ 51 | wTables.removeTabAt(i); 52 | break; 53 | } 54 | } } 55 | } 56 | -------------------------------------------------------------------------------- /pract4/src/ru/mirea/ikbo1218/grachev/Practice4.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | -------------------------------------------------------------------------------- /Lab2/src/ru/mirea/ikbo1218/grachev/Book.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public class Book { 4 | private String name, author, publisher; 5 | private int edition, publishYear; 6 | 7 | public Book(String name, String author, String publisher, int edition, int publishYear) { 8 | this.name = name; 9 | this.author = author; 10 | this.publisher = publisher; 11 | this.publishYear = publishYear; 12 | setEdition(edition); 13 | } 14 | 15 | public Book(String name, String author) { 16 | this.name = name; 17 | this.author = author; 18 | setEdition(0); 19 | } 20 | 21 | public Book() { 22 | this.name = "default"; 23 | this.author = "default"; 24 | setEdition(0); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | String res = "Book{" + 30 | "name='" + name + '\'' + 31 | ", author='" + author + '\''; 32 | if(edition > 0) 33 | res += ", publisher='" + publisher + '\'' + 34 | ", edition=" + edition + 35 | ", publishYear=" + publishYear+ 36 | '}'; 37 | else res += ", had not been published yet!}"; 38 | return res; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getAuthor() { 50 | return author; 51 | } 52 | 53 | public void setAuthor(String author) { 54 | this.author = author; 55 | } 56 | 57 | public String getPublisher() { 58 | return edition > 0 ? publisher:"None"; 59 | } 60 | 61 | public void setPublisher(String publisher) { 62 | this.publisher = publisher; 63 | } 64 | 65 | public int getEdition() { 66 | return edition; 67 | } 68 | 69 | public void setPublishYear(int publishYear) { 70 | this.publishYear = publishYear; 71 | } 72 | 73 | public int getPublishYear() { 74 | return edition > 0 ? publishYear : -1; 75 | } 76 | 77 | public void setEdition(int edition) { 78 | if(edition < 0) throw new IllegalArgumentException("Тираж не может быть меньше 0!"); 79 | this.edition = edition; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /pract1/src/ru/mirea/ikbo1218/grachev/ex3/Book.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex3; 2 | 3 | public class Book { 4 | private String name, author, publisher; 5 | private int edition, publishYear; 6 | 7 | public Book(String name, String author, String publisher, int edition, int publishYear) { 8 | this.name = name; 9 | this.author = author; 10 | this.publisher = publisher; 11 | this.publishYear = publishYear; 12 | setEdition(edition); 13 | } 14 | 15 | public Book(String name, String author) { 16 | this.name = name; 17 | this.author = author; 18 | setEdition(0); 19 | } 20 | 21 | public Book() { 22 | this.name = "default"; 23 | this.author = "default"; 24 | setEdition(0); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | String res = "Book{" + 30 | "name='" + name + '\'' + 31 | ", author='" + author + '\''; 32 | if(edition > 0) 33 | res += ", publisher='" + publisher + '\'' + 34 | ", edition=" + edition + 35 | ", publishYear=" + publishYear+ 36 | '}'; 37 | else res += ", had not been published yet!}"; 38 | return res; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getAuthor() { 50 | return author; 51 | } 52 | 53 | public void setAuthor(String author) { 54 | this.author = author; 55 | } 56 | 57 | public String getPublisher() { 58 | return edition > 0 ? publisher:"None"; 59 | } 60 | 61 | public void setPublisher(String publisher) { 62 | this.publisher = publisher; 63 | } 64 | 65 | public int getEdition() { 66 | return edition; 67 | } 68 | 69 | public void setPublishYear(int publishYear) { 70 | this.publishYear = publishYear; 71 | } 72 | 73 | public int getPublishYear() { 74 | return edition > 0 ? publishYear : -1; 75 | } 76 | 77 | public void setEdition(int edition) { 78 | if(edition < 0) throw new IllegalArgumentException("Тираж не может быть меньше 0!"); 79 | this.edition = edition; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Lab16/src/ru/mirea/ikbo1218/grachev/customers/Address.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.customers; 2 | 3 | public class Address { 4 | private String cityName, streetName; 5 | private int zipCode, buildingNumber, apartmentNumber; 6 | private char buildingLetter; 7 | public static final Address EMPTY_ADDRESS = new Address("", 0, "", 0, 0); 8 | 9 | public Address(String cityName, int zipCode, String streetName, int buildingNumber, int apartmentNumber){ 10 | this(cityName, zipCode, streetName, buildingNumber, ' ', apartmentNumber); 11 | } 12 | 13 | public Address(String cityName, int zipCode, String streetName, int buildingNumber, char buildingLetter, int apartmentNumber) { 14 | this.cityName = cityName; 15 | this.streetName = streetName; 16 | this.zipCode = zipCode; 17 | this.buildingNumber = buildingNumber; 18 | this.apartmentNumber = apartmentNumber; 19 | this.buildingLetter = buildingLetter; 20 | } 21 | 22 | public String getCityName() { 23 | return cityName; 24 | } 25 | 26 | public String getStreetName() { 27 | return streetName; 28 | } 29 | 30 | public int getZipCode() { 31 | return zipCode; 32 | } 33 | 34 | public int getBuildingNumber() { 35 | return buildingNumber; 36 | } 37 | 38 | public int getApartmentNumber() { 39 | return apartmentNumber; 40 | } 41 | 42 | public char getBuildingLetter() { 43 | return buildingLetter; 44 | } 45 | 46 | @Override 47 | public String toString(){ 48 | StringBuilder sb = new StringBuilder(); 49 | if(zipCode != 0) sb.append(zipCode); 50 | if(!cityName.equals("")){ 51 | if(sb.length() == 0) sb.append(cityName); 52 | else sb.append(", ").append(cityName); 53 | } 54 | if(!streetName.equals("")) { 55 | if (sb.length() == 0) sb.append("Ул. ").append(streetName); 56 | else sb.append(", ул. ").append(streetName); 57 | } 58 | if(buildingNumber != 0){ 59 | if (sb.length() == 0) sb.append("Дом ").append(buildingNumber); 60 | else sb.append(", дом ").append(buildingNumber); 61 | } 62 | if(buildingLetter!=' ') sb.append("-").append(buildingLetter); 63 | if(apartmentNumber != 0) sb.append(", кв. ").append(apartmentNumber); 64 | 65 | return sb.toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Pract16/src/ru/mirea/ikbo1218/grachev/customers/Address.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.customers; 2 | 3 | public class Address { 4 | private String cityName, streetName; 5 | private int zipCode, buildingNumber, apartmentNumber; 6 | private char buildingLetter; 7 | public static final Address EMPTY_ADDRESS = new Address("", 0, "", 0, 0); 8 | 9 | public Address(String cityName, int zipCode, String streetName, int buildingNumber, int apartmentNumber){ 10 | this(cityName, zipCode, streetName, buildingNumber, ' ', apartmentNumber); 11 | } 12 | 13 | public Address(String cityName, int zipCode, String streetName, int buildingNumber, char buildingLetter, int apartmentNumber) { 14 | this.cityName = cityName; 15 | this.streetName = streetName; 16 | this.zipCode = zipCode; 17 | this.buildingNumber = buildingNumber; 18 | this.apartmentNumber = apartmentNumber; 19 | this.buildingLetter = buildingLetter; 20 | } 21 | 22 | public String getCityName() { 23 | return cityName; 24 | } 25 | 26 | public String getStreetName() { 27 | return streetName; 28 | } 29 | 30 | public int getZipCode() { 31 | return zipCode; 32 | } 33 | 34 | public int getBuildingNumber() { 35 | return buildingNumber; 36 | } 37 | 38 | public int getApartmentNumber() { 39 | return apartmentNumber; 40 | } 41 | 42 | public char getBuildingLetter() { 43 | return buildingLetter; 44 | } 45 | 46 | @Override 47 | public String toString(){ 48 | StringBuilder sb = new StringBuilder(); 49 | if(zipCode != 0) sb.append(zipCode); 50 | if(!cityName.equals("")){ 51 | if(sb.length() == 0) sb.append(cityName); 52 | else sb.append(", ").append(cityName); 53 | } 54 | if(!streetName.equals("")) { 55 | if (sb.length() == 0) sb.append("Ул. ").append(streetName); 56 | else sb.append(", ул. ").append(streetName); 57 | } 58 | if(buildingNumber != 0){ 59 | if (sb.length() == 0) sb.append("Дом ").append(buildingNumber); 60 | else sb.append(", дом ").append(buildingNumber); 61 | } 62 | if(buildingLetter!=' ') sb.append("-").append(buildingLetter); 63 | if(apartmentNumber != 0) sb.append(", кв. ").append(apartmentNumber); 64 | 65 | return sb.toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Pract8/src/ru/mirea/ikbo1218/grachev/BoundedWaitList.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * Class of queue with constant max {@link BoundedWaitList#capacity}. 7 | * @param Type of stored data. 8 | * @see IWaitList 9 | * @see WaitList 10 | * @author aleksandrgracev 11 | * @version 1.2 12 | */ 13 | public class BoundedWaitList extends WaitList { 14 | 15 | /** 16 | * Field for maximum capacity of the queue. 17 | */ 18 | private int capacity; 19 | 20 | /** 21 | * Constructor - creating new object without any data and with maximum capacity. 22 | * @param capacity Maximum {@link BoundedWaitList#capacity} of queue. 23 | * @see WaitList#WaitList() 24 | * @throws IllegalArgumentException Maximum capacity equal or below zero. 25 | */ 26 | public BoundedWaitList(int capacity){ 27 | super(); 28 | if(capacity <= 0) throw new IllegalArgumentException("Максимальный размер должен быть больше 0! Получено значение: " + capacity); 29 | this.capacity = capacity; 30 | } 31 | 32 | 33 | /** 34 | * Overrides constructor of copies from superclass to set max capacity equal to collection's size. 35 | * @param col Collection to copy from 36 | * @see WaitList#WaitList(Collection) 37 | * @since 1.2 38 | */ 39 | public BoundedWaitList(Collection col){ 40 | super(col); 41 | this.capacity = col.size(); 42 | } 43 | 44 | /** 45 | * Method to get property {@link BoundedWaitList#capacity} 46 | * @return Value of {@link BoundedWaitList#capacity} 47 | */ 48 | public int getCapacity() { 49 | return capacity; 50 | } 51 | 52 | /** 53 | * Method to add element into queue (at end). 54 | * @param element Value to be added. 55 | * @throws IllegalStateException Queue is full: reached maximum {@link BoundedWaitList#capacity} 56 | * @see WaitList#add(Object) 57 | */ 58 | @Override 59 | public void add(E element) { 60 | if(components.size() == capacity) throw new IllegalStateException("Очередь заполнена!"); 61 | components.add(element); 62 | } 63 | 64 | /** 65 | * Method to get information about this list in String type. 66 | * @return String-value of this list. 67 | */ 68 | @Override 69 | public String toString() { 70 | return "BoundedWaitList{" + 71 | "capacity=" + capacity + 72 | ", components=" + components + 73 | '}'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Lab10/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 17 | 18 | 19 | 20 | 30 | 31 | 32 | 33 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 1573825983689 58 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /lab8/src/ru/mirea/ikbo1218/grachev/Lab8.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.io.File; 6 | import java.io.FileReader; 7 | import java.io.FileWriter; 8 | import java.io.IOException; 9 | 10 | 11 | public class Lab8 extends JFrame { 12 | 13 | public Lab8(){ 14 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 15 | setSize(480, 320); 16 | 17 | JTextArea ta = new JTextArea(); 18 | 19 | JPanel p = new JPanel(new FlowLayout()); 20 | JButton b1 = new JButton("Прочитать из файла"); 21 | JButton b2 = new JButton("Записать в файл (с заменой содержимого, если существует)"); 22 | JButton b3 = new JButton("Записать в файл (добавить в конец)"); 23 | 24 | p.add(b1); 25 | p.add(b2); 26 | p.add(b3); 27 | 28 | JFileChooser fc = new JFileChooser(); 29 | 30 | b1.addActionListener(e->{ 31 | if(fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){ 32 | File f = fc.getSelectedFile(); 33 | try(FileReader fr = new FileReader(f)){ 34 | StringBuilder msg = new StringBuilder(); 35 | int c; 36 | while ((c = fr.read()) != -1) msg.append((char) c); 37 | ta.setText(msg.toString()); 38 | }catch (IOException ex){ 39 | JOptionPane.showMessageDialog(this, ex.toString()); 40 | } 41 | } 42 | }); 43 | 44 | b2.addActionListener(e->{ 45 | if(fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){ 46 | File f = fc.getSelectedFile(); 47 | try (FileWriter fw = new FileWriter(f)){ 48 | fw.write(ta.getText()); 49 | }catch (IOException ex){ 50 | JOptionPane.showMessageDialog(this, ex.toString()); 51 | } 52 | } 53 | }); 54 | b3.addActionListener(e->{ 55 | if(fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){ 56 | File f = fc.getSelectedFile(); 57 | try (FileWriter fw = new FileWriter(f, true)){ 58 | fw.append(ta.getText()); 59 | }catch (IOException ex){ 60 | JOptionPane.showMessageDialog(this, ex.toString()); 61 | } 62 | } 63 | }); 64 | 65 | getContentPane().add(ta, BorderLayout.NORTH); 66 | getContentPane().add(p, BorderLayout.CENTER); 67 | 68 | setVisible(true); 69 | } 70 | 71 | public static void main(String[] args) { 72 | new Lab8(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Lab3/src/ru/mirea/ikbo1218/grachev/Furniture.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev; 2 | 3 | public abstract class Furniture { 4 | private int legCount; 5 | private double height; 6 | private double width; 7 | private double depth; 8 | private boolean maySeat; 9 | private int price; 10 | private String modelName; 11 | 12 | public Furniture(int legCount, double height, double width, double depth, boolean maySeat, int price, String modelName) { 13 | this.legCount = legCount; 14 | if(height <= 0) 15 | throw new IllegalArgumentException("Высота должна быть больше 0!"); 16 | this.height = height; 17 | if(width <= 0) 18 | throw new IllegalArgumentException("Ширина должна быть больше 0!"); 19 | this.width = width; 20 | if(depth <= 0) 21 | throw new IllegalArgumentException("Глубина должна быть больше 0!"); 22 | this.depth = depth; 23 | this.maySeat = maySeat; 24 | this.price = price; 25 | this.modelName = modelName; 26 | } 27 | 28 | public abstract void jumpOn(); 29 | 30 | public String getModelName() { 31 | return modelName; 32 | } 33 | 34 | public void setModelName(String modelName) { 35 | this.modelName = modelName; 36 | } 37 | 38 | public void setHeight(int height) { 39 | if(height <= 0) 40 | throw new IllegalArgumentException("Высота должна быть больше 0!"); 41 | this.height = height; 42 | } 43 | 44 | public void setWidth(int width) { 45 | if(width <= 0) 46 | throw new IllegalArgumentException("Ширина должна быть больше 0!"); 47 | this.width = width; 48 | } 49 | 50 | public void setDepth(int depth) { 51 | if(depth <= 0) 52 | throw new IllegalArgumentException("Глубина должна быть больше 0!"); 53 | this.depth = depth; 54 | } 55 | 56 | public int getPrice() { 57 | return price; 58 | } 59 | 60 | public void setPrice(int price) { 61 | this.price = price; 62 | } 63 | 64 | public double getHeight() { 65 | return height; 66 | } 67 | 68 | public double getWidth() { 69 | return width; 70 | } 71 | 72 | public double getDepth() { 73 | return depth; 74 | } 75 | 76 | public int getLegCount() { 77 | return legCount; 78 | } 79 | 80 | public boolean isMaySeat() { 81 | return maySeat; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | return "modelName=" + modelName + 87 | ", legCount=" + legCount + 88 | ", height=" + height + 89 | ", width=" + width + 90 | ", depth=" + depth + 91 | ", maySeat=" + maySeat + 92 | ", price=" + price; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Pract11/src/ru/mirea/ikbo1218/grachev/ex1/ArrayQueueModule.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex1; 2 | 3 | import ru.mirea.ikbo1218.grachev.ex2.AbstractQueue; 4 | 5 | // INV: FIFO (First in - first out) 6 | // 0 <= size <= q.length - 1 7 | // queue[head]..queue[tail] - queue 8 | // queue - Singleton 9 | // q.length = 2**x 10 | public class ArrayQueueModule extends AbstractQueue { 11 | private Object[] q; 12 | 13 | private static ArrayQueueModule instance; 14 | 15 | // PRE: queue - null 16 | // POST: queue.size = 0; 17 | // q.length = 16; 18 | private ArrayQueueModule(){ 19 | q = new Object[START_CAPACITY]; 20 | head = tail = 0; 21 | } 22 | 23 | // Pre: none; 24 | // Post: instance - Singleton; 25 | // queue - immutable 26 | public static ArrayQueueModule getInstance(){ 27 | if(instance == null) 28 | instance = new ArrayQueueModule(); 29 | return instance; 30 | } 31 | 32 | // PRE: size > 0 33 | // POST: R = queue[head] 34 | // queue[head] = queue[head+1] 35 | // queue[head+1]..queue[tail] - immutable 36 | @Override 37 | public Object dequeue(){ 38 | if(isEmpty()) throw new IndexOutOfBoundsException("Queue is empty!"); 39 | Object r = q[head++]; 40 | if(head == q.length) head = 0; 41 | if(Math.abs(head-tail) < q.length / 2) resize(q.length / 2); 42 | return r; 43 | } 44 | 45 | // PRE: None 46 | // POST: queue - immutable 47 | // R = (head == tale) 48 | @Override 49 | public boolean isEmpty() { 50 | return head == tail; 51 | } 52 | 53 | // PRE: None 54 | // POST: queue[tail] = element 55 | // queue[head]..queue[tail-1] - immutable 56 | @Override 57 | public void enqueue(Object element){ 58 | q[tail++] = element; 59 | if(tail == q.length) tail = 0; 60 | if(tail == head) resize(q.length * 2); 61 | } 62 | 63 | // Pre: none; 64 | // Post: q.length == nSize; 65 | // queue - immutable; 66 | private void resize(int nSize) { 67 | Object[] nq = new Object[nSize]; 68 | System.arraycopy(q, head, nq, 0, Math.abs(head-tail)); 69 | tail = Math.abs(head-tail); 70 | head = 0; 71 | q = nq; 72 | } 73 | 74 | // PRE: size > 0 75 | // POST: R = queue[head] 76 | // queue - immutable 77 | @Override 78 | public Object element(){ 79 | if(isEmpty()) throw new IndexOutOfBoundsException("Queue is empty!"); 80 | return q[head]; 81 | } 82 | 83 | // PRE: None 84 | // POST: size == 0 85 | // q.length = 16 86 | @Override 87 | public boolean clear(){ 88 | boolean r = !isEmpty(); 89 | head = tail = 0; 90 | resize(START_CAPACITY); 91 | return r; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs45/MovableRectangle.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs45; 2 | 3 | public class MovableRectangle implements Movable { 4 | private MovablePoint topLeft, bottomRight; 5 | 6 | public MovableRectangle(int x1, int y1, int x2, int y2, int xSpeed, int ySpeed) { 7 | topLeft = new MovablePoint(x1, y1, xSpeed, ySpeed); 8 | bottomRight = new MovablePoint(x2, y2, xSpeed, ySpeed); 9 | } 10 | 11 | public void setSpeed(int xSpeed, int ySpeed){ 12 | //method with mistake for checking work of isEquSpeed 13 | topLeft.ySpeed = ySpeed; 14 | topLeft.xSpeed = xSpeed; 15 | } 16 | 17 | private boolean isEquSpeed(){ 18 | return topLeft.xSpeed == bottomRight.xSpeed && topLeft.ySpeed == bottomRight.ySpeed; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "MovableRectangle{" + 24 | "topLeft=MovablePoint{x=" + topLeft.x + ", y="+ topLeft.y+ 25 | "}, bottomRight=MovablePoint{x=" + bottomRight.x + ", y=" + bottomRight.y + 26 | "}, xSpeed = " + topLeft.xSpeed + 27 | ", ySpeed=" + topLeft.ySpeed + 28 | "}"; 29 | } 30 | 31 | @Override 32 | public void moveUp() { 33 | if(!isEquSpeed()) throw new IllegalStateException("Скорости точек прямоугольника не совпадают!\n" + 34 | "topLeft:\n\txSpeed = " + topLeft.xSpeed + "\n\tySpeed = " + topLeft.ySpeed + 35 | "\nbottomRight:\n\txSpeed = " + bottomRight.xSpeed + "\n\tySpeed = " + bottomRight.ySpeed); 36 | topLeft.moveUp(); 37 | bottomRight.moveUp(); 38 | 39 | } 40 | 41 | @Override 42 | public void moveDown() { 43 | if(!isEquSpeed()) throw new IllegalStateException("Скорости точек прямоугольника не совпадают!\n" + 44 | "topLeft:\n\txSpeed = " + topLeft.xSpeed + "\n\tySpeed = " + topLeft.ySpeed + 45 | "\nbottomRight:\n\txSpeed = " + bottomRight.xSpeed + "\n\tySpeed = " + bottomRight.ySpeed); 46 | topLeft.moveDown(); 47 | bottomRight.moveDown(); 48 | 49 | } 50 | 51 | @Override 52 | public void moveLeft() { 53 | if(!isEquSpeed()) throw new IllegalStateException("Скорости точек прямоугольника не совпадают!\n" + 54 | "topLeft:\n\txSpeed = " + topLeft.xSpeed + "\n\tySpeed = " + topLeft.ySpeed + 55 | "\nbottomRight:\n\txSpeed = " + bottomRight.xSpeed + "\n\tySpeed = " + bottomRight.ySpeed); 56 | topLeft.moveLeft(); 57 | bottomRight.moveLeft(); 58 | 59 | } 60 | 61 | @Override 62 | public void moveRight() { 63 | if(!isEquSpeed()) throw new IllegalStateException("Скорости точек прямоугольника не совпадают!\n" + 64 | "topLeft:\n\txSpeed = " + topLeft.xSpeed + "\n\tySpeed = " + topLeft.ySpeed + 65 | "\nbottomRight:\n\txSpeed = " + bottomRight.xSpeed + "\n\tySpeed = " + bottomRight.ySpeed); 66 | topLeft.moveRight(); 67 | bottomRight.moveRight(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /pract3/src/ru/mirea/ikbo1218/grachev/exs123/ShapeTest.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.exs123; 2 | 3 | public class ShapeTest { 4 | public static void main(String[] args) { 5 | Shape s1 = new Circle("RED", false, 5.5); // Upcast Circle to Shape 6 | // Returns of Circle methods, defined in Shape 7 | System.out.println(s1); 8 | System.out.println(s1.getArea()); 9 | System.out.println(s1.getPerimeter()); 10 | System.out.println(s1.getColor()); 11 | System.out.println(s1.isFilled()); 12 | //System.out.println(s1.getRadius()); // Not in Shape 13 | 14 | System.out.println(); 15 | 16 | Circle c1 = (Circle)s1; // Downcast back to Circle 17 | // Returns of Circle methods 18 | System.out.println(c1); 19 | System.out.println(c1.getArea()); 20 | System.out.println(c1.getPerimeter()); 21 | System.out.println(c1.getColor()); 22 | System.out.println(c1.isFilled()); 23 | System.out.println(c1.getRadius()); 24 | 25 | 26 | System.out.println(); 27 | //Shape s2 = new Shape(); // Abstract 28 | 29 | Shape s3 = new Rectangle("RED", false, 1.0, 2.0); // Upcast 30 | // Returns of Rectangle methods, defined in Shape 31 | System.out.println(s3); 32 | System.out.println(s3.getArea()); 33 | System.out.println(s3.getPerimeter()); 34 | System.out.println(s3.getColor()); 35 | //System.out.println(s3.getLength()); // NOT in Shape 36 | 37 | System.out.println(); 38 | 39 | Rectangle r1 = (Rectangle)s3; // downcast 40 | // Returns of Rectangle methods 41 | System.out.println(r1); 42 | System.out.println(r1.getArea()); 43 | System.out.println(r1.getColor()); 44 | System.out.println(r1.getLength()); 45 | 46 | System.out.println(); 47 | 48 | Shape s4 = new Square(6.6); // Upcast 49 | // Returns of Square methods, defined in Shape 50 | System.out.println(s4); 51 | System.out.println(s4.getArea()); 52 | System.out.println(s4.getColor()); 53 | //System.out.println(s4.getSide()); // NOT in Rectangle 54 | 55 | System.out.println(); 56 | 57 | // Take note that we downcast Shape s4 to Rectangle, 58 | // which is a superclass of Square, instead of Square 59 | Rectangle r2 = (Rectangle)s4; 60 | // Returns of Square methods, defined in Rectangle 61 | System.out.println(r2); 62 | System.out.println(r2.getArea()); 63 | System.out.println(r2.getColor()); 64 | //System.out.println(r2.getSide()); // Not in Rectangle 65 | System.out.println(r2.getLength()); 66 | 67 | System.out.println(); 68 | 69 | // Downcast Rectangle r2 to Square 70 | Square sq1 = (Square)r2; 71 | // Returns of Square methods 72 | System.out.println(sq1); 73 | System.out.println(sq1.getArea()); 74 | System.out.println(sq1.getColor()); 75 | System.out.println(sq1.getSide()); 76 | System.out.println(sq1.getLength()); 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /pract7/src/ru/mirea/ikbo1218/grachev/ex5/GameInterface.java: -------------------------------------------------------------------------------- 1 | package ru.mirea.ikbo1218.grachev.ex5; 2 | 3 | import ru.mirea.ikbo1218.grachev.ex2.Game; 4 | import javax.swing.*; 5 | import java.awt.*; 6 | 7 | public class GameInterface extends JFrame { 8 | 9 | public GameInterface(){ 10 | super("Игра"); 11 | setSize(480, 140); 12 | setLocationRelativeTo(null); 13 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 14 | JLabel firstStart = new JLabel(), 15 | secondStart = new JLabel(), 16 | curAdd = new JLabel("0"); 17 | JPanel p = new JPanel(); 18 | BoxLayout b = new BoxLayout(p, BoxLayout.Y_AXIS); 19 | p.setLayout(b); 20 | 21 | JButton addFirst = new JButton("Первому!"), 22 | addSecond = new JButton("Второму!"), 23 | playButton = new JButton("Играть"); 24 | p.add(addFirst); 25 | p.add(addSecond); 26 | 27 | JPanel p1 = new JPanel(); 28 | p1.add(new JLabel("Первый игрок:")); 29 | p1.add(firstStart); 30 | 31 | JPanel p2 = new JPanel(); 32 | p2.add(new JLabel("Второй игрок:")); 33 | p2.add(secondStart); 34 | 35 | JPanel p3 = new JPanel(); 36 | p3.add( new JLabel("Добавить номер: ")); 37 | p3.add(curAdd); 38 | 39 | getContentPane().add(p1, BorderLayout.NORTH); 40 | getContentPane().add(p2, BorderLayout.SOUTH); 41 | getContentPane().add(p3, BorderLayout.CENTER); 42 | getContentPane().add(p, BorderLayout.EAST); 43 | getContentPane().add(playButton, BorderLayout.WEST); 44 | 45 | playButton.setEnabled(false); 46 | 47 | 48 | addFirst.addActionListener(e->{ 49 | firstStart.setText(firstStart.getText()+curAdd.getText()); 50 | curAdd.setText((new Integer(Integer.parseInt(curAdd.getText())+1)).toString()); 51 | if(firstStart.getText().length() == 5) { 52 | addFirst.setEnabled(false); 53 | if(secondStart.getText().length() == 5){ 54 | playButton.setEnabled(true); 55 | } 56 | } 57 | }); 58 | addSecond.addActionListener(e->{ 59 | secondStart.setText(secondStart.getText()+curAdd.getText()); 60 | curAdd.setText((new Integer(Integer.parseInt(curAdd.getText())+1)).toString()); 61 | if(secondStart.getText().length() == 5) { 62 | addSecond.setEnabled(false); 63 | if(firstStart.getText().length() == 5){ 64 | playButton.setEnabled(true); 65 | } 66 | } 67 | }); 68 | 69 | playButton.addActionListener(e->{ 70 | JOptionPane.showMessageDialog(this, new Game(firstStart.getText(), secondStart.getText()).play()); 71 | firstStart.setText(""); 72 | secondStart.setText(""); 73 | curAdd.setText("0"); 74 | addFirst.setEnabled(true); 75 | addSecond.setEnabled(true); 76 | playButton.setEnabled(false); 77 | }); 78 | 79 | } 80 | 81 | public static void main(String[] args) { 82 | new GameInterface().setVisible(true); 83 | } 84 | } 85 | --------------------------------------------------------------------------------