-
-
Save udacityandroid/6dfcdd2d7bc9b9656e73 to your computer and use it in GitHub Desktop.
Android Development for Beginners : Practice Set 2 Shopping List 1 Example
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
int raspberryPrice = 5; | |
display1("1 box: $" + raspberryPrice); | |
display2("2 boxes: $" + (raspberryPrice * 2)); | |
display3("3 boxes: $" + (raspberryPrice * 3)); |
1 box: $5
2 boxes: $10
3 boxes: $15
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);
}
}
it woooooooooooooooork masha allah
thaaaaaaaaanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read