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//***

Topic Selection Page

Welcome to Sessions!

You have chosen #{selectionsBean.numberOfSelections} selection(s)

Make a Selection and Press Submit

Click here for Check Out Page

***//shoppingcart html//***

Shopping Cart

Shopping Cart

  • #{book}

Click here to choose another topic

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!