public Customer getCustomer(String customerID) {
    try {
      global.openDBconnection();

      int customer_id = Integer.parseInt(customerID);

      global.select_customer_where_status_customer_id.setBoolean(1, true);
      global.select_customer_where_status_customer_id.setInt(2, customer_id);
      ResultSet rs = global.select_customer_where_status_customer_id.executeQuery();
      if (rs.next()) {
        Customer customer = new Customer();
        customer.set_customer(
            rs.getInt("id"),
            rs.getString("email"),
            new Date(rs.getTimestamp("registered").getTime()),
            rs.getBoolean("status"),
            rs.getString("phonenumber"),
            rs.getString("license_firstname"),
            rs.getString("license_middlename"),
            rs.getString("license_lastname"),
            rs.getDate("license_birthdate"),
            rs.getDate("license_expiration"),
            rs.getString("license_state"),
            rs.getString("license_no"),
            new Date(rs.getTimestamp("membership_exp").getTime()),
            rs.getDouble("balance"));
        customer.setUsername(rs.getString("username"));

        return customer;
      }

      return new Customer();
    } catch (Exception e) {
      System.err.println(e.getMessage());
      return new Customer();
    } finally {
      global.closeDBconnection();
    }
  }
  public List<Customer> getAllCustomers() {
    try {
      global.openDBconnection();

      List<Customer> customers = new ArrayList<Customer>();

      global.select_customer_where_status.setBoolean(1, true);
      ResultSet rs = global.select_customer_where_status.executeQuery();
      while (rs.next()) {
        Customer customer = new Customer();
        customer.set_customer(
            rs.getInt("id"),
            rs.getString("email"),
            new Date(rs.getTimestamp("registered").getTime()),
            rs.getBoolean("status"),
            rs.getString("phonenumber"),
            rs.getString("license_firstname"),
            rs.getString("license_middlename"),
            rs.getString("license_lastname"),
            rs.getDate("license_birthdate"),
            rs.getDate("license_expiration"),
            rs.getString("license_state"),
            rs.getString("license_no"),
            new Date(rs.getTimestamp("membership_exp").getTime()),
            rs.getDouble("balance"));
        customer.setUsername(rs.getString("username"));

        customers.add(customer);
      }

      return customers;
    } catch (Exception e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      return new ArrayList<Customer>();
    }
  }
  public Customer get_customer() {
    try {
      global.openDBconnection();

      Customer customer = new Customer();
      int membership_id = 0;

      // set from user table
      customer.set_user(data.getUser_id(), data.getUsername());

      // set from customer table
      global.select_customer_where_id.setInt(1, data.getCustomer_id());
      ResultSet rs = global.select_customer_where_id.executeQuery();
      if (rs.next()) {
        customer.set_customer(
            data.getCustomer_id(),
            rs.getString("email"),
            new Date(rs.getTimestamp("registered").getTime()),
            rs.getBoolean("status"),
            rs.getString("phonenumber"),
            rs.getString("license_firstname"),
            rs.getString("license_middlename"),
            rs.getString("license_lastname"),
            rs.getDate("license_birthdate"),
            rs.getDate("license_expiration"),
            rs.getString("license_state"),
            rs.getString("license_no"),
            new Date(rs.getTimestamp("membership_exp").getTime()),
            rs.getDouble("balance"));

        membership_id = rs.getInt("membership_id");
      }

      // set from customer address table
      global.select_customer_address_where_customer_id.setInt(1, data.getCustomer_id());
      rs = global.select_customer_address_where_customer_id.executeQuery();
      if (rs.next()) {
        customer.set_customer_address(
            rs.getInt("id"),
            rs.getString("name"),
            rs.getString("street1"),
            rs.getString("street2"),
            rs.getString("city"),
            rs.getString("state"),
            rs.getString("zip"));
      }

      // set from customer creditcard table
      global.select_customer_creditcard_where_customer_id.setInt(1, data.getCustomer_id());
      rs = global.select_customer_creditcard_where_customer_id.executeQuery();
      if (rs.next()) {
        customer.set_customer_creditcard(
            rs.getInt("id"),
            rs.getString("no"),
            rs.getString("code"),
            rs.getDate("expires"),
            rs.getString("firstname"),
            rs.getString("lastname"),
            rs.getString("street1"),
            rs.getString("street2"),
            rs.getString("city"),
            rs.getString("state"),
            rs.getString("zip"));
      }

      // set from customer table
      if (membership_id == 0) {
        customer.set_membership(membership_id, "Free", "", 0.0, 0);
      } else {
        global.select_membership_where_id.setInt(1, membership_id);
        rs = global.select_membership_where_id.executeQuery();
        if (rs.next()) {
          customer.set_membership(
              membership_id,
              rs.getString("name"),
              rs.getString("description"),
              rs.getDouble("price"),
              rs.getInt("months"));
        }
      }

      return customer;
    } catch (Exception e) {
      System.err.println(e.getMessage());
      return new Customer();
    } finally {
      global.closeDBconnection();
    }
  }
Beispiel #4
0
  public static boolean pack(ArrayList<Customer> customers, VehicleType ve) {
    double u = 0;
    ArrayList<Item> unpacked = new ArrayList<Item>();
    ArrayList<Item> packed = new ArrayList<Item>();
    for (Customer c : customers) {
      for (Item it : c.get_items()) {
        unpacked.add(it);
        u += it.get_area();
      }
    }
    u = u / ve.get_area();

    for (Item item : unpacked) {
      double vi = omega * item.get_area() + (1 - omega) * Math.pow(item.get_area(), p) / u;
      item.setUi(vi / item.get_area());
    }

    // 1. sorting
    Collections.sort(unpacked, Item.sort_by_Ui);
    // 2. loop
    int size = unpacked.size();
    double maxRemainArea = 0;
    for (int i = 0; i < size; ++i) {
      int k = -1;
      Item it = unpacked.get(i);
      for (int j = 0; j < ve.pos.size(); ++j) {
        // 3. inside loop you do GetLB
        if (couldPutHere(it, ve.pos.get(j), ve)) {
          int res = getLB(it, ve.pos.get(j), ve);

          if (maxRemainArea < res) {
            maxRemainArea = res;
            k = j;
          }
        }
      }
      if (k != -1) {
        Posi_tion positon = ve.pos.get(k);
        unpacked.remove(i);
        packed.add(it);
        it.set_item_x(positon.getX());
        it.set_item_y(positon.getY());
        // reset ve.pos;

        int x1 = ve.pos.get(k).getX() + it.get_width();
        int y1 = ve.pos.get(k).getY() + it.get_length();
        int itArea = it.get_length() * it.get_width();

        // Situation 1
        if (ve.pos.size() == 1) {
          remainArea = ve.get_area() - itArea;
          ve.pos.remove(0);
          ve.pos.add(new Posi_tion(0, it.get_length()));
          ve.pos.add(new Posi_tion(it.get_width(), 0));
        }

        // Need to find all possible positions to put new item and put all positions in the
        // arraylist pos.

        // Situation 2
        /*
        if (ve.pos.get(k).getX() == 0)
        {
        	if (x1 < ve.pos.get(1).getX())
        	{
        		ve.remainArea = ve.remainArea - itArea;
        		ve.pos.add(new Position(0, ve.pos.get(0).y
        				+ it.get_width()));
        		ve.pos.add(new Position(it.get_length(),
        				veve.pos.sort(new PosComp());.pos.get(0).y));
        		ve.pos.remove(0);
        		ve.pos.sort(new PosComp());
        	} else
        	{
        		ve.remainArea = ve.remainArea - itArea
        				- (x1 - ve.pos.get(1).x)
        				* (ve.pos.get(0).y - ve.pos.get(1).y);
        		ve.pos.add(new Position(0, ve.pos.get(0).y
        				+ it.get_width()));
        		ve.pos.add(new Position(it.get_length(),
        				ve.pos.get(1).y));
        		ve.pos.remove(0);
        		ve.pos.sort(new PosComp());
        	}
        }
        // Situation 3
        if (ve.pos.get(k).y == 0)
        {
        	if (y1 < ve.pos.get(ve.pos.size() - 1).y)
        	{
        		ve.remainArea = ve.remainArea - itArea;
        		ve.pos.add(new Position(ve.pos.get(k).x,
        				ve.pos.get(k).y + it.get_width()));
        		ve.pos.add(new Position(x1, 0));
        		ve.pos.remove(k);
        		ve.pos.sort(new PosComp());
        	} else
        	{
        		ve.remainArea = ve.remainArea
        				- itArea
        				- (ve.pos.get(k).x - ve.pos
        						.get(ve.pos.size() - 2).x)
        				* (y1 - ve.pos.get(ve.pos.size() - 2).y);
        		ve.pos.add(new Position(ve.pos.get(k - 1).x, y1));
        		ve.pos.add(new Position(x1, 0));
        		ve.pos.remove(k);
        		ve.pos.sort(new PosComp());
        	}
        }
        // Situation 4
        int ip = ve.pos.indexOf(ve.pos.get(k));
        if (x1 < ve.pos.get(ip + 1).x && y1 < ve.pos.get(ip - 1).y)
        {
        	ve.remainArea = ve.remainArea - itArea;
        	ve.pos.add(new Position(ve.pos.get(k).x, y1));
        	ve.pos.add(new Position(x1, ve.pos.get(k).y));
        	ve.pos.remove(k);
        	ve.pos.sort(new PosComp());
        } else if (y1 >= ve.pos.get(ip - 1).y)
        {
        	ve.remainArea = ve.remainArea - itArea
        			- (ve.pos.get(k).x - ve.pos.get(ip - 1).x)
        			* (y1 - ve.pos.get(ip - 1).y);
        	ve.pos.add(new Position(ve.pos.get(k - 1).x, y1));
        	ve.pos.add(new Position(x1, ve.pos.get(k).y));
        	ve.pos.remove(k);
        	ve.pos.sort(new PosComp());
        } else if (x1 > ve.pos.get(ip + 1).x)
        {
        	ve.remainArea = ve.remainArea - itArea
        			- (x1 - ve.pos.get(ip + 1).x)
        			* (y1 - ve.pos.get(ip + 1).y);
        	ve.pos.add(new Position(ve.pos.get(k).x, y1));
        	ve.pos.add(new Position(x1, ve.pos.get(k + 1).y));
        	ve.pos.remove(k);
        	ve.pos.sort(new PosComp());
        } else
        	;*/
      }
    }
    if (unpacked.size() != 0) return false;
    else return true;
  }