Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java - PLEASE ANSWER ASAP. THANK YOU! I have the code below, help me fix my calculation price as shown. HELP. I need the calculation
Java - PLEASE ANSWER ASAP. THANK YOU!
I have the code below, help me fix my calculation price as shown.
HELP. I need the calculation to show the correct price. like shown in the picture above.
For a 29 inch crispy pizza without any toppings it needs to show $33.03
--------------------------------
Here is my code: (xml and main)
MainActivity.java
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 { //Define the Radio group 1 and 2 RadioGroup myRG1, myRG2; // Pizza crust and order option RadioButton crispy, thick, soggy, restaurant, deliver, pickup; // Pizza topping options CheckBox myCB1, myCB2, myCB3, myCB4; // Pizza size SeekBar mySB; // text view for price TextView tv, tv1; // Variables used to calculate the total cost double perInchPrice=0.5,toppingPrice=0.1; int 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); // pizza size inch tv1 = (TextView)findViewById(R.id.TotalPrice); // Setting Radio button group 1 crispy = (RadioButton)findViewById(R.id.crispy); thick = (RadioButton)findViewById(R.id.thick); soggy = (RadioButton)findViewById(R.id.soggy); // Setting Radio button group 2 restaurant = (RadioButton)findViewById(R.id.restaurant); pickup = (RadioButton)findViewById(R.id.pickup); deliver = (RadioButton)findViewById(R.id.deliver); // Radio Group of Crust 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); } }); // Radio Group of Togo or no 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() { 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); } }); mySB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv.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) { } }); } private void calculatePrice(int size) { progress=size; double totalPrice=0,totalToppingPrice=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; } if(myCB1.isChecked()){ totalToppingPrice+=toppingPrice; } if(myCB2.isChecked()){ totalToppingPrice+=toppingPrice; } if(myCB3.isChecked()){ totalToppingPrice+=toppingPrice; } if(myCB4.isChecked()){ totalToppingPrice+=toppingPrice; } totalPrice+=(size*totalToppingPrice)+(size*perInchPrice); tv1.setText("$"+decimalFormat.format(totalPrice)); } }
--------------------------------------------------------------------------------------------
XML Code:
Create a pizza pricing application shown as follows: Crispy MainActivity Crust Topping Anchovies O Thick Pineapple O Soggy O Garlic Okra To go or no? At restaurant O Pickup O Deliver Size 29 in $33.03 o 0 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 Create a pizza pricing application shown as follows: Crispy MainActivity Crust Topping Anchovies O Thick Pineapple O Soggy O Garlic Okra To go or no? At restaurant O Pickup O Deliver Size 29 in $33.03 o 0 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
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