I got stuck at the exercise and i’m confused at what am i supposed to do, i’ve tried looking at the cheat sheet (community answer) and i still don’t understand how the program functions.
Is it okay to copy - paste another user’s program?
also if you want to try to enlighten me about the exercise, please do, i’m really confused right now
i’m sorry if my use of words doesn’t fit the perfect situation, i’m just desperate for help
Please help us help you. One can be confused in lots of ways – please explain to us your particular confusion:
- What have you tried? What was the result? Which errors?
- Which specific parts (quotes) of the instructions leave you confused? What do they make you think, and which of these thoughts are in conflict with each other?
You’ll find that people are much more likely to help you quickly when you provide this information from the start.
Very bluntly put, you shouldn’t care about this. Presumably, your goal is to get better at programming. If copy-pasting other’s code helps you achieve this, then so be it.
I find most of exercises and explanations confusing and incomplete. I really don’t understand this exercise too.
I think the messages you recieve (logs) are pre-programmed smewhere and you have to write a code to get them.
Each exercise has unit tests with error messages which are displayed when the tests fail. The test file is included in the exercise.
Hi! I don’t get where should we define the LogLine.getLogLevel() method. If I define a separate class LogLine I get duplicate class: LogLine
If I define a class LogLine inside the LogLevel class, I get Please implement the getLogLevel() method
.
Any ideas? Thanks!
Sample code (draft, work in progress, I’m still not able to pass the first test).
public enum LogLevel {
INFO("INF"),
WARNING("WARN"),
DEBUG("DEB"),
FATAL("FATAL"),
TRACE("TRACE"),
ERROR("ERROR");
private final String level;
LogLevel(String level) {
this.level = level;
}
public String getLogLevel() {
return this.level;
}
}
class LogLine {
String line;
public LogLine(String line) {
this.line = line;
}
public LogLevel getLogLevel() {
String logLineTrimmed = this.line.substring(1, 4);
switch (logLineTrimmed) {
case "INF": {
return LogLevel.INFO;
}
case "WAR": {
return LogLevel.WARNING;
}
case "DEB": {
return LogLevel.DEBUG;
}
case "FAT": {
return LogLevel.FATAL;
}
case "TRC": {
return LogLevel.TRACE;
}
case "ERR": {
return LogLevel.ERROR;
}
default: {
return LogLevel.WARNING;
}
}
}
}
class Test {
public static void main(String[] args) {
LogLine logLine = new LogLine("[TRC]: Line 84 - System.out.println(\"Hello World\");");
System.out.println(logLine.getLogLevel());
System.out.println(LogLevel.valueOf("TRACE"));
}
}
Hi @osvaldo984058,
The problem is not very difficult. It is just designed in a way that it doesn’t reveal all the hints. Although, if you are clear with the concepts like method types: static and instance types, how method calls are made, how methods run, you should be able to make sense of the problem statement.
Now, if you understand those concepts, re-read the Instructions section, this time a bit slow, try to relate to the instructions with the given method header, instructions of the given tasks, and respective examples. You will definitely make sense of the problem.
I hope that helps.
Thanks, I looked at the problem again and my issue was that I did not realize that there were two files, lol. I was working only with LogLevel.java and not using LogLine.java at all.