Afternoon all, I am new to Java Programming and am currently studying in this field. The mentor has asked that we create a simple app that allows user to enter amount of tickets and click to compute cost at a set rate of $18 for the two locations. We have been asked to outsource and research to complete the app; so that tickets to (1)Cape Marie cost $20 and tickets to (2)Star Island cost $30. Any help would be greatly appreciated my code is below;
public class MainActivity extends Activity
{
double costPerTicket=18.00;
int numberOfTickets;
double totalCost;
String groupChoice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText tickets=(EditText)findViewById(R.id.txtTickets);
final Spinner group=(Spinner)findViewById(R.id.txtGroup);
Button cost = (Button)findViewById(R.id.btnCost);
cost.setOnClickListener(new OnClickListener()
{
final TextView result=((TextView)findViewById(R.id.txtResult));
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
numberOfTickets=Integer.parseInt(tickets.getText().toString());
totalCost=costPerTicket * numberOfTickets;
DecimalFormat currency=new DecimalFormat("$###,###.##");
groupChoice=group.getSelectedItem().toString();
result.setText("Total cost for "+groupChoice +" is " +currency.format(totalCost));
}
});
}
0 comments:
Post a Comment