NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*calculator ki java file*/


package com.calculator.ayush.calculator;

import android.graphics.Color;
import android.renderscript.Sampler;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.text.InputType;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {
EditText ed1;
TextView tv1;
Boolean nextNumber=Boolean.FALSE;
Boolean newNumber=Boolean.TRUE;
Boolean decimal=Boolean.FALSE;
Boolean operatorPressed=Boolean.FALSE;
double answer=0;
double numberTwo=0;
String value;
String operator="";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText) findViewById(R.id.outputField);
ed1.setInputType(InputType.TYPE_NULL);
tv1=(TextView)findViewById(R.id.textView2);
}



@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);
return true;
}
public void setFunctionView(){
if (operator.equals("+")) {
tv1.setText(" +");
} else if (operator.equals("-")) {
tv1.setText(" -");
} else if (operator.equals("x")) {
tv1.setText(" x");
} else if (operator.equals("/")) {
tv1.setText(" /");
} else {
tv1.setText(" =");
}
}
public void clearField(View v){
nextNumber=Boolean.FALSE;
newNumber=Boolean.TRUE;
decimal=Boolean.FALSE;
answer=0;
numberTwo=0;
ed1.setText("");
tv1.setText("");
v=getWindow().getDecorView();
v.setBackgroundColor(Color.WHITE);
}
public void one(View v) {
if(newNumber){
ed1.setText("1");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"1");
}

}
public void two(View v){
if(newNumber){
ed1.setText("2");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"2");
}
}
public void three(View v){
if(newNumber){
ed1.setText("3");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"3");
}
}
public void four(View v){
if(newNumber){
ed1.setText("4");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"4");
}
}
public void five(View v){
if(newNumber){
ed1.setText("5");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"5");
}
}
public void six(View v){
if(newNumber){
ed1.setText("6");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"6");
}
}
public void seven(View v){
if(newNumber){
ed1.setText("7");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"7");
}
}
public void eight(View v){
if(newNumber){
ed1.setText("8");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"8");
}
}
public void nine(View v){
if(newNumber){
ed1.setText("9");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
ed1.setText(value+"9");
}
}
public void zero(View v){
if(newNumber){
ed1.setText("0");
newNumber=Boolean.FALSE;
decimal=Boolean.FALSE;
operatorPressed=Boolean.FALSE;
}else{
value = ed1.getText().toString();
if(value.compareTo("0")!=0){
ed1.setText(value+"0");
}
}
}
public void deleteFromField(View v){
value = ed1.getText().toString();
if(operatorPressed){
operator="";
tv1.setText("");
operatorPressed=Boolean.FALSE;
newNumber = Boolean.FALSE;
v = getWindow().getDecorView();
v.setBackgroundColor(Color.WHITE);
}else {
if (value.length() > 0) {
if (value.charAt(value.length() - 1) == '.') {
decimal = Boolean.FALSE;
}
value = value.substring(0, value.length() - 1);
}
ed1.setText(value);
newNumber = Boolean.FALSE;
}
}
public void putDot(View v){
if(newNumber){
ed1.setText(".");
newNumber=Boolean.FALSE;
decimal=Boolean.TRUE;

}else{
if(!decimal) {
value = ed1.getText().toString();
ed1.setText(value + ".");
decimal = Boolean.TRUE;
}
}
}


public void calculateAns(){
if (operator.equals("+")) {
answer = answer + numberTwo;
} else if (operator.equals("-")) {
answer = answer - numberTwo;
} else if (operator.equals("x")) {
answer = answer * numberTwo;
} else if (operator.equals("/")) {
if(numberTwo==0){
answer=0;
}else {
answer = answer / numberTwo;
}
} else {
answer=numberTwo;
}
operator="";
}
public void addType1(View v) {
if(!operatorPressed) {
value = ed1.getText().toString();
operatorPressed=Boolean.TRUE;
if (value.compareTo("") != 0) {
if (!nextNumber) {
answer = Double.parseDouble(value);
nextNumber = Boolean.TRUE;
newNumber = Boolean.TRUE;
operator = "+";
decimal = Boolean.FALSE;

} else {
value = ed1.getText().toString();
if (value.compareTo("") != 0) {
numberTwo = Double.parseDouble(value);
calculateAns();
operator = "+";
newNumber = Boolean.TRUE;
decimal = Boolean.FALSE;
}
}
setFunctionView();
v = getWindow().getDecorView();
v.setBackgroundColor(Color.GREEN);
}
}
}
public void subtractType1(View v){
if(!operatorPressed) {
value = ed1.getText().toString();
operatorPressed = Boolean.TRUE;
if (value.compareTo("") != 0) {
if (!nextNumber) {
answer = Double.parseDouble(value);
nextNumber = Boolean.TRUE;
newNumber = Boolean.TRUE;
decimal = Boolean.FALSE;
operator = "-";

} else {
value = ed1.getText().toString();
if (value.compareTo("") != 0) {
numberTwo = Double.parseDouble(value);
calculateAns();
operator = "-";
newNumber = Boolean.TRUE;

}
}
setFunctionView();
v = getWindow().getDecorView();
v.setBackgroundColor(Color.RED);
}
}
}
public void multiplyType1(View v){
if(!operatorPressed) {
value = ed1.getText().toString();
operatorPressed = Boolean.TRUE;
if (value.compareTo("") != 0) {
if (!nextNumber) {
answer = Double.parseDouble(value);
nextNumber = Boolean.TRUE;
newNumber = Boolean.TRUE;
decimal = Boolean.FALSE;
operator = "x";

} else {
value = ed1.getText().toString();
if (value.compareTo("") != 0) {
numberTwo = Double.parseDouble(value);
calculateAns();
operator = "x";
newNumber = Boolean.TRUE;
}

}
setFunctionView();
v = getWindow().getDecorView();
v.setBackgroundColor(Color.BLUE);
}
}
}
public void divType1(View v){
if(!operatorPressed) {
value = ed1.getText().toString();
operatorPressed = Boolean.TRUE;
if (value.compareTo("") != 0) {
if (!nextNumber) {
answer = Double.parseDouble(value);
nextNumber = Boolean.TRUE;
newNumber = Boolean.TRUE;
decimal = Boolean.FALSE;
operator = "/";

} else {
value = ed1.getText().toString();
if (value.compareTo("") != 0) {
numberTwo = Double.parseDouble(value);
calculateAns();
operator = "/";
newNumber = Boolean.TRUE;
}
}
setFunctionView();
v = getWindow().getDecorView();
v.setBackgroundColor(Color.YELLOW);
}
}
}
public void equals(View v) {
value=ed1.getText().toString();
if(value.compareTo("")!=0) {
numberTwo = Double.parseDouble(value);
calculateAns();
}
operator="";
tv1.setText("");
setFunctionView();
ed1.setText("" + answer);
newNumber=Boolean.TRUE;
decimal=Boolean.TRUE;
operatorPressed=Boolean.FALSE;
}

@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);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.