shoppingcartbean.java

来自「100多M的J2EE培训内容」· Java 代码 · 共 87 行

JAVA
87
字号
package sfsbsample;

import javax.ejb.*;
import java.util.*;
public class ShoppingCartBean implements SessionBean {
  SessionContext sessionContext;
  private String userId;
  private String userName;
  private Vector MyScheduleList;

  public void ejbCreate() throws CreateException {
    System.out.println(" *** ShoppingCartEJB - ejbCreate() ***");
    MyScheduleList = new Vector(10);
  }
  public void ejbCreateCustom(String aUserId, String aUserName) throws CreateException {
    System.out.println("  ***ShoppingCartEJB - ejbCreate(arg1, arg2) ****");
    userId = aUserId;
    userName = aUserName;
    MyScheduleList = new Vector(20);
  }
  public void ejbRemove() {
    /**@todo Complete this method*/
  }
  public void ejbActivate() {
    /**@todo Complete this method*/
  }
  public void ejbPassivate() {
    /**@todo Complete this method*/
  }
  public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
  }
  public void addASchedule(ScheduleVO schedule) {
    System.out.println(
        "  ***ShoppingCartEJB -- addASchedule() called schedID: " +
        schedule.getScheduleID());
    System.out.println("  ***ShoppingCartEJB - got a schedule " +
                       schedule.getCourseTitle());
    MyScheduleList.add(schedule);
    System.out.println("  ***ShoppingCartEJB - added a schedule to the list");
  }
  public void deleteASchedule(String ScheduleId) {
    //delete a ScheduleVO from a Vector list
    System.out.println("  ***ShoppingCartEJB -- deleteASchedule() called ");
    for (int j = 0; j <= MyScheduleList.size(); j++) {
      ScheduleVO sched = (ScheduleVO) MyScheduleList.get(j);
      if ( (sched.getScheduleID()).equals(ScheduleId))
        MyScheduleList.removeElementAt(j);
   }
  }

  public java.util.Vector getMyScheduleList() {
    //return the updated ScheduleList vector
        System.out.println("  ***ShoppingCartEJB - returnig MyScheduleList size =>"+MyScheduleList.size());
        return MyScheduleList;
  }

  public void emptyMyScheduleList() {
    //clear the ScheduleList vector
       MyScheduleList.removeAllElements();
       System.out.println("  *** ShoppingCartEJB emptied out MyScheduleList size "+MyScheduleList.size());
  }
  public double getTotalCost() {
    //add option to read the local and state sales tax from the env.
    double taxRate = getTaxRate();

    //extract cost per schedules from the ScheduleList, add up the total and return
    double total = 0.0;
    double sum = 0.0;
    for (int i = 0; i <= MyScheduleList.size(); i++) {
      ScheduleVO sched = (ScheduleVO) MyScheduleList.elementAt(i);
      sum += (double) sched.getCost();
    }
    total = (sum * taxRate);
    System.out.println("  ***In ShoppingCartEJB total cost =" + total);
    return total;
  }
  private double getTaxRate()
  {
      //read the local state and local tax information from the env.
      return 1.0;
  }

  public void checkOut() {
    /**@todo Complete this method*/
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?