Android Sample Project Part - 4
In this section you will know more about MainActivity.java and Concept in android sample project
In this app you will know how to declare variable and some conditions in Salary Tax.
There are some conditions that we will to do it in MainActivity.java
Monthly salary (Riels) | Rate |
0 - 800,000 | 0% |
800,001 - 1,250,000 | 5% |
1,250,001 - 8,500,000 | 10% |
8,500,001 - 12,500,000 | 15% |
12,500,001 - upwards | 20% |
public class MainActivity extends Activity {
public Button CalculateTax;
public EditText Salary;
public TextView NetSalary;
public TextView Tax;
public double salarys, netsalary,tax = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//call method
addOnclickListener();
}
private void addOnclickListener() {
// TODO Auto-generated method stub
CalculateTax = (Button)findViewById(R.id.btncal);
Salary = (EditText)findViewById(R.id.txtsalary);
NetSalary = (TextView)findViewById(R.id.lblnet);
Tax = (TextView)findViewById(R.id.lbltax);
CalculateTax.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(Salary.getText().toString().equals("")){
Toast.makeText(getApplicationContext(), "Please Fill in the salary", Toast.LENGTH_LONG).show();
}
else
{
salarys = Double.valueOf(Salary.getText().toString());
if(salarys>=0 && salarys<=800000){
netsalary = salarys ;
tax = 0;
}else if(salarys >= 800001 && salarys <= 1250000){
tax = (salarys *0.05)-40000;
netsalary = salarys -((salarys *0.05) - 40000);
}else if(salarys >=1250001 && salarys <= 8500000){
tax = (salarys *0.1)-102500;
netsalary = salarys - ((salarys *0.1 ) - 102500);
}else if(salarys >= 8500001 && salarys <= 12500000){
tax = (salarys *0.15)-527500;
netsalary = salarys - ((salarys *0.15)-527500);
}else {
tax = (salarys *0.2)-1152500;
DecimalFormat df = new DecimalFormat("00.00");
String myre = df.format(tax);
netsalary = salarys - ((salarys *0.2)-1152500);
DecimalFormat dfo = new DecimalFormat("00.00");
String myreo = dfo.format(netsalary );
}
}
String finaltax = String.valueOf(tax);
Tax.setText(" Pay tax = "+finaltax);
NetSalary.setText("Your Balance = "+ String.valueOf(netsalary ));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
EmoticonEmoticon