Last active
October 28, 2016 18:07
-
-
Save sendz/0d865b229b0f70f71dc51f96236a2864 to your computer and use it in GitHub Desktop.
Hitung Luas Codes MVP
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
package io.github.sendz.hitungluas; | |
import android.os.Bundle; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
public class MainActivity extends AppCompatActivity implements MainView { | |
private int panjang; | |
private int lebar; | |
private EditText inputPanjang; | |
private EditText inputLebar; | |
private Button reset; | |
private MainPresenter presenter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
renderTampilan(); | |
presenter = new MainPresenter(this); | |
reset.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
panjang = Integer.valueOf(inputPanjang.getText().toString()); | |
lebar = Integer.valueOf(inputLebar.getText().toString()); | |
presenter.hitungLuas(MainActivity.this.panjang, MainActivity.this.lebar); | |
} | |
}); | |
} | |
private void renderTampilan() { | |
inputPanjang = (EditText) findViewById(R.id.edit_text_panjang); | |
inputLebar = (EditText) findViewById(R.id.edit_text_lebar); | |
reset = (Button) findViewById(R.id.button_hitung); | |
} | |
@Override | |
public void tampilkanLuas(MainModel model) { | |
new AlertDialog.Builder(MainActivity.this).setTitle("Luas").setMessage(String.valueOf(model.getLuas())).show(); | |
} | |
} |
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
package io.github.sendz.hitungluas; | |
public class MainModel { | |
int luas; | |
public MainModel(int luas) { | |
this.luas = luas; | |
} | |
public int getLuas() { | |
return luas; | |
} | |
public void setLuas(int luas) { | |
this.luas = luas; | |
} | |
} |
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
package io.github.sendz.hitungluas; | |
public class MainPresenter { | |
private MainView view; | |
private MainModel model; | |
public MainPresenter(MainView view) { | |
this.view = view; | |
} | |
public void hitungLuas(int panjang, int lebar) { | |
int luas = luasPersegi(panjang, lebar); | |
model = new MainModel(luas); | |
view.tampilkanLuas(model); | |
} | |
private int luasPersegi(int panjang, int lebar) { | |
return panjang * lebar; | |
} | |
} |
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
package io.github.sendz.hitungluas; | |
public interface MainView { | |
void tampilkanLuas(MainModel model); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment