package net.apptools.appbuttonproject1;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import net.apptools.appbuttonproject1.R;

import java.util.Random;

public class PlusOpActivity extends Activity {
private Random mRand1 ;

private TextView tvCurrentScore;

private TextView tvOperand1d1 ;
private TextView tvOperand1d10 ;
private TextView tvOperand1d100 ;

private TextView tvOperand2d1 ;
private TextView tvOperand2d10 ;
private TextView tvOperand2d100 ;

private TextView tvResultd1;
private TextView tvResultd10;
private TextView tvResultd100;

private int sum = 0;
private int operand1 = 0;
private int operand2 = 0;

private int cp = 0;
private int questionNo = 0;
private int currentScore = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plus_op);

ActionBar actionBar = getActionBar();
actionBar.hide();

tvCurrentScore = (TextView) findViewById(R.id.plus_tvCurrentScore);

tvOperand1d1 = (TextView) findViewById(R.id.plus_tvOperand1d1);
tvOperand1d10 = (TextView) findViewById(R.id.plus_tvOperand1d10);

tvOperand2d1 = (TextView) findViewById(R.id.plus_tvOperand2d1);
tvOperand2d10 = (TextView) findViewById(R.id.plus_tvOperand2d10);
tvOperand2d100 = (TextView) findViewById(R.id.plus_tvOperand2d100);

tvResultd1 = (TextView) findViewById(R.id.plus_tvResultd1);
tvResultd10 = (TextView) findViewById(R.id.plus_tvResultd10);
tvResultd100 = (TextView) findViewById(R.id.plus_tvResultd100);

mRand1 = new Random();

this.initScreen();

}


public int getRandomNumber( int max, int offset ) {
int nResult;
nResult = mRand1.nextInt( max ) + offset;
return nResult;
}





public void OnDelBtnPressed( View v) {
if ( cp > 0) {

int temp = 0;

if ( cp == 1 ) {
temp = Integer.parseInt( tvResultd1.getText().toString() );
tvResultd1.setText(" ");
}

if ( cp == 2 ) {
temp = Integer.parseInt( tvResultd10.getText().toString() ) * 10 ;
tvResultd10.setText(" ");
}

if ( cp == 3 ) {
temp = Integer.parseInt( tvResultd100.getText().toString() ) * 100 ;
tvResultd100.setText(" ");
}

cp = cp - 1;
sum = sum - temp;
}
}
public void OnMarkingBtnPressed( View v) {
int temp;

temp = operand1 + operand2;

if ( sum != 0 ) {
if ( temp == sum ) {
questionNo = questionNo + 1;
currentScore = currentScore + 10;
tvCurrentScore.setText( currentScore + "점");
TextView tvCorrect = (TextView) findViewById(R.id.plus_tvCorrect);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
tvCorrect.startAnimation( animation );
// Toast.makeText(this, "정답입니다. ", Toast.LENGTH_SHORT).show();
} else {
questionNo = questionNo + 1;
TextView tvWrong = (TextView) findViewById(R.id.plus_tvWrong);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
tvWrong.startAnimation( animation );

// Toast.makeText(this, "오답입니다. ", Toast.LENGTH_SHORT).show();
}
// Toast.makeText(this," onMarking - before init() ", Toast.LENGTH_SHORT).show();
this.initScreen();
}

}


public void OnNumericBtnPressed( View v) {
int btnid = v.getId();
int inputNumber=0 ;

if ( cp < 3 ) {
cp = cp + 1;
switch ( btnid ) {
case R.id.numericbutton0 : inputNumber = 0;
break;
case R.id.numericbutton1 : inputNumber = 1;
break;
case R.id.numericbutton2 : inputNumber = 2;
break;
case R.id.numericbutton3 : inputNumber = 3;
break;
case R.id.numericbutton4 : inputNumber = 4;
break;
case R.id.numericbutton5 : inputNumber = 5;
break;
case R.id.numericbutton6 : inputNumber = 6;
break;
case R.id.numericbutton7 : inputNumber = 7;
break;
case R.id.numericbutton8 : inputNumber = 8;
break;
case R.id.numericbutton9 : inputNumber = 9;
break;
}



sum = sum + inputNumber * (int) Math.pow( 10, cp - 1 ) ;
displayResult( sum );

// Toast.makeText(this, "sum="+sum, Toast.LENGTH_SHORT).show();<br></span><span style="color:#808080;font-style:italic;">
}
}

public void displayResult( int num ) {


if ( num > 0 && num <= 9 ) {
tvResultd1.setText( Integer.toString(num));
} else if ( num >= 10 && num <= 99 ) {
int secondDigit = num / 10;
int firstDigit = ( num - ( 10 * secondDigit ) );

tvResultd1.setText( Integer.toString(firstDigit) );
tvResultd10.setText( Integer.toString(secondDigit) );

} else if ( num >= 100 && num <= 999 ) {
int thirdDigit = num / 100;
int temp = ( num - ( 100 * thirdDigit ) );
int secondDigit = temp / 10;
int firstDigit = temp - ( 10 * secondDigit ) ;

tvResultd1.setText( Integer.toString(firstDigit) );
tvResultd10.setText( Integer.toString(secondDigit) );
tvResultd100.setText( Integer.toString(thirdDigit) );
}
}

public void initScreen() {
int qnum;
int rnum;

questionNo = questionNo + 1;

tvOperand1d1.setText( "" );
tvOperand1d10.setText("" );
tvOperand2d1.setText( "" );
tvOperand2d10.setText( "" );
tvOperand2d100.setText("" ); // null pointer

operand1 = getRandomNumber(18,1);
// Toast.makeText(this," operand 1 = " + operand1, Toast.LENGTH_SHORT).show();

if ( operand1 >= 1 && operand1 <= 9 ) {
tvOperand1d1.setText( Integer.toString( operand1 ) );
} else {
qnum = operand1 / 10;
rnum = operand1 - ( qnum * 10 );
tvOperand1d1.setText( Integer.toString( rnum ) );
tvOperand1d10.setText( Integer.toString( qnum ) );
}


operand2 = getRandomNumber(18,1);
// Toast.makeText(this," operand 2 = " + operand2, Toast.LENGTH_SHORT).show();
if ( operand2 >= 1 && operand2 <= 9 ) {
tvOperand2d1.setText( Integer.toString( operand2 ) );
tvOperand2d100.setText( "+" );
} else {
qnum = operand2 / 10;
rnum = operand2 - ( qnum * 10 );
tvOperand2d1.setText( Integer.toString( rnum ) );
tvOperand2d10.setText( Integer.toString( qnum ) );
tvOperand2d100.setText( "+" ); // null pointer
}

tvResultd1.setText(" ");
tvResultd10.setText(" ");
tvResultd100.setText(" ");
cp = 0;
sum = 0;
}

}

코딩뉴빈데

이코드를 뺄셈, 곱셈, 나눗셈으로 바꿔줘 개새끼들아