-
Notifications
You must be signed in to change notification settings - Fork 12
Module 3 LinearEquationSolver #8
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
base: master
Are you sure you want to change the base?
Conversation
| Row normalizeRow(int index) { | ||
| try { | ||
| return divide(row[index]); | ||
| } catch (ArithmeticException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the word "ignore" after the ArithmeticException keyword.
|
|
||
| Row divide(double v) { | ||
| if(v == 0){ | ||
| throw new java.lang.ArithmeticException("Division by zero"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can simply write: throw new ArithmeticException("Division by zero");
| * Example: > java Solver -in in.txt -out out.txt | ||
| * @param args | ||
| */ | ||
| public static void main(String[] args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method main is very big. If your method does two or three different things at a time then you should consider splitting the functionality of this method into other methods (single responsibility principle) and just try to make your methods as small as possible.
| public class Main { | ||
|
|
||
| static String getHelp() { | ||
| String helpMsg = "This program is intended to solve Linear Equations with any amount of variables using Gauss-Jordan Elimination. \n\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User StringBuilder (of course the compiler will use StringBuilder automatically, but the usage of it is more look like Builder pattern).
| AugmentedMatrix() {} | ||
|
|
||
| public void readMatrix(Scanner scanner) throws InputMismatchException { | ||
| int n = scanner.nextInt(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never use only one letter in the name. Variable should represent the value it was created for.
| private void transformToUpperTriangularForm() { | ||
| Row currentRow; | ||
| int n = matrix.size()[0]; | ||
| for(int i = 0; i < n; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need space after "for"
| for(int i = 0; i < n; i++) { | ||
| currentRow = matrix.getRow(i); | ||
| normalizeRowsForTransforming(i, currentRow); | ||
| for(int j = i + 1; j < n; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need space after "for"
| double coefficient = matrix.getRow(j).get(i); | ||
| if(coefficient != 1.0) { | ||
| matrix.getRow(j).normalizeRow(i); | ||
| logMessage(String.format("R%d / %s - R%d -> R%d", j, new DecimalFormat("#.###").format(coefficient), i, j)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you are better off having static String variable with "#.###"
| */ | ||
| private void subtractRowsForTransforming(int i, int j, Row currentRow) { | ||
| double coefficient = matrix.getRow(j).get(i); | ||
| if(coefficient != 1.0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need space after "if"
| */ | ||
| private void normalizeRowsForTransforming(int i, Row currentRow) { | ||
| double coefficient = currentRow.get(i); | ||
| if(coefficient != 1.0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need space after "if"
|
|
||
| public String getResultString() { | ||
| StringBuilder sb = new StringBuilder(); | ||
| for(double coefficient: result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need space after "for"
| sb.append(new DecimalFormat("#.####").format(coefficient)); | ||
| sb.append("\n"); | ||
| } | ||
| sb.deleteCharAt(sb.length()-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need spaces after "sb.length()" and before "-1"
| int n = this.matrix.size()[0]; | ||
| int m = this.matrix.size()[1]; | ||
| result = new double[n]; | ||
| for(int i = 0; i < n; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need space after "for"
| System.out.println("The solution is: (" + res.replaceAll("\n", ", ") + ")"); | ||
|
|
||
| // Output writing | ||
| try(FileWriter fileWriter = new FileWriter(outputFile)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need space after "try"
edvardyanushkevich
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution contains quite a few remarks on formatting, so I would like to give some advices:
IDE has hotkeys for auto-formatting. (For example IDEA: Ctrl+Alt+L, Eclipse: Ctrl + Shift + F, NetBeans: Alt + Shift + F)
Java Code Conventions: https://www.oracle.com/technetwork/java/codeconventions-150003.pdf
Single Responsibility - one method should be responsible only for one action. If your method does two or three different things at a time then you should consider splitting the functionality of this method into other methods.
Small Methods - there is no a standard pattern for method length among the developers. Just try to make your methods as small as possible.
Hi!
Check out my realization, plz)