Skip to content

added all java files#28

Open
TimSon1022 wants to merge 1 commit intoSWE-CS410:mainfrom
TimSon1022:Timothy_Son_CodeReview
Open

added all java files#28
TimSon1022 wants to merge 1 commit intoSWE-CS410:mainfrom
TimSon1022:Timothy_Son_CodeReview

Conversation

@TimSon1022
Copy link

No description provided.

@chiouc chiouc self-requested a review June 20, 2023 05:57
@chiouc
Copy link

chiouc commented Jun 20, 2023

Hi Tim, your code overall looks functional, concise, and is all very readable. I think most of the tests (besides the null pointer exception tests) test all the edge cases. Since the code works, I would just recommend some refactoring for cleaner code.

}

else if (endWord > words.length) {
throw new IndexOutOfBoundsException("Error: end index is larger than the string length");
Copy link

Choose a reason for hiding this comment

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

I think you would be able to combine this else if statement with the one from line 79. This will help make the code shorter and will combine the same type of exception.
Ex: else if (startWord > endWord || endWord > words.length) {
throw new IndexOutOfBoundsException();
}

public String[] getSubStrings(int startWord, int endWord) {
return null;
if (string == null) {
throw new NullPointerException("Error: string is not yet initialized");
Copy link

Choose a reason for hiding this comment

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

Null Pointer Exception error isn't required for this method. I'm pretty sure this is actually supposed to be an Illegal Argument Exception so I would modify this as part of that exception.

if (indices.length != string.length()) {
throw new IllegalArgumentException("Error: string length is not equal to indices length");
}
for (int i = 0; i < indices.length - 1; i++) {
Copy link

Choose a reason for hiding this comment

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

This outer nested for loop seems redundant. I'm not sure why you need to run the for loop for indices.length - 1. I believe you can just combine the 2 for loops into for (int i = 0; i < indices.length; i++) and then just run the exception in your if statement for if indices[i]< 0 or indices[i]>= string length

char[] restored = new char[indices.length];
for (int i = 0; i < indices.length; i++) {

restored[i] = string.charAt(indices[i]);
Copy link

Choose a reason for hiding this comment

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

you can run this code in the original for loop at line 108 instead of writing a whole new for loop for this portion.

fail("Not yet implemented");
public void testGetSubStrings2() {
manipulatedstring.setString(null);
NullPointerException testException = assertThrows(NullPointerException.class, () -> {
Copy link

Choose a reason for hiding this comment

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

I don't think you need a test for null pointer exception since this would fall under the other exceptions. It might be best to redo this test so you can test this under illegal argument exception

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