-
Notifications
You must be signed in to change notification settings - Fork 23
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
Finished Practice PR #8
base: main
Are you sure you want to change the base?
Conversation
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.
Nice job! See feedback in the comments below.
public class ListPractice { | ||
|
||
|
||
public static void main(String[] args) { | ||
// Create an empty ArrayList of Strings and assign it to a variable of type List | ||
|
||
ArrayList<String> list = new ArrayList<String>(); |
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.
Remember to use interface types where appropriate (List)
for(String entry : mapsPractice.keySet()){ | ||
System.out.println("Key: " + entry + ". Value: " + mapsPractice.get(entry)); | ||
} |
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.
This works! In the future, also consider entrySet
public String name = ""; | ||
private int age = -99; |
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.
For these it's probably best not to set the defaults. They will automatically default to null and 0.
public Person(String x, int y){ | ||
name = x; | ||
age = y; | ||
} |
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.
This works, but try to use more descriptive variable names in the future. A caller of this class will be confused as to what x and y represent.
public int birthYear(int currentYear){ | ||
return(currentYear - age); | ||
} |
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.
Here and elsewhere we don't need the parentheses after return. You can just say return currentYear - age;
public String getName(){ | ||
return(name); | ||
} |
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.
We don't need getters for a public instance variable.
No description provided.