跪求Java数据结构排队就餐问题经典的生产者消费者模式,网上百度一堆,两种方式,一种blockingqueue阻塞队列,一种逻辑实现
java吃货联盟订餐系统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; inames.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; jdishNames.length; j) {
System.out.println(
(j1)"\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 (time10 || time20) {
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"元,""总计:"
(sumPricesendMoney)"元 。");
// 添加数据
names[i] = name;
dishMegs[i] = dishMeg;
times[i] = time;
dishNums[i] = number;
addresses[i] = address;
sumPrices[i] = sumPricesendMoney;
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; inames.length; i) {
if (names[i] != null) {
String state = (states[i] == 0) ? "已预订" : "已完成";
System.out.println((i1)"\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; inames.length; i) {
if (names[i] != nullstates[i] == 0sign == i1) {
states[i] = 1;
System.out.println("订单签收成功!");
isSignFind = true;// 标记已找到的订单
} else if (names[i] != nullstates[i] == 1sign == i1) {
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; inames.length; i) {
// 根据状态值判断能不能删除,只有已完成的才能删除
if (names[i] != nullstates[i] == 1delID == i1) {
isDelFind = true;
for (int j = delID - 1; jnames.length - 1; j) {
names[j] = names[j1];
dishMegs[j] = dishMegs[j1];
dishNums[j] = dishNums[j1];
times[j] = times[j1];
addresses[j] = addresses[j1];
states[j] = states[j1];
sumPrices[j] = sumPrices[j1];
}
// 将最后一位清空
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] != nullstates[i] == 0delID == i1) {
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; idishNames.length; i) {
String priaiseNum = (praiseNums[i]0) ? praiseNums[i]"赞" : "";
System.out.println((i1)"\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();
}
}
Java新手问问题!请用for循环,while以及do while循环帮我写一个点餐系统,只需要写出消费多少元就行!public class Test {
public static void main(String[] args) {
System.out.println("请问您需要消费多少钱?");
Scanner scan=new Scanner(System.in);
double sum=0d;
double money=scan.nextDouble();
sum =money;
System.out.println("本次消费:" money "元");
System.out.println("请问您是否需要继续消费?(输入1,表示继续消费)");
int isContinue=scan.nextInt();
while(true){
if(isContinue==1){
System.out.println("请问您需要消费多少钱?");
money=scan.nextDouble();
sum =money;
System.out.println("本次消费:" money "元");
System.out.println("请问您是否需要继续消费?(输入1 , 表示继续消费)");
isContinue=scan.nextInt();
}else{
System.out.println("本次消费结束");
System.out.println("总共消费:" sum "元");
break;
}
}
}
}
怎样用Java swing 来做一个点餐系统里面的订单模块,只需要窗体,不需要其他效果 。菜鸟求代码绑定一个事件到被点击的窗体或控件,点击后获取控件信息,然后传参给一个自定义的窗体类的构造函数 , 如A = new oneDialog(参数1 , 参数2....);然后A.setVisible(true) 。大概就是这个样子,有不懂得可以继续问
java小程序源代码,简单点的,100多行,谁有?。浚?/h2>// My car shop.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class carshop extends JFrame
{
// JPanel to hold all pictures
private JPanel windowJPanel;
private String[] cars = { "","阿斯顿马丁", "美洲虎", "凯迪拉克",
"罗孚", "劳斯莱斯","别克"};
private int[] jiage = { 0,150000, 260000, 230000,
140000, 290000, 150000};
// JLabels for first snack shown
private JLabel oneJLabel;
private JLabel oneIconJLabel;
// JLabels for second snack shown
private JLabel twoJLabel;
private JLabel twoIconJLabel;
// JLabels for third snack shown
private JLabel threeJLabel;
private JLabel threeIconJLabel;
// JLabels for fourth snack shown
private JLabel fourJLabel;
private JLabel fourIconJLabel;
// JLabels for fifth snack shown
private JLabel fiveJLabel;
private JLabel fiveIconJLabel;
// JLabels for sixth snack shown
private JLabel sixJLabel;
private JLabel sixIconJLabel;
// JTextField for displaying snack price
private JTextArea displayJTextArea;
// JLabel and JTextField for user input
private JLabel inputJLabel;
private JComboBox selectCountryJComboBox;
private JLabel inputJLabel2;
private JTextField inputJTextField2;
// JButton to enter user input
private JButton enterJButton;
//JButton to clear the components
private JButton clearJButton;
// no-argument constructor
public carshop()
{
createUserInterface();
}
// create and position GUI components; register event handlers
private void createUserInterface()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane();
// enable explicit positioning of GUI components
contentPane.setLayout( null );
// set up windowJPanel
windowJPanel = new JPanel();
windowJPanel.setBounds( 10, 20, 340, 200 );
windowJPanel.setBorder( new LineBorder( Color.BLACK ) );
windowJPanel.setLayout( null );
contentPane.add( windowJPanel );
// set up oneIconJLabel
oneIconJLabel = new JLabel();
oneIconJLabel.setBounds( 10, 20, 100, 65 );
oneIconJLabel.setIcon( new ImageIcon( "images/阿斯顿马丁.jpg" ) );
windowJPanel.add( oneIconJLabel );
// set up oneJLabel
oneJLabel = new JLabel();
oneJLabel.setBounds( 10, 60, 100, 70 );
oneJLabel.setText( "阿斯顿马丁" );
oneJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( oneJLabel );
// set up twoIconJLabel
twoIconJLabel = new JLabel();
twoIconJLabel.setBounds( 120, 20, 100, 65 );
twoIconJLabel.setIcon( new ImageIcon( "images/美洲虎.jpg" ) );
windowJPanel.add( twoIconJLabel );
// set up twoJLabel
twoJLabel = new JLabel();
twoJLabel.setBounds( 110, 60, 100, 70 );
twoJLabel.setText( "美洲虎" );
twoJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( twoJLabel );
// set up threeIconJLabel
threeIconJLabel = new JLabel();
threeIconJLabel.setBounds( 230, 20, 100, 65 );
threeIconJLabel.setIcon( new ImageIcon(
"images/凯迪拉克.jpg" ) );
windowJPanel.add( threeIconJLabel );
// set up threeJLabel
threeJLabel = new JLabel();
threeJLabel.setBounds( 230, 60, 100, 70);
threeJLabel.setText( "凯迪拉克" );
threeJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( threeJLabel );
// set up fourIconJLabel
fourIconJLabel = new JLabel();
fourIconJLabel.setBounds( 10, 100, 100, 65 );
fourIconJLabel.setIcon( new ImageIcon( "images/罗孚.jpg" ) );
windowJPanel.add( fourIconJLabel );
// set up fourJLabel
fourJLabel = new JLabel();
fourJLabel.setBounds( 10, 150, 50, 70 );
fourJLabel.setText( "罗孚" );
fourJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fourJLabel );
// set up fiveIconJLabel
fiveIconJLabel = new JLabel();
fiveIconJLabel.setBounds( 120, 100, 100, 65 );
fiveIconJLabel.setIcon( new ImageIcon(
"images/劳斯莱斯.jpg" ) );
windowJPanel.add( fiveIconJLabel );
// set up fiveJLabel
fiveJLabel = new JLabel();
fiveJLabel.setBounds( 110, 150, 100, 70 );
fiveJLabel.setText( "劳斯莱斯" );
fiveJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fiveJLabel );
// set up sixIconJLabel
sixIconJLabel = new JLabel();
sixIconJLabel.setBounds( 230, 100, 100, 65 );
sixIconJLabel.setIcon( new ImageIcon( "images/别克.jpg" ) );
windowJPanel.add( sixIconJLabel );
// set up sixJLabel
sixJLabel = new JLabel();
sixJLabel.setBounds( 230, 150, 100, 70 );
sixJLabel.setText( "别克" );
sixJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( sixJLabel );
//set up enterJButton
enterJButton = new JButton();
enterJButton.setBounds( 390, 160, 135, 30 );
enterJButton.setText( "Enter" );
contentPane.add( enterJButton );
enterJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when enterJButton is clicked
public void actionPerformed( ActionEvent event )
{
enterJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
//set up clearJButton
clearJButton = new JButton();
clearJButton.setBounds( 390, 200, 135, 30 );
clearJButton.setText( "Clear" );
contentPane.add( clearJButton );
// set up inputJLabel
inputJLabel = new JLabel();
inputJLabel.setBounds( 390, 25, 135, 25 );
inputJLabel.setText( "Please make selection:" );
contentPane.add( inputJLabel );
selectCountryJComboBox = new JComboBox( cars );
selectCountryJComboBox.setBounds( 390, 50, 135, 21 );
selectCountryJComboBox.setMaximumRowCount( 3 );
contentPane.add( selectCountryJComboBox );
// set up inputJTextField
inputJLabel2 = new JLabel();
inputJLabel2.setBounds( 390, 80, 150, 20 );
inputJLabel2.setText( "Input the Numble:" );
contentPane.add( inputJLabel2 );
// set up inputJTextField
inputJTextField2 = new JTextField();
inputJTextField2.setBounds( 390, 100, 135, 25 );
inputJTextField2.setHorizontalAlignment( JTextField.RIGHT );
contentPane.add( inputJTextField2 );
clearJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when clearJButton is clicked
public void actionPerformed( ActionEvent event )
{
clearJButtonActionPerformed( event );
}
} // end anonymous inner class
);
// set up displayJTextField
displayJTextArea = new JTextArea();
displayJTextArea.setBounds( 10, 237,515, 70 );
displayJTextArea.setEditable( false );
contentPane.add( displayJTextArea );
// set properties of application's window
setTitle( "My car Shop" ); // set title bar string
setSize( 550, 360 );// set window size
setVisible( true );// display window
} // end method createUserInterface
private void clearJButtonActionPerformed( ActionEvent event )
{
// clear the JTextFields
inputJTextField2.setText( "" );
displayJTextArea.setText("");
} // end method clearJButtonActionPerformed
private void enterJButtonActionPerformed( ActionEvent event )
{
double z;
double c;
int x;
int y;
x=selectCountryJComboBox.getSelectedIndex();
y=Integer.parseInt(inputJTextField2.getText());
double discountRate;
int amount = Integer.parseInt( inputJTextField2.getText());
switch (amount/5)
{
case 0:
discountRate = 0;
break;
case 1:
discountRate = 1;
break;
case 2:
discountRate = 2;
break;
case 3:
discountRate = 3;
break;
default:
discountRate = 4;
} // end switch statement
c=1-discountRate/100;
z=jiage[x]*y*c;
displayJTextArea.append("你选择的是:" cars[x] ";"
"它的单价是:" jiage[x] ";""你购买该产品的数量是:" y ",""\n" "该数量的折扣是:"
discountRate" %" ";" "本次消费的总价格是:" z "元" "!" "\n");
}
public static void main( String args[] )
{
carshop application = new carshop();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end method main
} // end class carshop
JAVA语言编写的网上订餐系统购物车功能如何实现?用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; ifoodItems.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; iobj.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;
}
}
【求java点餐的源代码 java点菜程序】求java点餐的源代码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于java点菜程序、求java点餐的源代码的信息别忘了在本站进行查找喔 。
推荐阅读
- java中应用redis,java redisson
- 公馆客运站公众号关注,公馆镇客运站
- 捕鱼游戏系统软件开发,一款捕鱼游戏开发需要多少钱
- mysql怎么放图片视频 mysql存图片和视频
- 丽台游戏显卡怎么样,丽台显卡有什么优势
- 恋爱中的养成游戏小说,恋爱中的养成游戏小说百度云
- 微信视频号直播助手电脑版,微信视频号直播有pc端吗
- 用python做求导函数 python求导数调用什么库
- 关于放样数据怎么在电脑上打开的信息