-
Notifications
You must be signed in to change notification settings - Fork 21
Lab 1 #36
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
shandomruffle
wants to merge
18
commits into
Rrenkens:main
Choose a base branch
from
shandomruffle:lab-1
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
Lab 1 #36
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fcb8ade
.gitignore
shandomruffle f8da345
Create classes & Implement Quiz
shandomruffle 868012c
.gitignore
shandomruffle e182df1
Fix typo
shandomruffle e5abc12
Implement EquationTask & ExpressionTask
shandomruffle e69ab12
Implement GroupTaskGenerator
shandomruffle b0202d9
Implement PoolTaskGenerator
shandomruffle 492a14b
Make generators static nested
shandomruffle 10758c7
Add some abstractions
shandomruffle d352a67
Improve package structure
shandomruffle 265f355
Make math tasks support double instead of int
shandomruffle a250283
Basic support of precision
shandomruffle 9d0308a
Implement interaction
shandomruffle 8d67f16
Test PoolGenerator & TextTask, Implement copy constructor for quiz
shandomruffle cd22fe6
Test generators Math & Group
shandomruffle 0193008
Add a couple of tasks
shandomruffle e9c14db
Move Task & TaskGenerator into appropriate packages
shandomruffle a3cbc4e
Fixes from PR
shandomruffle 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,3 @@ | ||
| .idea/ | ||
| out/ | ||
| *.iml |
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,4 @@ | ||
| package by.toharrius.quizer; | ||
| public enum CopyParameter { | ||
| FLAG | ||
| } |
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,131 @@ | ||
| package by.toharrius.quizer; | ||
|
|
||
| import by.toharrius.quizer.task_generators.GroupTaskGenerator; | ||
| import by.toharrius.quizer.task_generators.PoolTaskGenerator; | ||
| import by.toharrius.quizer.tasks.imminence_tasks.GenerousTask; | ||
| import by.toharrius.quizer.tasks.TextTask; | ||
| import by.toharrius.quizer.tasks.imminence_tasks.TrickyTask; | ||
| import by.toharrius.quizer.tasks.math_tasks.EquationTask; | ||
| import by.toharrius.quizer.tasks.math_tasks.ExpressionTask; | ||
| import by.toharrius.quizer.tasks.math_tasks.MathOperation; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.EnumSet; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class Main { | ||
| private static final String helpMessage = "list : view available quizes\n" + | ||
| "<test name> : run particular quiz\n" + | ||
| "help : view this message\n" + | ||
| "exit | quit | stop : terminate session"; | ||
| private static Map<String, Quiz> quizes; | ||
| /** | ||
| * @return тесты в {@link Map}, где | ||
| * ключ - название теста {@link String} | ||
| * значение - сам тест {@link by.toharrius.quizer.Quiz} | ||
| */ | ||
| private static @NotNull Map<String, Quiz> getQuizMap() { | ||
| var quizes = new HashMap<String, Quiz>(); | ||
| { | ||
| var gen = new PoolTaskGenerator(false, | ||
| new TextTask("Какая (по слухам) подработка у С*****ча?", "сборщик мусора"), | ||
| new TextTask("Как называется человек, убегающий от каннибала?", "фастфуд"), | ||
| new TextTask("Какой вид порно не могут снять бомжи?", "домашнее"), | ||
| new TextTask("Как называется оглушающий удар татара?", "татарстан")); | ||
| quizes.put("stupid-questions", new Quiz(gen, 4)); | ||
| } | ||
| { | ||
| var gen = new PoolTaskGenerator(true, | ||
| new GenerousTask("Каков правильный ответ?"), | ||
| new TrickyTask("Это утверждение ложно.")); | ||
| quizes.put("know-your-luck", new Quiz(gen, 7)); | ||
| } | ||
| { | ||
| var gen_eq_add = new EquationTask.Generator(2, 55, | ||
| EnumSet.of(MathOperation.ADD)); | ||
| var gen_eq_42_all = new EquationTask.Generator(42, 42, | ||
| EnumSet.allOf(MathOperation.class)); | ||
| var gen_ex_div = new ExpressionTask.Generator(17, 42, | ||
| EnumSet.of(MathOperation.DIVIDE)); | ||
| var gen_ex_all = new ExpressionTask.Generator(41, 42, | ||
| EnumSet.allOf(MathOperation.class)); | ||
| var gen_eq = new GroupTaskGenerator(gen_eq_42_all, gen_eq_add); | ||
| var gen_ex = new GroupTaskGenerator(new ExpressionTask.Generator[]{gen_ex_div, gen_ex_all}); | ||
| var gen_group = new GroupTaskGenerator(gen_ex, gen_eq, | ||
| new EquationTask.Generator(gen_eq_42_all, CopyParameter.FLAG)); | ||
| quizes.put("tricky-math", new Quiz(gen_group, 5)); | ||
| } | ||
| return quizes; | ||
| } | ||
|
|
||
| private static String inputLineNormalized() throws IOException { | ||
| return consoleReader.readLine().toLowerCase().trim(); | ||
| } | ||
|
|
||
| private static void tryLaunchQuiz(String query) throws IOException { | ||
| if (quizes.containsKey(query)) { | ||
| System.out.println("Starting quiz \"" + query + "\"!"); | ||
| Quiz clone; | ||
| try { | ||
| clone = new Quiz(quizes.get(query)); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Unable to clone", e); | ||
| } | ||
| runProblemSet(clone); | ||
| } else { | ||
| System.out.println("Sorry, not found. Type \"list\" to see available"); | ||
| } | ||
| } | ||
|
|
||
| private static void runProblemSet(Quiz quiz) throws IOException { | ||
| while (!quiz.isFinished()) { | ||
| var task = quiz.nextTask(); | ||
| System.out.println("Task " + (quiz.getCurrentTaskIndex() + 1) | ||
| + " out of " + quiz.getTaskCount() | ||
| + ": " + task.getText()); | ||
| var answer = inputLineNormalized(); | ||
| System.out.println(switch (quiz.provideAnswer(answer)) { | ||
| case OK -> "Nice!"; | ||
| case WRONG -> "Nope."; | ||
| case INCORRECT_INPUT -> "Bad input format. Please, try again."; | ||
| }); | ||
| } | ||
| System.out.println("Quiz finished! Your statistics:"); | ||
| System.out.println("Correct answers: " + quiz.getCorrectAnswerNumber()); | ||
| System.out.println("Wrong answers: " + quiz.getWrongAnswerNumber()); | ||
| System.out.println("Total tries: " + quiz.getTotalAnswerNumber()); | ||
| System.out.println("Final mark: " + quiz.getMark()); | ||
| } | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| System.out.println(helpMessage); | ||
| quizes = getQuizMap(); | ||
| consoleReader = new BufferedReader(new InputStreamReader(System.in)); | ||
| boolean interactionFinished = false; | ||
| while (!interactionFinished) { | ||
| var query = inputLineNormalized(); | ||
| switch (query) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот если бы у меня не было кода, я бы не узнал об этом никак. Про help & exit точно.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. фикс, выводится хелпа с самого начала |
||
| case "list" -> { | ||
| if (quizes.isEmpty()) { | ||
| System.out.println("There are no quizes now, coming soon ):"); | ||
| } else { | ||
| System.out.println("The total of " + quizes.size() + " quizes are present"); | ||
| quizes.forEach((name, q) -> System.out.println(name)); | ||
| } | ||
| } | ||
| case "help" -> { | ||
| System.out.println(helpMessage); | ||
| } | ||
| case "exit", "quit", "stop", ":q" -> { | ||
| interactionFinished = true; | ||
| } | ||
| default -> tryLaunchQuiz(query); | ||
| } | ||
| } | ||
| } | ||
| private static BufferedReader consoleReader; | ||
| } | ||
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.
...
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.
сказали же захардкодить...