Question: Please help modify the web application code to calculate a total cost for the selected books. Current code: ***//SelectionsBeans Class//*** // SelectionsBean.java // Manages a
Please help modify the web application code to calculate a total cost for the selected books.
Current code:
***//SelectionsBeans Class//***
// SelectionsBean.java // Manages a user's topic selections
package sessiontracking;
import java.io.Serializable; import java.util.HashMap; import java.util.Set; import java.util.TreeSet; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped;
@ManagedBean(name="selectionsBean") @SessionScoped public class SelectionsBeans implements Serializable { // map of topics to book titles private static final HashMap< String, String > booksMap = new HashMap< String, String >();
// intialize booksMap static { booksMap.put("java", "$205 - Java How to Program"); booksMap.put("cpp", "$190 - C++ How to Program"); booksMap.put("iphone", "$430 - iPhone for Programmers: An App-Driven Approach"); booksMap.put("android", "$297 - Android for Programmers: An App-Driven Approach"); } // end static initalizer block
// stores individual user's selections private Set< String > selections = new TreeSet< String >(); private String selection; // stores the current selection private int total=0;
// return number of selections public int getNumberOfSelections() { return selections.size(); }
// returns the currrent selection public String getSelection() { return selection; } // end method getSelection
// store user's selection public void setSelection(String topic) { selection = booksMap.get(topic); selections.add(selection); } // end method setSelection
// return the Set of selections public String[] getSelections() { return selections.toArray(new String[selections.size()]); } // end method getSelections } // end class SelectionsBean
***//index.xhtml//***
You have chosen #{selectionsBean.numberOfSelections} selection(s) Welcome to Sessions!
Make a Selection and Press Submit
***//shoppingcart html//***
Shopping Cart
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
