Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Created May 25, 2015 21:46
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save udacityandroid/aebbe8df6932e9c1c9bf to your computer and use it in GitHub Desktop.
Save udacityandroid/aebbe8df6932e9c1c9bf to your computer and use it in GitHub Desktop.
Android Development for Beginners : Practice Set 2 Email Directory Example
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);
@Maxwe1
Copy link

Maxwe1 commented Jan 31, 2018

Not correct.
it's displaying:
Fujiwara.Lyla@justjava.com

@Nogaeman
Copy link

Nogaeman commented Feb 3, 2018

The Result of code
1
So This Not Correct

The Correct Code To Achieve The Goal Is

  String firstName = "Lyla";
        String lastName = "Fujiwara";
        String contactInfo = firstName + " " + lastName;
        contactInfo = firstName + " " + lastName + "<" + lastName + "." + firstName + "@justjava.com>";
        display(contactInfo);

untitled

@Noupha
Copy link

Noupha commented Feb 9, 2018

the code should be:
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = contactInfo + ”<“ + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

What is displayed would be:
Lyla FujiwaraFujiwara.Lyla@justjava.com

@abdahma01
Copy link

untitled

@MahmoudMabrok
Copy link

@Manoj0718 could you screen the code

@peteribrahimgorgy
Copy link

only setting part of the needed out put

image

@first-hero
Copy link

first-hero commented Feb 24, 2018

not correct
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);............................................<Fujiwara.Lyla@justjava.com>
screenshot_20180224-095234 1

to display the correct message the code will be

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);
screenshot_20180224-101058 1

@Chevoo
Copy link

Chevoo commented Mar 2, 2018

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo= firstName+" "+lastName;
contactInfo+="<" + lastName+"."+firstName+"@justjava.com>";
display(contactInfo);

@ak3096
Copy link

ak3096 commented Mar 4, 2018

String firstName ="Lyla";
String lastName ="Fujiwara";
String contactInfo=firstName+" "+lastName;
contactInfo= contactInfo+"<"+lastName+"."+firstName+"@justjava.com>";
display(contactInfo);

@wardiemotivations
Copy link

hey everyone, I am getting the same errors as @R964 and @JobVilligran please help @udacityandroid

@louayeldin
Copy link

image

@conbradst
Copy link

Given

String firstName = "Lyla";

    String lastName = "Fujiwara";

    String contactInfo = firstName + " " + lastName;

    contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";

    display(contactInfo);

Corrected Code

String firstName = "Lyla ";

    String lastName = "Fujiwara";

    String contactInfo = firstName + " " + lastName;

    contactInfo = " <" + lastName + "." + firstName + "@justjava.com>";

    display(firstName + lastName + contactInfo);

@conbradst
Copy link

Another option to correct program...

String firstName = "Lyla ";

    String lastName = "Fujiwara";

    String contactInfo = firstName + " " + lastName;

    contactInfo = firstName + lastName + " <" + lastName + "." + firstName + "@justjava.com>";

    display(contactInfo);

@Imsurajkr
Copy link

Hey i got the
Error :- Stirng cannot be converted to int and i solved this issue so what we have to do is change the value of public void to string value

String firstName = "Lyla"; String lastName = "Fujiwara"; String contactInfo = firstName + " " + lastName; contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>"; display1(contactInfo);
// This is the right java code and the programme will run fine .
public void display1(String text) { TextView t = (TextView) findViewById(R.id.display_text_view); t.setText(text); }

Happy to Help

@OluwatobilobaLight
Copy link

`package com.example.android.practiceset2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String contactInfo = firstName + " " + lastName;
    contactInfo = contactInfo + " <" + lastName + "." + firstName + "@justjava.com>";
    display(contactInfo);
}
/**
 * Display methods that allow the text to appear on the screen. Don't worry if you don't know
 * how these work yet. We'll be covering them in lesson 3.
 */

public void display(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(text);
}

public void display(int text) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(text + "");
}

public void display1(String text) {
    display(text);
}

public void display2(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_2);
    t.setText(text);
}

public void display3(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_3);
    t.setText(text);
}

}`

screenshot_1526481105

@mohamedsaleh1984
Copy link

The fix is

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo +="<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

@Mohanad0
Copy link

111

@tooptooptoop
Copy link

screenshot_2018-06-02-14-21-36 1
package com.example.android.practiceset2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String conttactInfo = firstName + " " + lastName;
    conttactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
    display(conttactInfo);

}

/**
 * Display methods that allow the text to appear on the screen. Don't worry if you don't know
 * how these work yet. We'll be covering them in lesson 3.
 */
public void display(String i) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(""+ i);
}

}

<TextView
    android:id="@+id/display_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="45sp" />

@ZahraaElhaj
Copy link

it's displaying:
Fujiwara.Lyla@justjava.com

@ahmedmtaher
Copy link

@gemjack
Copy link

gemjack commented Jun 12, 2018

package com.example.android.practiceset2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // PASTE CODE YOU WANT TO TEST HERE

    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String contactInfo = firstName + " " + lastName;
    String contactName = firstName + " " + lastName;
    contactName = (firstName + " " lastName);
    contactInfo = "<" + firstName + "." + lastName + "@justjava.com>";
    display(contactName);
    display2(contactInfo);


}

/**
 * Display methods that allow the text to appear on the screen. Don't worry if you don't know
 * how these work yet. We'll be covering them in lesson 3.
 */

public void display(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(text);
}

// public void display(int text) {
// TextView t = (TextView) findViewById(R.id.display_text_view);
// t.setText(text + "");
// }

public void display1(String text) {
    display(text);
}

public void display2(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_2);
    t.setText(text);
}

public void display3(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_3);
    t.setText(text);
}

}

image

@gemjack
Copy link

gemjack commented Jun 12, 2018

This worked for me...

Copy link

ghost commented Jun 12, 2018

@Torh-21
Copy link

Torh-21 commented Jun 14, 2018

Correct Code:

screenshot_2018-06-14-05-15-54
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

@jerylee
Copy link

jerylee commented Jun 26, 2018

image

@waelfareed
Copy link

@shiva-karthick
Copy link

Done!

package com.example.android.practiceset2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // PASTE CODE YOU WANT TO TEST HERE

        //  int weekday = 5;
        //  int weekend = 9;
        //  int optimalHours = 7 * 8;

        //  int actualHours = weekday;
        //  actualHours = actualHours + weekend * 2;
        //  int solution = optimalHours - actualHours;
        //  display(solution);

        // int dollars = 40;
        // int dollarsToYen = 119;
        // int yen = dollarsToYen * dollars;
        // display(yen);

        String firstName = "Shiva";
        String lastName = "Shankar";
        String contactInfo = firstName + " " + lastName;
        contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
        display(contactInfo);

    }

    /**
     * Display methods that allow the text to appear on the screen. Don't worry if you don't know
     * how these work yet. We'll be covering them in lesson 3.
     */

    public void display(String text) {
        TextView t = (TextView) findViewById(R.id.display_text_view);
        t.setText(text);
    }

    public void display(int text) {
        TextView t = (TextView) findViewById(R.id.display_text_view);
        t.setText(text + "");
    }

    public void display1(String text) {
        display(text);
    }

    public void display2(String text) {
        TextView t = (TextView) findViewById(R.id.display_text_view_2);
        t.setText(text);
    }

    public void display3(String text) {
        TextView t = (TextView) findViewById(R.id.display_text_view_3);
        t.setText(text);
    }
}

@YassineOuardini
Copy link

I can not find the mistake... Please, I will need help
screenshot 2018-01-21 19 07 11

public void display(String i)
so
public void display1(String i) {
TextView t = (TextView) findViewById(R.id.display_text_view);
t.setText(i + "");
}

@Darney8512
Copy link

Maybe
String firstName = "Lyla";
String lastName = "Fujiwara";
String fullName = firstName + " " + lastName;
String contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
display(fullName + contactInfo);

@MarvUkazu
Copy link

This worked for me :

    String firstName = "Lyla ";  
    String lastName = "Fujiwara";
    String contactInfo = firstName +  lastName +  " <" + lastName + "." + firstName + "@justjava.com>";
    display(contactInfo);
  • I merged the 3rd line with the 4th line and removed the double quotes in the third line
  • I also added a space to the string of the first name, to create a space between the first and last name

Screenshot 2021-02-06 at 7 58 41 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment