Welcome to the Ranch!
I was wondering if there is an easier( and more beautiful to the eye) way to calculate several variables
Yes, there is a more
elegant way to do the calculation. In fact, there are at least two options that are more elegant.
First, if you want to make your method flexible, then the parameters you declare in its signature should not have to change when you add more items. This means that the way you've written it now needs to be changed.
Next, instead of individual independent items, you need to put the things you want to treat as a group into a collection. You can use a Map with the id as the key and the price as the value. Alternatively, you can define a MenuItem class and use that as the map value. You may need two Maps: one for the menu items, one for the items selected by the user. Alternatively, if you use a MenuItem class and override its
equals() and
hashCode() methods, you can use a List to hold the items that were selected.
In your onCreate() method, you'd configure your checkboxes to respond to click events by adding an onClick listener. Search for "
Android add onClick listeners for checkboxes" You only need one listener method. It would use the view.getId() method to look up the id of the checkbox that was clicked and use that id to find a MenuItem object in you menu map. Then you can either add/remove that MenuItem object into your selected item list or you can simply add/subtract its price from a running total variable.
BTW, they are if-statements, not if-loops. A loop does something multiple times. An if-statement's body is executed only once and only when its conditional expression is true.