Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Created June 10, 2015 03:50
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save udacityandroid/a50468fc7cc66389b884 to your computer and use it in GitHub Desktop.
Save udacityandroid/a50468fc7cc66389b884 to your computer and use it in GitHub Desktop.
Android Development for Beginners : Define a Method
/**
* Get the email account name.
*
* @return the name of the account.
*/
private String getAccountName() {
return "android@gmail.com";
return "droid@gmail.com";
}
/**
* Add $4 of tip onto the current bill.
*
* @return the total price of the bill (including tip).
*/
private addTip(int bill) {
return bill + 4;
}
/**
* Sets up the app for the current city.
*/
private nothing setup() {
cityName = "London";
}
/**
* Get the number of students in a class.
*
* @return the number of students.
*/
private int getStudentClassSize() {
return "20";
}
@Bendzi98
Copy link

hey guys..would anybody be so kind and paste me the whole code because apparently I didn't save it.

@abdahma01
Copy link

Method 1 Ln 8 unreachable code after the first return statement.
Method 2 Ln 6 The data type of the return value must match the method's declared return type. It should be int
Method 3 Ln 4 There is not a method's declared return type of "nothing". It should be void.
Method 4 Ln 7 The data type of the return value must match the method's declared return type.20 should be without quotes

@shirimaG
Copy link

you are correct @abdahma01

@badrddinb
Copy link

DONE

@sherifhisham
Copy link

DONE . thank god !

@vyruss-zz
Copy link

Please stop putting the solution in the comments.

@AbdelrhmanMHsn
Copy link

Method1------>this is correct
private String getAccountName() {
return "android@gmail.com";
}

Method2------>this is correct
private int addTip(int bill) {
return bill + 4;
}

Method3------>this is correct
private nothing setup() {
return cityName = "London";
}

Method4------>this is correct
private int getStudentClassSize() {
return 20;
}

@louayeldin
Copy link

#1 Method: line 8: extra return statement line at the end of the method code.
#2 Method: line 6: Missing datatype of the method itself to be returned.
#3 Method: line 4: The method just set the value to cityName and doesn't return a value or we should define a data type for the method to be able to return something such as String value.
#4 Method: line 7: int not a proper data type used in the method to return a value of type String.

@enpaca
Copy link

enpaca commented May 10, 2018

Method #3 does not include a return statement in its definition. Keeping in mind that except void methods, any other method should have a return statement, setup() should return a reference to a nothing object.

@shoooka
Copy link

shoooka commented May 11, 2018

8 - can't return two values.
6 - forget return data type.
4 - nothing is not return data type.
7 - "20" not correct return data type,must be integer and this string.

@mohamedsaleh1984
Copy link

why we comment here ??

@Eduese
Copy link

Eduese commented May 21, 2018

Are we suppose to provide answers here?

I don't think so guys

Copy link

ghost commented May 30, 2018

@Eduese I don't think so too.

@MijeLafe
Copy link

MijeLafe commented Jun 8, 2018

Done

@OmarAtia
Copy link

thx

@Mostafa1A
Copy link

can't return two values

@Fury4hwxc
Copy link

Method 1) : 8_ there is extra return line
Method 2) : 6_need data type then method name, data type is missing
Method 3) : 4_need data type String to get return value
Method 4) : 7_must be int or string , not proper data type

@ahmedmtaher
Copy link

done

Copy link

ghost commented Jun 21, 2018

8,6,4,7

@johninit
Copy link

I agree Nogaeman keep it like that lad

@emanhamad
Copy link

Method (1) : 8 there is extra return line
Method (2) : 6 data type is missing
Method(3) : 4 need data type String to return value
Method (4) : 7 not proper data type

@Hanaa94
Copy link

Hanaa94 commented Sep 26, 2018

8,6,4,7

@djalilo24
Copy link

methode1------>line8-Return 2 values
methode2------>line6-return data type
methode3------>line4-return data type and methode name
methode4------>line7-" 10"return type int not string

@AhmedMohammed11
Copy link

Method 1: LN8,
Method 2: LN6,
Method 3: LN4,
Method 4: LN7.

@Mazenabdallah
Copy link

guys please anyone solve lab1 ??

@Mazenabdallah
Copy link

@MAllaw
Copy link

MAllaw commented May 11, 2020

-nothing- could be a return type only if -nothing- is a class, but a class in java should have the first letter capitalized like -Nothing-. if we had -Nothing- in place of -nothing- then it will be correct and the method will return an object of the class Nothing.

I disagree with u bro , classes can begin with small letters , but we put it capital to make a different between the class and it's instances

@yaz71
Copy link

yaz71 commented Sep 13, 2020

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

@anishbharti118
Copy link

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

@AjayThenuan-CodingQuiz
Copy link

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