Skip to content
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

Roman numerals solution #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Roman numerals solution #2

wants to merge 7 commits into from

Conversation

AlexGeryavenko
Copy link

Hi, my solution for roman-numerals task.

final String numStr = numArray[i];
boolean e = true;
for (int k = 0; k < numStr.length(); k++) {
if (Character.isDigit(numStr.charAt(k)) == false) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the == false, use if (! condition)


}

public static void readInput() {
Copy link
Owner

@ZsoltFabok ZsoltFabok Sep 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private, and this applies to the other methods.

}
}

if (e) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is hard to figure out what you are testing here.

}

public static void convert() {
for (int i = 0; i < numArray.length; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, you should use collections, because there are way better functions to work with them than with arrays.


}

public static void runTest() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to write a JUnit test

runTest();
}
} else {
readInput();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this style, but the methods should return something and the next method should use it as input.

public final static String TWELVE = "XII";
public final static String ONE_HUNDRED_AND_THREE = "CIII";

private static String[] numArray;
Copy link
Owner

@ZsoltFabok ZsoltFabok Sep 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You either solve this problem in an OOP fashion or functional, but this is approach is none of them. You use a static variable to pass around value. If you create two RomanNumeralsConvert this won't work.

line = line.replace("\"", "").trim();
numArray = line.split("\\s+");
}
} catch (final IOException e) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you catch the exception here, the validate() method will still run

public final static String tensArray[] = { "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" };
public final static String hundredsArray[] = { "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" };

public final static String TEST_MOD = "-test";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move test data somewhere else.

if (args.length > 1 || !TEST_MOD.equals(args[0])) {
System.out.println("Only one flag supports: - test");
} else {
runTest();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See later, but it would be better to have tests in a JUnit class.

}

public static void validate() {
for (int i = 0; i < numArray.length; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for(... : ...)


final int ones = num % 10;

num = (num - ones) / 10;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this and the following steps a bit more simpler?


num = (num - hundreds) / 10;
for (int n = 0; n < num; n++) {
Roman += "M";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have "M" here, but the rest is at the top.

using collection
change convert algorithm
exit if catch exception
changed  methods access modifiers
fix condition in if statement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants