-
Notifications
You must be signed in to change notification settings - Fork 1
FIXBUG #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FedorTvor
wants to merge
1
commit into
main
Choose a base branch
from
dev_fa_BUGFIX
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
FIXBUG #21
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AuthorOfBook extends ValueGetter<Book, java.lang.String>{ | ||
| public java.lang.String get(Book book){ | ||
| return book.getAuthor(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,32 @@ | ||
| import java.util.Random; | ||
|
|
||
| public class BookRandomizer implements ItemRandomizer<Book> { | ||
| private static final String[] AUTHORS = {"Jane Austen", "Harper Lee", "Scott Fitzgerald", "Gabriel Garcia", "Truman Capote"}; | ||
| private static final String[] TITLES = {"Pride and Prejudice", "To Kill a Mockingbird", "The Great Gatsby", "One Hundred Years of Solitude", "In Cold Blood"}; | ||
| private static final Integer MIN_PAGES = 300; | ||
| private static final Integer MAX_PAGES = 1500; | ||
| private static final Random RANDOM = new Random(); | ||
| private final String[] authors = {"Jane Austen", "Harper Lee", "Scott Fitzgerald", "Gabriel Garcia", "Truman Capote"}; | ||
| private final String[] titles = {"Pride and Prejudice", "To Kill a Mockingbird", "The Great Gatsby", "One Hundred Years of Solitude", "In Cold Blood"}; | ||
| private final Integer minPages = 300; | ||
| private final Integer maxPages = 1500; | ||
| private final Random random = new Random(); | ||
|
|
||
| @Override | ||
| public Book generate(){ | ||
| String author = getRandomAuthor(); | ||
| String title = getRandomTitle(); | ||
| Integer pages = getRandomPages(); | ||
|
|
||
| return new Book.Builder() | ||
| .setAuthor(author) | ||
| .setTitle(title) | ||
| .setPages(pages) | ||
| .build(); | ||
| return Book.createInstance(author,title,pages); | ||
| } | ||
|
|
||
| private static String getRandomAuthor() { | ||
| int index = RANDOM.nextInt(AUTHORS.length); | ||
| return AUTHORS[index]; | ||
| private String getRandomAuthor() { | ||
| int index = random.nextInt(authors.length); | ||
| return authors[index]; | ||
| } | ||
|
|
||
| private static String getRandomTitle() { | ||
| int index = RANDOM.nextInt(TITLES.length); | ||
| return TITLES[index]; | ||
| private String getRandomTitle() { | ||
| int index = random.nextInt(titles.length); | ||
| return titles[index]; | ||
| } | ||
|
|
||
| private static Integer getRandomPages() { | ||
| return MIN_PAGES + RANDOM.nextInt(MAX_PAGES - MIN_PAGES + 1); | ||
| private Integer getRandomPages() { | ||
| return minPages + random.nextInt(maxPages - minPages + 1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,32 @@ | ||
| import java.util.Random; | ||
|
|
||
| public class CarRandomizer implements ItemRandomizer<Car>{ | ||
| private static final String[] MODELS = {"Ford Bronco", "Haval Jolion", "Audi A3", "Mercedes-Benz V-Class", "Lexus LS"}; | ||
| private static final Integer MIN_POWER = 100; | ||
| private static final Integer MAX_POWER = 400; | ||
| private static final Integer MIN_YEAR = 2000; | ||
| private static final Integer MAX_YEAR = 2025; | ||
| private static final Random RANDOM = new Random(); | ||
| private final String[] models = {"Ford Bronco", "Haval Jolion", "Audi A3", "Mercedes-Benz V-Class", "Lexus LS"}; | ||
| private final Integer minPower = 100; | ||
| private final Integer maxPower = 400; | ||
| private final Integer minYear = 2000; | ||
| private final Integer maxYear = 2025; | ||
| private final Random random = new Random(); | ||
|
|
||
| @Override | ||
| public Car generate() { | ||
| Integer power = getRandomPower(); | ||
| String model = getRandomModel(); | ||
| Integer year = getRandomYear(); | ||
|
|
||
| return new Car.BuildCAr() | ||
| .setPower(power) | ||
| .setModel(model) | ||
| .setYearOfProduction(year) | ||
| .build(); | ||
| return Car.createInstance(power,model,year); | ||
| } | ||
|
|
||
| private static Integer getRandomPower() { | ||
| return MIN_POWER + RANDOM.nextInt(MAX_POWER - MIN_POWER + 1); | ||
| private Integer getRandomPower() { | ||
| return minPower + random.nextInt(maxPower - minPower + 1); | ||
| } | ||
|
|
||
| private static String getRandomModel() { | ||
| int index = RANDOM.nextInt(MODELS.length); | ||
| return MODELS[index]; | ||
| private String getRandomModel() { | ||
| int index = random.nextInt(models.length); | ||
| return models[index]; | ||
| } | ||
|
|
||
| private static Integer getRandomYear() { | ||
| return MIN_YEAR + RANDOM.nextInt(MAX_YEAR - MIN_YEAR + 1); | ||
| private Integer getRandomYear() { | ||
| return minYear + random.nextInt(maxYear - minYear + 1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class ColourOfRV extends ValueGetter<RootVegetable, java.lang.String>{ | ||
| public java.lang.String get(RootVegetable rv){ | ||
| return rv.getColour(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| public class DataType { | ||
| public static enum datatype{ | ||
| CAR(Car.class), | ||
| BOOK(Book.class), | ||
| ROOTVEGETABLE(RootVegetable.class); | ||
| private final Class<?> clazz; | ||
|
|
||
| datatype(Class<?> clazz) { | ||
| this.clazz = clazz; | ||
| } | ||
| public Class<?> getClazz() { | ||
| return clazz; | ||
| } | ||
| public String getClassName() { | ||
| return clazz.getSimpleName(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| public class ExitAction implements MenuAction{ | ||
| @Override | ||
| public void execute() { | ||
| public MenuAction execute() { | ||
| System.out.println("Выход из программы..."); | ||
| System.exit(0); | ||
|
|
||
| } | ||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,19 @@ | ||
| import java.util.Arrays; | ||
| import java.util.Scanner; | ||
|
|
||
|
|
||
| public class Main { | ||
| public static enum datatype{ | ||
| CAR, | ||
| BOOK, | ||
| ROOTVEGETABLE | ||
| } | ||
| public static void main(String[] args) { | ||
| //Storage storage = Storage.getInstance(); | ||
|
|
||
| Menu print_array_menu=new Menu(); | ||
| print_array_menu.prelude="Выберите тип данных"; | ||
| print_array_menu.addAction("1", "Автомобиль",new PrintArrayAction<Car>(datatype.CAR)); | ||
| print_array_menu.addAction("2", "Книга",new PrintArrayAction<Book>(datatype.BOOK)); | ||
| print_array_menu.addAction("3", "Корнепллод",new PrintArrayAction<RootVegetable>(datatype.ROOTVEGETABLE)); | ||
| print_array_menu.addAction("0", "Отмена", null); | ||
|
|
||
| Menu menu = new Menu(); | ||
| menu.reopen_after_submenu_closes=true; | ||
| menu.addAction("1", "Заполнение массива объектов вручную", new ManuallyFillArrayAction()); | ||
| menu.addAction("2", "Создание массива объектов с рандомными значениями", new RandomFillArrayAction()); | ||
| menu.addAction("3", "Вывод массива объектов на экран", print_array_menu); | ||
| menu.addAction("4", "Сортировка массива", null);//TODO | ||
| menu.addAction("5", "Выход", null); | ||
| menu.addAction("1", "Заполнение массива объектов из файла", new ReadFileArrayAction()); | ||
| menu.addAction("2", "Заполнение массива объектов вручную", new ManuallyFillArrayAction()); | ||
| menu.addAction("3", "Заполнение массива объектов рандомными значениями", new RandomFillArrayAction()); | ||
| menu.addAction("4", "Вывод массива объектов на экран", new PrintType()); | ||
| menu.addAction("5", "Сортировка", new SortAction()); | ||
| menu.addAction("7", "Поиск элемента в массиве",new SearchHelper()); | ||
| menu.addAction("0", "Выход", new ExitAction()); | ||
|
|
||
| menu.execute(); | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,65 @@ | ||
| public class ManuallyFillArrayAction implements MenuAction{ | ||
| import java.io.File; | ||
| import java.util.Scanner; | ||
|
|
||
| public class ManuallyFillArrayAction implements MenuAction { | ||
|
|
||
| @Override | ||
| public void execute(){ | ||
| public MenuAction execute() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| boolean step = true; | ||
| while (step) { | ||
| System.out.println("Выберите тип данных для массива:"); | ||
| System.out.println("1. Автомобиль"); | ||
| System.out.println("2. Книга"); | ||
| System.out.println("3. Корнепллод"); | ||
| System.out.println("0. Вернуться в главное меню"); | ||
| String choice = scanner.next(); | ||
| switch (choice) { | ||
| case "1": | ||
| fillArray(scanner, DataType.datatype.CAR, new FillCarManually()); | ||
| step = false; | ||
| break; | ||
| case "2": | ||
| fillArray(scanner, DataType.datatype.BOOK, new FillBookManually()); | ||
| step = false; | ||
| break; | ||
| case "3": | ||
| fillArray(scanner, DataType.datatype.ROOTVEGETABLE, new FillRootVegetableManually()); | ||
| step = false; | ||
| break; | ||
| case "0": | ||
| step = false; | ||
| break; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private <T> void fillArray(Scanner scanner, DataType.datatype datatype, Fill<T> filler) { | ||
| Storage<T> storage = Storage.<T>getInstance(datatype); | ||
| T[] array = filler.fill(); | ||
| int start_index = findFirst(storage, array.length); | ||
| Object[] objects = storage.getObjects(); | ||
| System.arraycopy(array, 0, objects, start_index, array.length); | ||
| String className = datatype.getClassName(); | ||
| WriterFile writerFile = new WriterFile<>(new File(className + ".txt")); | ||
| writerFile.createdFile(); | ||
| writerFile.writeText(objects); | ||
| } | ||
|
|
||
|
|
||
| private int findFirst(Storage<? extends Object> storage, int size) { | ||
| Object[] objects = storage.getObjects(); | ||
| int startIndex = 0; | ||
| // Найти первое свободное место в массиве | ||
| while (startIndex < objects.length && objects[startIndex] != null) { | ||
| startIndex++; | ||
| } | ||
| // Если места нет увеличиваем размер массива | ||
| if (startIndex >= objects.length) { | ||
| storage.expandArray(size); | ||
| objects = storage.getObjects(); | ||
| } | ||
| return startIndex; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| public interface MenuAction { | ||
| void execute(); | ||
| MenuAction execute(); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хочу обсудить