Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class newTwo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, StringBuilder> book = new HashMap<>();
- String[] notes = scanner.nextLine().split(" \\| ");
- for (String note : notes) {
- String[] data = note.split(": ");
- String word = data[0];
- String def = data[1];
- book.putIfAbsent(word, new StringBuilder());
- // NOTE!
- // System.lineSeparator() runs on all systems effectively, whereas the "\n" might interfere with other systems like Linux
- //removed the ".append(" -")" as we can do it on the printing instead
- // replaced the System.lineSeparator() with "\n",
- book.get(word).append(def).append("\n"); // now we just append the "def" String variable in the StringBuilder
- // adding "\n" -> ensuring new info related to a Title ( word ) is on a new line
- // book.get(word).append(" -").append(def).append(System.lineSeparator());
- }
- notes = scanner.nextLine().split(" \\| ");
- String command = scanner.nextLine();
- // you can still use the below boolean variable for the if on line 49 - if you think it's no longer confusing
- // boolean isExamTime = "Test".equals(command);
- // if("Test".equals(command)) -> if(isExamTime){
- for (String currentTopic : notes) {
- // renamed to topicFromBook as its more accurate
- // replaced the System.lineSeparator() with "\n",
- String topicFromBook = "\n" + book.get(currentTopic);
- //String topicFromBook = System.lineSeparator() + book.get(currentTopic);
- //split the ternary operator into an if else if statement
- //System.out.print(isExamTime ? currentTopic + ":" + topicFromBook : currentTopic + " ");
- if (book.containsKey(currentTopic)) {
- // first we have to check our book with past notes if it contains the particular topic(s) our teacher is asking us
- if("Test".equals(command)){
- System.out.println(currentTopic + (":") + (" -") + topicFromBook);
- } else if ("Hand Over".equals(command)){
- System.out.println(currentTopic + " ");
- }
- // print only the topics saved in your book in the order being asced depending on whether is an:
- // 1. exam -> print everything "Title(s)" ( word ) and Paragraph(s) ( def )
- // 2. brief check -> print only the "Title(s)" ( word )
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement