Answered step by step
Verified Expert Solution
Question
1 Approved Answer
-----Related to Android mobile app development need help with the code. The only problem I'm having is when i click on thick or soggy, the
-----Related to Android mobile app development
need help with the code. The only problem I'm having is when i click on thick or soggy, the price doesn't change. When clicked on thick, the price is supposed to go up by $2.50 and when clicked on soggy, the price should go up by $5.00. Also, when i click on deliver the price doesn't change as well, its supposed to go up by $3.00.
The source code that I have is posted below. Please let me know what's wrong or how to fix the price. Thank You!
SOURCE CODE:
package com.example.lab2; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; import java.text.DecimalFormat; import java.text.NumberFormat; public class MainActivity extends AppCompatActivity{ RadioGroup myRG1, myRG2; RadioButton crispy,thick, soggy, restaurant, deliver, pickup; CheckBox myCB1, myCB2, myCB3, myCB4; SeekBar mySB; TextView tv, tv1, tv2, tv3, tv4, tv5; double perInchPrice=0.05; double toppingPrice=0.05; double progress=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myRG1= (RadioGroup)findViewById(R.id.radiogroup1); myRG2=(RadioGroup)findViewById(R.id.radiogroup2); myCB1=(CheckBox)findViewById(R.id.checkBox); myCB2=(CheckBox)findViewById(R.id.checkBox2); myCB3=(CheckBox)findViewById(R.id.checkBox3); myCB4=(CheckBox)findViewById(R.id.checkBox4); mySB=(SeekBar)findViewById(R.id.seekBar); tv=(TextView)findViewById(R.id.textView5); tv1=(TextView)findViewById(R.id.TotalPrice); tv2=(TextView)findViewById(R.id.Price); tv3=(TextView)findViewById(R.id.textView); tv4=(TextView)findViewById(R.id.textView2); tv5=(TextView)findViewById(R.id.textView7); crispy=(RadioButton)findViewById(R.id.crispy); thick=(RadioButton)findViewById(R.id.thick); soggy=(RadioButton)findViewById(R.id.soggy); restaurant=(RadioButton)findViewById(R.id.restaurant); pickup=(RadioButton)findViewById(R.id.pickup); deliver=(RadioButton)findViewById(R.id.deliver); mySB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv3.setText(progress + "in"); calculatePrice(progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { Toast.makeText(MainActivity.this,"started",Toast.LENGTH_SHORT); } @Override public void onStopTrackingTouch(SeekBar seekBar){ } }); myRG1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group,int checkedId){ int currentId= myRG1.getCheckedRadioButtonId(); RadioButton currentRB=(RadioButton)findViewById(currentId); Toast.makeText(getApplicationContext(),currentRB.getText(),Toast.LENGTH_SHORT); calculatePrice(progress); } }); myRG2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group,int checkedId){ int currentId= myRG2.getCheckedRadioButtonId(); RadioButton currentRB=(RadioButton)findViewById(currentId); Toast.makeText(getApplicationContext(),currentRB.getText(),Toast.LENGTH_SHORT); calculatePrice(progress); } }); myCB1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(buttonView==myCB1 && isChecked) Toast.makeText(getApplicationContext(),myCB1.getText(),Toast.LENGTH_SHORT).show(); calculatePrice(progress); } }); myCB2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(buttonView==myCB2 && isChecked) Toast.makeText(getApplicationContext(),myCB2.getText(),Toast.LENGTH_SHORT).show(); calculatePrice(progress); } }); myCB3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(buttonView==myCB3 && isChecked) Toast.makeText(getApplicationContext(),myCB3.getText(),Toast.LENGTH_SHORT).show(); calculatePrice(progress); } }); myCB4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(buttonView==myCB4 && isChecked) Toast.makeText(getApplicationContext(),myCB4.getText(),Toast.LENGTH_SHORT).show(); calculatePrice(progress); } }); } private void calculatePrice(double size) { progress=size; double radius= size/2; double totalToppingPrice=0, totalPrice=0; DecimalFormat decimalFormat= new DecimalFormat(".##"); if(myRG1.getCheckedRadioButtonId()==thick.getId()) { totalPrice=totalPrice+ 2.50; } else if (myRG1.getCheckedRadioButtonId()==soggy.getId()) { totalPrice=totalPrice+ 5.00; } if(myRG2.getCheckedRadioButtonId()==deliver.getId()) { totalPrice=totalPrice+ 3.00; } else if(myRG2.getCheckedRadioButtonId()==restaurant.getId()) { totalPrice=totalPrice+ 0.00; } else if(myRG2.getCheckedRadioButtonId()==pickup.getId()) { totalPrice=totalPrice+ 0.00; } if(myCB1.isChecked()){ totalToppingPrice+=toppingPrice; } if(myCB2.isChecked()){ totalToppingPrice+=toppingPrice; } if(myCB3.isChecked()){ totalToppingPrice+=toppingPrice; } if(myCB4.isChecked()){ totalToppingPrice+=toppingPrice; } totalPrice=(size*totalToppingPrice)+ (3.14159* (radius* radius))*perInchPrice; tv4.setText("$"+ decimalFormat.format(totalPrice)); } }MainActivity Crust Topping Crispy Anchovies O Thick O Pineapple O Soggy O Garlic O Okra To go or no? At restaurant O Pickup O O Deliver Size 29 in $33.03 o o O $.05 per square inch $.05 per topping per square inch Different crust types . No surcharge for crispy $2.50 extra for thick crust $5.00 extra for soggy crust Different delivery options . At the restaurant or pickup, no charge Delivery charge is $3.00 O The application will react whenever the state of a control changes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started