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

First day problems #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

First day problems #1

wants to merge 1 commit into from

Conversation

paulhristea
Copy link

No description provided.

String line = br.readLine();
while ( line != null) {
try {
double numar = Double.parseDouble(line);
Copy link
Author

Choose a reason for hiding this comment

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

nice.


} catch (NullPointerException ignored) {
}
Collator.getInstance().compare("ceva", "altceva");
Copy link
Author

Choose a reason for hiding this comment

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

this should be removed I think

try {
br = new BufferedReader(new FileReader("src/fisier.txt"));
text = br.readLine();
String name[] = text.split(",");
Copy link
Author

Choose a reason for hiding this comment

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

rename the array to 'names' - not critical here, but naming is important!


}

public static boolean numeIdeal(String name) {
Copy link
Author

@paulhristea paulhristea Nov 27, 2017

Choose a reason for hiding this comment

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

this function should be called 'isIdealName' - in real projects all naming will be english, and it is good practice to start boolean functions' names with the appropriate verbs ('is', 'are', 'has' etc.). So at least it would be 'esteNumeIdeal'.

if (!ok)
return false;

return true;
Copy link
Author

Choose a reason for hiding this comment

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

or simply - return ok; 😋

for (int i = 1; i < chars.length; i++) {
if (!Character.isLowerCase(chars[i]))
ok = false;
}
Copy link
Author

@paulhristea paulhristea Nov 27, 2017

Choose a reason for hiding this comment

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

good - also think about a solution using RegEx
http://www.vogella.com/tutorials/JavaRegularExpressions/article.html

BufferedReader br = null;
String text = null;
try {
br = new BufferedReader(new FileReader("src/fisier.txt"));
Copy link
Author

Choose a reason for hiding this comment

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

it's the third time that we are using this code for reading from files - how about extracting it into a separate class!

br = new BufferedReader(new FileReader("src/fisier.txt"));
text = br.readLine();
String name[] = text.split(",");
List<String> nume = Arrays.asList(name);
Copy link
Author

Choose a reason for hiding this comment

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

english!

text = br.readLine();
String name[] = text.split(",");
List<String> nume = Arrays.asList(name);
nume.sort(String::compareToIgnoreCase);
Copy link
Author

Choose a reason for hiding this comment

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

nice

try {
br = new BufferedReader(new FileReader("src/fisier.txt"));
text = br.readLine();
String name[] = text.split(",");
Copy link
Author

Choose a reason for hiding this comment

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

array should be called 'names' - although maybe a better alternative would be 'words' or even 'strings', as we are not necessarily reading names from the file. Naming is very important - it determines what other devs will think your intentions are.

}

public static boolean isVowel(char c) {
return "AEIOUaeiou".indexOf(c) != -1;
Copy link
Author

Choose a reason for hiding this comment

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

not bad

tricou.setDescription(sc.next());
tricou.setColor(sc.next());
tricou.setSize(sc.next());
System.out.println(tricou);
Copy link
Author

Choose a reason for hiding this comment

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

try to always keep the code properly indented and formatted - use CTRL+ALT+L in IDEA to auto-arrange it quickly at any time!

}



Copy link
Author

Choose a reason for hiding this comment

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

try to avoid having extra newlines where they do not improve code readability - in real projects this would actually reduce readability

@razvancruceanu
Copy link
Owner

razvancruceanu commented Nov 27, 2017 via email

@paulhristea
Copy link
Author

no problem! Eu comentez pe cele mai mici chestii pentru că deocamdată acesta este tot codebase-ul pe care putem discuta. Cel mai util ar fi dacă din comentarii din astea reușim să pornim discuții constructive

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