请求放置}和;在完成这件事的时候,事情就开始变得棘手了。谢谢你告诉我如何处理这件事,埃里克。 import java.text.DecimalFormat; import java.text.NumberFormat; import android.R.
请求放置}和;在完成这件事的时候,事情就开始变得棘手了。谢谢你告诉我如何处理这件事,埃里克。请求放置}和;在完成这件事的时候,事情就开始变得棘手了。谢谢你告诉我如何处理这件事,埃里克。 import java.text.DecimalFormat; import java.text.NumberFormat; import android.R.,java,Java,请求放置}和;在完成这件事的时候,事情就开始变得棘手了。谢谢你告诉我如何处理这件事,埃里克。 import java.text.DecimalFormat; import java.text.NumberFormat; import android.R.integer; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.widget.Check
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
public class MainActivity extends Activity {
EditText mile,diesel;
Button button1, button2;
TextView tv, tv2, tv3;
private double x, y, z, costper, gallon, litres, ophours, ophour, drive, stopdrive;
CheckBox checkBox1, checkBox2, checkBox3, checkBox4;
NumberFormat format = NumberFormat.getCurrencyInstance();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mile= (EditText) findViewById(R.id.mile);
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(onClickListener);
button2.setOnClickListener(onClickListener);
tv = (TextView) findViewById(R.id.cost);
tv2 = (TextView) findViewById(R.id.cpm);
tv3 = (TextView) findViewById(R.id.gallons);
diesel= (EditText) findViewById(R.id.diesel);
}
private OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(final View v) {
switch(v.getId()){
case R.id.button1:
x=Double.parseDouble(mile.getText().toString());
y=Double.parseDouble(diesel.getText().toString());
ophour = x/55;
ophours = 0;
if (ophour>10){
drive = ophour/10;
if (drive>1) {
stopdrive = drive-1;
ophour = ophour + 10;
if (stopdrive>1);
ophour = ophour + (10*stopdrive);
if (stopdrive<1);
ophour = ophour + 10;
}
}
ophours = ((x/55)*10);
}
if (checkBox2.isChecked()) {
x=x*2;
}
if (checkBox1.isChecked()) {
x=x*0.62137;
}
gallon = x/5.5;
if (checkBox4.isChecked()) {
gallon = gallon + (ophour*1.1);
}
if (checkBox3.isChecked()) {
litres = gallon*3.785;
tv3.setText(new DecimalFormat("####.##").format(litres)+"L");
}
z=(gallon*y)+(x*0.655);
costper=z/x;
tv.setText(format.format(z));
tv2.setText(format.format(costper)+"/mile");
tv3.setText(new DecimalFormat("####.##").format(gallon)+"gal.");
break;
case R.id.button2:
Intent browserIntent =
new Intent(Intent.ACTION_VIEW, Url.parse("http://www.google.com"));
startActivity(browserIntent);
break;
}
;};}
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
public class MainActivity extends Activity {
EditText mile,diesel;
Button button1, button2;
TextView tv, tv2, tv3;
private double x, y, z, costper, gallon, litres, ophours, ophour, drive, stopdrive;
CheckBox checkBox1, checkBox2, checkBox3, checkBox4;
NumberFormat format = NumberFormat.getCurrencyInstance();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mile= (EditText) findViewById(R.id.mile);
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(onClickListener);
button2.setOnClickListener(onClickListener);
tv = (TextView) findViewById(R.id.cost);
tv2 = (TextView) findViewById(R.id.cpm);
tv3 = (TextView) findViewById(R.id.gallons);
diesel= (EditText) findViewById(R.id.diesel);
}
private OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(final View v) {
switch(v.getId()){
case R.id.button1:
x=Double.parseDouble(mile.getText().toString());
y=Double.parseDouble(diesel.getText().toString());
ophour = x/55;
ophours = 0;
if (ophour>10){
drive = ophour/10;
if (drive>1) {
stopdrive = drive-1;
ophour = ophour + 10;
if (stopdrive>1); // This IF statement will ALWAYS execute; remove the ";"
ophour = ophour + (10*stopdrive);
if (stopdrive<1); // This IF statement will ALWAYS execute; remove the ";"
ophour = ophour + 10;
}
}
ophours = ((x/55)*10);
} // This should not be here
if (checkBox2.isChecked()) {
x=x*2;
}
if (checkBox1.isChecked()) {
x=x*0.62137;
}
gallon = x/5.5;
if (checkBox4.isChecked()) {
gallon = gallon + (ophour*1.1);
}
if (checkBox3.isChecked()) {
litres = gallon*3.785;
tv3.setText(new DecimalFormat("####.##").format(litres)+"L");
}
z=(gallon*y)+(x*0.655);
costper=z/x;
tv.setText(format.format(z));
tv2.setText(format.format(costper)+"/mile");
tv3.setText(new DecimalFormat("####.##").format(gallon)+"gal.");
break;
case R.id.button2:
Intent browserIntent =
new Intent(Intent.ACTION_VIEW, Url.parse("http://www.google.com"));
startActivity(browserIntent);
break;
// There should be a "}" here.
};
};
}