Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Created May 25, 2015 21:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save udacityandroid/6dfcdd2d7bc9b9656e73 to your computer and use it in GitHub Desktop.
Save udacityandroid/6dfcdd2d7bc9b9656e73 to your computer and use it in GitHub Desktop.
Android Development for Beginners : Practice Set 2 Shopping List 1 Example
int raspberryPrice = 5;
display1("1 box: $" + raspberryPrice);
display2("2 boxes: $" + (raspberryPrice * 2));
display3("3 boxes: $" + (raspberryPrice * 3));
@totoantonio
Copy link

Read

@AdriaticHeart
Copy link

1 box: $5
2 boxes: $10
3 boxes: $15

@ge0pol
Copy link

ge0pol commented Apr 11, 2017

This is the java file I used to reproduce the results from beginning to end. You don't really need the first "display" method but I left it there in case it's useful for the next quiz.

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);
    int raspberryPrice = 5;
    display1("1 box: $" + raspberryPrice);
    display2("2 boxes: $" + (raspberryPrice * 2));
    display3("3 boxes: $" + (raspberryPrice * 3));

}

/**
 * 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);
}

}

@burobot2016
Copy link

it woooooooooooooooork masha allah
thaaaaaaaaanks

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