#I need help with java LogLines

1 messages · Page 1 of 1 (latest)

proven marsh
#

Hii, i just started with my path but i got stuck on this exercise, the third part i cannot understand how to do it, would you like to give me some ideas or help, code below
public class LogLevels {

public static String message(String logLine) {
    return logLine.split(":", 2)[1].trim();
}

public static String logLevel(String logLine) {
    return logLine.split("\\[|\\]", 3)[1].toLowerCase();
}

// I got problems here xd
public static String reformat(String logLine) {
return logLine.format("(" logLine.split("\[|\]", 3)[1]")").toLowerCase());
}
}

wide laurel
#

please put the code into a codeblock using 3 backticks `, and also post the detail of the error you are receiving in codeblock

Example:

def hello(arg):
  return "hello world"
proven marsh
#

But i dont get any error, its just i ran out of braincells and i got no idea how to solve, and i read the whole page the hints sends me to

wide laurel
#

Why not run the code, see what error it returns, check the differences and try to solve it?

#

Exercism is TDD (Test Driven Development), where tests are written before the actual code. It mean the tests and its errors are part of the hints and learning experience.

#

If you don't know or see where it went wrong, how do you know what to fix?

wide laurel
#

@proven marsh Do you still need help?

proven marsh
#

Yeah but I'm trying still, I know what's the error, the error is that I'm not doing what the tests need, that's why I was asking for help it says I need to reformat the lines but idk how to do it and my brain is at it's max

wide laurel
#

I think we got a bit of misunderstanding here. When i ask to see the error output, im not asking you to point out where it went wrong in the code.
Im asking you the output on the website , something like

but got that

it is in the results tab, it tells you which test passed and which test failed
And then we can go from there to check for the error in the code

rain surge
#

@proven marsh Exercism uses test driven development. You need to read (and share) the test details

proven marsh
# wide laurel I think we got a bit of misunderstanding here. When i ask to see the error outpu...

Ouh okay i got it, this is the output of the tests


@Test
@Tag("task:3")
@DisplayName("The reformat method correctly reformats an error log line")
public void error_reformat() {
    assertThat(LogLevels.reformat("[ERROR]: Segmentation fault")).isEqualTo("Segmentation fault (error)");
}

Test Failure

Message: 
expected: "Segmentation fault (error)"
 but was: "error"
Exception: org.opentest4j.AssertionFailedError: 
expected: "Segmentation fault (error)"
 but was: "error"
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
    at LogLevelsTest.error_reformat(LogLevelsTest.java:62)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
wide laurel
rain surge
#

​​1. Do you understand what the test is doing?
2. Do you understand what the test is expecting and why?
3. Do you understand what your code returns and how it differs?
4. Do you understand why your code is returning what it returns?

proven marsh
proven marsh
wide laurel
#

here is a hint for the 3rd task: it accept a string input in a form of
[LEVEL]: Information
and return
Information (level)
Do you see anywhere in your code that you had something to help you extracting them?

turbid sparrow
#

Luper I've submitted solutions to this problem in about 8 different languages and it's a lot of fun to learn how to manipulate strings in all the various languages. But I think glaxxie is hinting that you might be able to reuse some of the code you've already written to solve this portion.