Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with android mobile app code. I am having trouble with the java file. The calculations is not showing correct. Here is what it

Need help with android mobile app code. I am having trouble with the java file. The calculations is not showing correct.

Here is what it should look like:

image text in transcribed

REQUIREMENTS

image text in transcribed

WHAT I HAVE

image text in transcribed

******here, when clicked on crispy and at restaurant with 29 inch size, the price should be $33.03. My price is not correct.

The java code that i have:

package com.example.lab2; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.provider.MediaStore; 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; 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); 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(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); tv4.setText("$"+ decimalFormat.format(totalPrice)); } } 

MainActivity Crust Topping Crispy Anchovies O Thick Pineapple O Soggy Garlic O Okra To go or no? At restaurant O Pickup O Deliver Size 29 in $33.03 O 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. 8:34 O @ Lab2 dio Crust Topping anchovies O crispy O thick soggy 13 pineapple garlic okra To go or no? O pickup O restaurant O deliver on Size 29in $1.45

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions