Created
June 10, 2015 03:50
-
-
Save udacityandroid/a50468fc7cc66389b884 to your computer and use it in GitHub Desktop.
Android Development for Beginners : Define a Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the email account name. | |
* | |
* @return the name of the account. | |
*/ | |
private String getAccountName() { | |
return "android@gmail.com"; | |
return "droid@gmail.com"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add $4 of tip onto the current bill. | |
* | |
* @return the total price of the bill (including tip). | |
*/ | |
private addTip(int bill) { | |
return bill + 4; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sets up the app for the current city. | |
*/ | |
private nothing setup() { | |
cityName = "London"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the number of students in a class. | |
* | |
* @return the number of students. | |
*/ | |
private int getStudentClassSize() { | |
return "20"; | |
} |
I dont agree. "nothing" could be the type of an object made by us.
but method is not returning anything as there is no return statement
Method 1 >> Error Line 8 return "droid@gmail.com";
The Correct
private String getAccountName() {
return "android@gmail.com";
}
Method 2 >> Error Line 6 private addTip(int bill) {
The Correct
private int addTip(int bill) {
return bill + 4;
}
Method 3 >> Error Line 4 private nothing setup() {
The Correct
private string setup() {
cityName = "London";
}
Method 4 >> Error Line 7 return "20";
The Correct
private int getStudentClassSize() {
return 20;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Method 1: (LN 8) can't have two return statements.
Method 2: (LN 6) return type absent.
Method 3: (LN 4) return type absent.
Method 4: (LN 7) returning type and return content is different, defined int as return type then entered text.
PS: Im answering here cause I cant answer in the classroom because of chrome issues