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

Finished Practice PR #8

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Finished Practice PR #8

wants to merge 12 commits into from

Conversation

Butenkite
Copy link

No description provided.

Copy link

@auberonedu auberonedu left a 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>();

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)

Comment on lines +32 to +34
for(String entry : mapsPractice.keySet()){
System.out.println("Key: " + entry + ". Value: " + mapsPractice.get(entry));
}

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

Comment on lines +11 to +12
public String name = "";
private int age = -99;

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.

Comment on lines +16 to +19
public Person(String x, int y){
name = x;
age = y;
}

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.

Comment on lines +39 to +41
public int birthYear(int currentYear){
return(currentYear - age);
}

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;

Comment on lines +43 to +45
public String getName(){
return(name);
}

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.

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