今天我們要來做一個專案,我要做一個計算機,以我們所學的來說技術方面很簡單,但邏輯方面會比較難,以我來說要動點腦子燒腦袋,還不一定能做出完美無BUG的情況!
首先先附上我的程式介面
接著來講解各個按鈕與程式
所有的參數
TextView number;
double num;
double num1;
double num2 = 0;
double tempplus;
double tempnegetive;
double temptime;
double tempdevide;
double temp = 0;
double plus =0;
double negetive =0;
double time = 1;
double devide = 1;
int record = 5;
int recordplus = 1;
int recordnegetive =1;
int recordtime = 1;
int recorddevide =1;
int warming = 0;
數字與原理
public void count(){
num = (num2 * 10)+ num1;
num2 = num;
warming = 0;
}
public void one(View view){
num1 = 1;
count();
number.setText(num+"");
}
public void two(View view){
num1 = 2;
count();
number.setText(num+"");
}
public void three(View view){
num1 = 3;
count();
number.setText(num+"");
}
public void four(View view){
num1 = 4;
count();
number.setText(num+"");
}
public void five(View view){
num1 = 5;
count();
number.setText(num+"");
}
public void six(View view){
num1 = 6;
count();
number.setText(num+"");
}
public void seven(View view){
num1 = 7;
count();
number.setText(num+"");
}
public void eight(View view){
num1 = 8;
count();
number.setText(num+"");
}
public void nine(View view){
num1 = 9;
count();
number.setText(num+"");
}
public void zero(View view){
num1 = 0;
count();
number.setText(num+"");
}
按2再按9會變成29,我設計了count方法,count的原理就是,假設我按2,最後num會變成2,再按9,num會變成2X10+9,就會變成29了
接著是AC歸零
public void ac(View view){
number.setText("0");
num = 0;
num1 =0 ;
num2 = 0;
temp = 0;
record = 5;
recordplus = 1;
recordnegetive = 1;
recordtime = 1;
recorddevide = 1;
plus = 0;
negetive = 0;
time = 0;
devide = 0;
}
就把數字變成0,再把參數還原,非常簡單
然後是Delete
public void delete(View view){
if(num >= 10) {
num = (num - num1)/ 10;
num2 = num;
number.setText(num+"");
}else if(num > 0){
num = 0;
num2 = num;
number.setText(num+"");
}
}
假設要按29按成28,就是讓28-8後除以10就是2了,接著再按9就好了
那麼明天再繼續講解其他的按鈕吧,大家可以先猜猜我是怎麼設計的,說不定我們想法相同呢!