-1

我正在尝试创建一个根据用户输入返回分数的应用程序。

例如,如果用户在特定站点上有 1000 个帖子,它将返回 1。我将在 10000 处结束。

1000 = 1 2000 = 2 等等。

这是我到目前为止所拥有的,谢谢。这个网站很棒。现在我只添加每个条目。值 1+值 2 等。

public class DataIn extends Activity {

EditText editPostCount;
EditText editThanksCount;
EditText editRomCount;
EditText editThemeCount;
EditText editKernelCount;
EditText editTutorialCount;
EditText editYearsJoined;
Button mButton;
TextView results;
Button mButton1;

@Override
public void onCreate (Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.data_in);
android.app.ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

editPostCount = (EditText)findViewById(R.id.editPostCount);
editThanksCount = (EditText)findViewById(R.id.editThanksCount);
editRomCount =  (EditText)findViewById(R.id.editRomThreads);
results = (TextView)findViewById(R.id.results);
editThemeCount = (EditText)findViewById(R.id.editThemeCount);
editKernelCount = (EditText)findViewById(R.id.editKernelCount);
editTutorialCount = (EditText)findViewById(R.id.editTutorialCount);
editYearsJoined = (EditText)findViewById(R.id.editYearsJoined);

mButton = (Button)findViewById(R.id.results_button);
mButton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
         //When the button is clicked, call the calucate method.
         calculate();
        }
});


private void calculate() {
    try {

        Double value1 = Double.parseDouble(editPostCount.getText().toString());
        Double value2 = Double.parseDouble(editThanksCount.getText().toString());
        Double value3 = Double.parseDouble(editRomCount.getText().toString());
        Double value4 = Double.parseDouble(editKernelCount.getText().toString());
        Double value5 = Double.parseDouble(editThemeCount.getText().toString());
        Double value6 = Double.parseDouble(editYearsJoined.getText().toString());
        Double value7 = Double.parseDouble(editTutorialCount.getText().toString());
      //do the calculation

        Double calculatedValue = (value1+value2+value3+value4+value5+value6+value7);
        //set the value to the textView, to display on screen.
        results.setText(calculatedValue.toString());


    } catch (NumberFormatException e) {
        // EditText EtPotential does not contain a valid double
    }

mButton1 = (Button)findViewById(R.id.clear_button);
mButton1.setOnClickListener(new OnClickListener() {

     public void onClick(View v) {

          editPostCount.setText("");
          editThanksCount.setText("");
          editRomCount.setText("");
          editThemeCount.setText("");
          editKernelCount.setText("");
          editTutorialCount.setText("");
          editYearsJoined.setText("");
             results.setText("");}
 });

    }   }
4

2 回答 2

0

我希望我没有误解你的问题,但是如果你想让分数每1000个帖子加1分,你只需将帖子数除以1000。例如:

//value1 is the post count
int calculatedvalue = value1/1000;

所以如果posts(value1)的数量是3500,那么计算出来的值就是3。(除法时将余数截断)

于 2013-08-25T21:37:13.563 回答
0

您可以使用简单的除法来获得每个值的分数,即切为整数。在这个例子中,我还定义了一个常数来为每个不同的值确定一个特定的分数因子。

private static final int TOTALCOUNT_SCOREFACTOR = 1000;

int totalCountScore = totalCount / TOTALCOUNT_SCOREFACTOR;

我建议你不要使用双打,一般 int 就足够了。我还建议您使用一组值,而不是单独定义所有值。这样,您将来可以轻松地添加或删除值。

于 2013-08-25T21:53:27.613 回答