Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.jdsch_000.testing;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- EditText billAmount =(EditText) findViewById(R.id.billAmount);
- EditText tip1Field = (EditText) findViewById(R.id.tip1);
- EditText tip2Field = (EditText) findViewById(R.id.tip2);
- EditText tip3Field = (EditText) findViewById(R.id.tip3);
- EditText comp1 = (EditText) findViewById(R.id.comp1);
- EditText comp2 = (EditText) findViewById(R.id.comp2);
- EditText comp3 = (EditText) findViewById(R.id.comp3);
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- Button okBtn = (Button) findViewById(R.id.okBtn);
- Button resetBtn = (Button) findViewById(R.id.resetBtn);
- okBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- tip tip1 = new tip(Double.parseDouble(billAmount.toString()), Double.parseDouble(tip1Field.toString()));
- tip tip2 = new tip(Double.parseDouble(billAmount.toString()), Double.parseDouble(tip2Field.toString()));
- tip tip3 = new tip(Double.parseDouble(billAmount.toString()), Double.parseDouble(tip3Field.toString()));
- comp1.setText(String.format(".2f", tip1.calculateTip()));
- comp2.setText(String.format(".2f", tip2.calculateTip()));
- comp3.setText(String.format(".2f", tip3.calculateTip()));
- }
- });
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- package com.example.jdsch_000.testing;
- /**
- * Created by jdsch_000 on 11/20/2014.
- */
- public class tip {
- private double billAmount;
- private double rate;
- public tip(double v){
- billAmount = 0;
- }
- public tip(double billAmount, double rate){
- this.rate = rate / 100;
- this.billAmount = billAmount;
- }
- public double calculateTip(){
- double total = rate * billAmount;
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement