大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
用Vector 或者是HashMap去装
为碾子山等地区用户提供了全套网页设计制作服务,及碾子山网站建设行业解决方案。主营业务为成都网站制作、成都网站设计、碾子山网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
下面有部分代码你去看吧
package com.aptech.restrant.DAO;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.sql.Connection;
import com.aptech.restrant.bean.CartItemBean;
import com.aptech.restrant.bean.FoodBean;
public class CartModel {
private Connection conn;
public CartModel(Connection conn) {
this.conn=conn;
}
/**
* 得到订餐列表
*
* @return
*/
public List changeToList(Map carts) {
// 将Set中元素转换成数组,以便使用循环进行遍历
Object[] foodItems = carts.keySet().toArray();
// 定义double变量total,用于存放购物车内餐品总价格
double total = 0;
List list = new ArrayList();
// 循环遍历购物车内餐品,并显示各个餐品的餐品名称,价格,数量
for (int i = 0; i foodItems.length; i++) {
// 从Map对象cart中取出第i个餐品,放入cartItem中
CartItemBean cartItem = (CartItemBean) carts
.get((String) foodItems[i]);
// 从cartItem中取出FoodBean对象
FoodBean food1 = cartItem.getFoodBean();
// 定义int类型变量quantity,用于表示购物车中单个餐品的数量
int quantity = cartItem.getQuantity();
// 定义double变量price,表示餐品单价
double price = food1.getFoodPrice();
// 定义double变量,subtotal表示单个餐品总价
double subtotal = quantity * price;
// // 计算购物车内餐品总价格
total += subtotal;
cartItem.setSubtotal(subtotal);
cartItem.setTotal(total);
list.add(cartItem);
}
return list;
}
/**
* 增加订餐
*/
public Map add(Map cart, String foodID) {
// 购物车为空
if (cart == null) {
cart = new HashMap();
}
FoodModel fd = new FoodModel(conn);
FoodBean food = fd.findFoodById(foodID);
// 判断购物车是否放东西(第一次点餐)
if (cart.isEmpty()) {
CartItemBean cartBean = new CartItemBean(food, 1);
cart.put(foodID, cartBean);
} else {
// 判断当前菜是否在购物车中,false表示当前菜没有被点过。。
boolean flag = false;
// 得到键的集合
Set set = cart.keySet();
// 遍历集合
Object[] obj = set.toArray();
for (int i = 0; i obj.length; i++) {
Object object = obj[i];
// 如果购物车已经存在当前菜,数量+1
if (object.equals(foodID)) {
int quantity = ((CartItemBean) cart.get(object))
.getQuantity();
quantity += 1;
System.out.println(quantity);
((CartItemBean) cart.get(object)).setQuantity(quantity);
flag = true;
break;
}
}
if (flag == false) {
// 把当前菜放到购物车里面
CartItemBean cartBean = new CartItemBean(food, 1);
cart.put(foodID, cartBean);
}
}
return cart;
}
/**
* 取消订餐
*/
public Map remove(Map cart, String foodID) {
cart.remove(foodID);
return cart;
}
/**
* 更新购物车信息
*
* @param cart
* @param foodID
* @return
*/
public MapString, CartItemBean update(Map cart, String foodID,
boolean isAddorRemove) {
Map map;
if (isAddorRemove) {
map = add(cart, foodID);
} else {
map = remove(cart, foodID);
}
return map;
}
}
绑定一个事件到被点击的窗体或控件,点击后获取控件信息,然后传参给一个自定义的窗体类的构造函数,如A = new oneDialog(参数1,参数2....);然后A.setVisible(true)。大概就是这个样子,有不懂得可以继续问
ackage cn.practice1200;
import java.util.Scanner;
public class Eater_Alliance {
/**
* 吃货联盟订餐系统
*
* @author QCD
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
// 初始化3个数组存储菜品、价格、点赞数
String[] dishNames = { "苦瓜炒鸡蛋", "红烧排骨", "辣子鸡丁", "石锅鱼", "麻婆豆腐" };
double[] prices = { 15.0, 30.0, 35.0, 90.0, 20.0 };
int[] praiseNums = new int[5];
// 在初始化6个数组用于存储订单信息
String[] names = new String[5];// 保存订餐人姓名
String[] dishMegs = new String[5];// 保存所选菜品名
int[] dishNums = new int[5];// 保存所选菜品份数
int[] times = new int[5];// 保存送餐时间
String[] addresses = new String[5];// 保存送餐地址
int[] states = new int[5];// 保存订单状态:0表示已预订,1表示已完成
double[] sumPrices = new double[5];// 保存订单的总金额
// 初始化2条订单信息
// 第1条
names[0] = "王大锤";
dishMegs[0] = "辣子鸡丁";
dishNums[0] = 2;
times[0] = 12;
addresses[0] = "莞太路3号";
states[0] = 0;
sumPrices[0] = 70.0;
// 第2条
names[1] = "王大柱";
dishMegs[1] = "麻婆豆腐";
dishNums[1] = 1;
times[1] = 19;
addresses[1] = "建设路2号";
states[1] = 1;
sumPrices[1] = 25.0;
/* 实现菜单切换 */
System.out.println("欢迎使用“吃货联盟订餐系统”");
int num = 1;// 用户输入0返回主菜单否则退出系统
boolean isExit = false;// 标记用户是否退出系统,true为退出
// 循环控制用户输入选择并执行
do {
System.out.println("************************");
System.out.println("1、我要订餐");
System.out.println("2、查看餐袋");
System.out.println("3、签收订单");
System.out.println("4、删除订单");
System.out.println("5、我要点赞");
System.out.println("6、退出系统");
System.out.println("************************");
System.out.print("请选择:");
num = input.nextInt();// 用户输入所要选择进行的操作
/* 使用switch结构来建立选择内容 */
switch (num) {
case 1:// 我要订餐
System.out.println("***我要订餐***");
boolean isAdd = false;// 记录是否可以点餐
for (int i = 0; i names.length; i++) {
if (names[i] == null) {
isAdd = false;
System.out.print("请输入订餐人姓名:");
String name = input.next();
System.out.println("序号" + "\t" + "菜名" + "\t\t" + "单价" + "\t" + "点赞数");
for (int j = 0; j dishNames.length; j++) {
System.out.println(
(j + 1) + "\t" + dishNames[j] + "\t\t" + prices[j] + "元" + "\t" + praiseNums[j]);
}
System.out.print("请选择您要点的菜品编号:");
int chooseDish = input.nextInt();
String dishMeg = dishNames[chooseDish - 1];
System.out.print("请选择您需要的份数:");
int number = input.nextInt();
System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
int time = input.nextInt();
while (time 10 || time 20) {
System.out.print("您的输入有误,请输入10-20间的整数");
time = input.nextInt();
}
System.out.print("请输入送餐地址:");
String address = input.next();
// 默认可以预定,不用写订单状态
System.out.println("订餐成功!");
System.out.println("您定的是:" + dishNames[chooseDish - 1] + number + "份");
System.out.println("送餐时间:" + time + "点");
double sumPrice = prices[chooseDish - 1] * number;// 计算餐费
double sendMoney = (sumPrice = 50) ? 0 : 5;// 计算送餐费
System.out.println("餐费:" + sumPrice + "元," + "送餐费" + sendMoney + "元," + "总计:"
+ (sumPrice + sendMoney) + "元。");
// 添加数据
names[i] = name;
dishMegs[i] = dishMeg;
times[i] = time;
dishNums[i] = number;
addresses[i] = address;
sumPrices[i] = sumPrice + sendMoney;
break;
}
if (isAdd) {
System.out.println("对不起,您的餐袋已满!");
}
}
break;
case 2:// 查看餐袋
System.out.println("***查看餐袋***");
System.out.println("序号\t订餐人\t餐品名称\t餐品数量\t送餐时间\t送餐地址\t总金额\t订单状态");
for (int i = 0; i names.length; i++) {
if (names[i] != null) {
String state = (states[i] == 0) ? "已预订" : "已完成";
System.out.println((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + dishNums[i] + "份"
+ "\t" + times[i] + "\t" + addresses[i] + "\t" + sumPrices[i] + "元" + "\t" + state);
}
}
break;
case 3:// 签收订单
System.out.println("***签收订单***");
boolean isSignFind = false;
System.out.print("请选择要签收的订单序号:");
int sign = input.nextInt();
for (int i = 0; i names.length; i++) {
if (names[i] != null states[i] == 0 sign == i + 1) {
states[i] = 1;
System.out.println("订单签收成功!");
isSignFind = true;// 标记已找到的订单
} else if (names[i] != null states[i] == 1 sign == i + 1) {
System.out.println("您选择的订单已完成签收,不能再次签收!");
isSignFind = true;// 标记已找到的订单
}
}
if (!isSignFind) {
System.out.println("您选择的订单不存在!");
}
break;
case 4:// 删除订单
System.out.println("***删除订单***");
boolean isDelFind = false;
System.out.print("请输入要删除的订单序号:");
int delID = input.nextInt();
for (int i = 0; i names.length; i++) {
// 根据状态值判断能不能删除,只有已完成的才能删除
if (names[i] != null states[i] == 1 delID == i + 1) {
isDelFind = true;
for (int j = delID - 1; j names.length - 1; j++) {
names[j] = names[j + 1];
dishMegs[j] = dishMegs[j + 1];
dishNums[j] = dishNums[j + 1];
times[j] = times[j + 1];
addresses[j] = addresses[j + 1];
states[j] = states[j + 1];
sumPrices[j] = sumPrices[j + 1];
}
// 将最后一位清空
names[names.length - 1] = null;
dishMegs[names.length - 1] = null;
dishNums[names.length - 1] = 0;
times[names.length - 1] = 0;
addresses[names.length - 1] = null;
states[names.length - 1] = 0;
sumPrices[names.length - 1] = 0;
System.out.println("删除订单成功!");
break;
} else if (names[i] != null states[i] == 0 delID == i + 1) {
isDelFind = true;
System.out.println("您选择的订单未签收,不能删除!");
break;
}
} // 未找到的订单不能删除
if (!isDelFind) {
System.out.println("您要删除的订单不存在!");
}
break;
case 5:// 我要点赞
System.out.println("***我要点赞***");
// 显示菜品信息
System.out.println("序号\t菜名\t单价");
for (int i = 0; i dishNames.length; i++) {
String priaiseNum = (praiseNums[i] 0) ? praiseNums[i] + "赞" : "";
System.out.println((i + 1) + "\t" + dishNames[i] + "\t" + prices[i] + "元" + priaiseNum);
}
System.out.print("请选择您要点赞的菜品序号:");
int number = input.nextInt();
praiseNums[number - 1]++;
System.out.println("点赞成功");
break;
case 6:// 退出系统
isExit = true;
break;
default:// 退出系统
isExit = true;
break;
}
// 返回主界面
if (!isExit) {
System.out.print("输入0返回:");
num = input.nextInt();
} else {
break;
}
} while (num == 0);
System.out.println("谢谢惠顾,欢迎您再次使用!");
input.close();
}
}