java-logic====吃货联盟

本文介绍了一个简单的餐厅点餐系统的实现方法,包括菜单展示、点餐、订单提交、订单删除和点赞等功能。系统通过Java语言实现,利用Scanner类进行用户输入处理,并通过实体类和功能类来组织代码。

1.系统界面

 

 

 

2.功能一

 

 

 

 

 

 

3.查看餐袋

 

 

4.签收订单

 

 

 

 

5.删除订单

 

 

 

6.我要点赞

 

主要分在两个类中:

第一个类entity,主要的是一些共有的属性

主要代码:

 1 public class entity {
 2 
 3     public String name;
 4     public double money;
 5     public int id;
 6     public int add;
 7     public int num;
 8     public double sumMoney;
 9     public String address;
10     public int time;
11     public int dian=0;
12     public int dingdan;
13 }
View Code

第二个类Menus,主要写功能的实现

  1 package cn.canting;
  2 
  3 import java.io.InputStream;
  4 import java.nio.channels.SelectableChannel;
  5 import java.util.ArrayList;
  6 import java.util.InputMismatchException;
  7 import java.util.Iterator;
  8 import java.util.List;
  9 import java.util.Scanner;
 10 
 11 import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
 12 
 13 public class Menus {
 14     static Scanner input=new Scanner(System.in);
 15     static Scanner input1=new Scanner(System.in);
 16       public  static List<entity> list=new ArrayList<entity>();
 17       public  static List<entity> listNew=new ArrayList<entity>();
 18     public static void main(String[] args) {
 19         boolean flag=true;    
 20         wwd();
 21     }
 22 
 23     public static void wwd(){
 24         
 25         add();
 26         Show();
 27             System.out.println("请输入要使用的功能");
 28             
 29         boolean flag=input.hasNextInt();
 30         
 31             while (!flag) {
 32                  input=new Scanner(System.in);
 33                 System.out.println("请输入数字");
 34                 
 35                 flag=input.hasNextInt();
 36             }
 37             int num=input.nextInt();
 38             num(num);
 39     }
 40     
 41     //显示页面的方法
 42     public static void Show(){
 43         
 44         System.out.println("****************************欢迎来到餐厅***************************");
 45         System.out.println("1.点餐系统");
 46         System.out.println("2.查看订单详情");
 47         System.out.println("3.提交订单");
 48         System.out.println("4.删除订单");
 49         System.out.println("5.点赞系统");
 50         System.out.println("6.退出");
 51     }
 52     public static void num(int num){     
 53 
 54         switch (num) {
 55         case 1:
 56              boolean flags=true;
 57             select();
 58             
 59              int num2=0;
 60              do{
 61                  System.out.println("请输入要点的餐");
 62                  if(!input.hasNextInt()){
 63                      input=new Scanner(System.in);                
 64                      
 65                      flags=false;
 66                  }else {
 67                      num2=input.nextInt();
 68                      flags=true;
 69                  if(num2>3){
 70                      boolean f=true;
 71                     do { System.out.println("请输入正确的点餐编号");
 72                     
 73                     num2=input.nextInt();
 74                     if(num2<=3&&num2>0){
 75                         f=false;
 76                     }
 77                      }while(f==true);
 78                     System.out.println("请输入要点餐的数量");
 79                      int num3=input1.nextInt();
 80                     
 81                      System.out.println("请输入要送餐的地址");
 82                      String address=input1.next();
 83                      boolean flag=false;
 84                      int time=0;
 85                      do{
 86                      System.out.println("请输入要送餐的时间(10点到22点之间)");
 87                     
 88                      time=input1.nextInt();
 89                      if(time>=10&&time<=22){
 90                          flag=false;
 91                      }else {
 92                         System.out.println("请重新输入");
 93                         flag=true;
 94                     }
 95                      }while (flag==true) ;
 96                      for (entity item:list) {
 97                         if(item.id==num2){
 98                             item.dingdan=listNew.size()+1;
 99                             item.address=address;
100                             item.time=time;
101                             item.num=num3;
102                             listNew.add(item);
103                             item.sumMoney=item.money*num3;
104                         }
105                         
106                     }
107                      System.out.println("订餐成功");
108                  }else {
109                                      
110                      System.out.println("请输入要点餐的数量");
111                      int num3=input1.nextInt();
112                     
113                      System.out.println("请输入要送餐的地址");
114                      String address=input1.next();
115                      boolean flag=false;
116                      int time=0;
117                      do{
118                      System.out.println("请输入要送餐的时间(10点到22点之间)");
119                     
120                      time=input1.nextInt();
121                      if(time>=10&&time<=22){
122                          flag=false;
123                      }else {
124                         System.out.println("请重新输入");
125                         flag=true;
126                     }
127                      }while (flag==true) ;
128                      for (entity item:list) {
129                         if(item.id==num2){
130                             item.dingdan=listNew.size()+1;
131                             item.address=address;
132                             item.time=time;
133                             item.num=num3;
134                             listNew.add(item);
135                             item.sumMoney=item.money*num3;
136                         }                        
137                     }
138                      System.out.println("订餐成功");
139                 }
140                  }
141              }while (flags==false);             
142              
143              System.out.println("按0返回");
144              int zero=input.nextInt();
145              if(zero==0){
146                  Show();
147                     System.out.println("请输入要使用的功能");
148                     int num5=input.nextInt();
149                     num(num5);
150              }
151             break;
152            case 2:
153                Showt();
154                 input=new Scanner(System.in);
155                System.out.println("按0返回");
156                 zero=input.nextInt();
157                if(zero==0){
158                    Show();
159                       System.out.println("请输入要使用的功能");
160                       int num5=input.nextInt();
161                       num(num5);
162                }
163             break;
164            case 3:
165                caozuo();
166              input=new Scanner(System.in);
167                System.out.println("按0返回");
168               zero=input.nextInt();
169              if(zero==0){
170                  Show();
171                     System.out.println("请输入要使用的功能");
172                     int num5=input.nextInt();
173                     num(num5);
174              }
175             break;
176            case 4:
177                input=new Scanner(System.in);
178                         delect();
179                      System.out.println("按0返回");
180                        zero=input.nextInt();
181                       if(zero==0){
182                           Show();
183                              System.out.println("请输入要使用的功能");
184                              int num5=input.nextInt();
185                              num(num5);
186                       }
187             break;
188            case 5:
189                zan();
190              input=new Scanner(System.in);
191             System.out.println("按0返回");
192               zero=input.nextInt();
193              if(zero==0){
194                  Show();
195                     System.out.println("请输入要使用的功能");
196                     int num5=input.nextInt();
197                     num(num5);
198              }
199             break;
200            case 6:
201                 System.out.println("退出成功");
202             break;
203         default:
204             break;
205         }        
206     }
207       //添加的订单
208       public static  void add(){
209           
210           entity en=new entity();
211           
212           en.id=1;
213           en.name="红烧牛肉";
214           en.money=25;
215           en.sumMoney=0;
216           en.add=0;
217           
218           entity en1=new entity();
219           
220           en1.id=2;
221           en1.name="红烧猪蹄";
222           en1.money=20;
223           en1.sumMoney=0;
224           en1.add=0;
225           
226           entity en2=new entity();
227           
228           en2.id=3;
229           en2.name="红烧猪肉";
230           en2.money=30;
231           en2.sumMoney=0;
232           en2.add=0;
233           list.add(en);
234           list.add(en1);
235           list.add(en2);
236       }
237       public static void select(){
238           
239           System.out.println("本餐厅菜单****************************");
240           System.out.println("菜品编号\t\t菜品名称\t\t菜品价格\t\t菜品点赞次数");
241           for (entity item : list) {
242             System.out.println(item.id+"\t\t"+item.name+"\t\t"+item.money+"\t\t"+item.add);
243         }         
244       }
245       
246      public static void Showt(){
247          System.out.println("订单编号\t\t菜品编号\t\t菜品名称\t\t菜品价格\t\t送餐地址\t\t点餐数量\t\t总价");
248          for (entity item : listNew) {
249              if(item.dian==1){
250             System.out.println(item.dingdan+"\t\t"+item.id+"\t\t"+item.name+"\t\t"+item.money+"\t\t"+item.address+"\t\t"+item.num+"\t\t"+item.sumMoney);
251         }
252          }
253      }
254      public static void caozuo(){
255          System.out.println("未提交菜单");
256          System.out.println("订单编号\t\t菜品编号\t\t菜品名称\t\t菜品价格\t\t送餐地址\t\t点餐数量\t\t总价");
257          for (entity item : listNew) {
258              if(item.dian==0){
259                  
260             System.out.println(item.dingdan+"\t\t"+item.id+"\t\t"+item.name+"\t\t"+item.money+"\t\t"+item.address+"\t\t"+item.num+"\t\t"+item.sumMoney);
261              }
262          }
263          System.out.println("请选择提交的订单编号");
264          
265          int num=input.nextInt();
266          int num2=0;
267          for (entity item : listNew) {
268              if(item.dian==0){
269          if(num==item.dingdan){
270              item.dian=1;
271              num2=1;
272          }
273              }
274      }
275          if(num2==0){
276              System.out.println("无此编号");
277          }else{
278          System.out.println("提交成功");
279          }
280      }
281      public static void delect(){
282          
283          for (entity item : listNew) {
284              if(item.dian==1){
285                         
286             System.out.println(item.dingdan+"\t\t"+item.id+"\t\t"+item.name+"\t\t"+item.money+"\t\t"+item.address+"\t\t"+item.num+"\t\t"+item.sumMoney);
287         }
288          }
289          System.out.println("请选择删除的订单号码");
290          int num=input.nextInt();
291          int num2=0;
292          for (entity item : listNew) {
293              if(item.dian==0){
294          if(num==item.dingdan){
295              listNew.remove(item);
296              num2=1;
297          }
298              }         
299      }
300          if(num2==0){
301              System.out.println("无此编号");
302          }else {
303              System.out.println("删除成功");
304         }    
305      }
306      public static void zan(){
307          
308          System.out.println("本餐厅菜单****************************");
309          System.out.println("菜品编号\t\t菜品名称\t\t菜品价格\t\t菜品点赞次数");
310          for (entity item : list) {
311             System.out.println(item.id+"\t\t"+item.name+"\t\t"+item.money+"\t\t"+item.add);
312         }
313          System.out.println("请选择点赞的商品编号");
314          int num=input.nextInt();
315          for (entity item : list) {
316              if(item.id==num){
317                  item.add=item.add+1;
318              }         
319          }
320          System.out.println("点赞成功,是否继续(0退出,其他任意数字键继续)");
321          int num2=input.nextInt();
322          if(num2!=0){
323              
324              zan();
325          }
326      }
327      }

 

转载于:https://www.cnblogs.com/hfddz/p/6834212.html

“library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity TrafficLightSystem is Port ( clk_50MHz : in STD_LOGIC; -- 50MHz系统时钟 reset : in STD_LOGIC; -- 系统复位(高有效) red_led : out STD_LOGIC; -- 红灯控制 green_led : out STD_LOGIC; -- 绿灯控制 yellow_led : out STD_LOGIC; -- 黄灯控制 seg_data : out STD_LOGIC_VECTOR(6 downto 0); -- 7段数码管段选 an : out STD_LOGIC_VECTOR(1 downto 0) -- 数码管位选 ); end TrafficLightSystem; architecture Behavioral of TrafficLightSystem is -- 状态定义 type LightState is (S_RED, S_GREEN, S_YELLOW); signal current_state : LightState := S_RED; signal next_state : LightState := S_RED; -- 时钟分频信号 signal clk_1Hz : STD_LOGIC; -- 1Hz时钟(秒级计数) signal clk_1kHz : STD_LOGIC; -- 1kHz时钟(数码管扫描) -- 计数器信号 signal counter : UNSIGNED(7 downto 0) := (others => '0'); constant MAX_COUNT : UNSIGNED(7 downto 0) := to_unsigned(28, 8); -- 29进制(0-28) signal carry_out : STD_LOGIC; -- 进位信号 -- 显示控制 signal display_val : STD_LOGIC_VECTOR(7 downto 0); -- 显示值 signal digit_select : integer range 0 to 1 := 0; -- 当前选择的数码管 signal bcd_tens : STD_LOGIC_VECTOR(3 downto 0); -- 十位BCD signal bcd_units : STD_LOGIC_VECTOR(3 downto 0); -- 个位BCD -- 时钟分频计数器 signal div_1Hz_cnt : integer range 0 to 49999999 := 0; -- 50MHz到1Hz分频 signal div_1kHz_cnt : integer range 0 to 49999 := 0; -- 50MHz到1kHz分频 begin -- ======================================================================= -- 时钟分频器(50MHz -> 1Hz) -- ======================================================================= clk_divider: process(clk_50MHz, reset) begin if reset = '1' then div_1Hz_cnt <= 0; clk_1Hz <= '0'; elsif rising_edge(clk_50MHz) then if div_1Hz_cnt = 49999999 then -- 50MHz/(50M) = 1Hz div_1Hz_cnt <= 0; clk_1Hz <= not clk_1Hz; else div_1Hz_cnt <= div_1Hz_cnt + 1; end if; end if; end process; -- ======================================================================= -- 数码管扫描时钟分频(50MHz -> 1kHz) -- ======================================================================= scan_divider: process(clk_50MHz, reset) begin if reset = '1' then div_1kHz_cnt <= 0; clk_1kHz <= '0'; elsif rising_edge(clk_50MHz) then if div_1kHz_cnt = 49999 then -- 50MHz/(50k) = 1kHz div_1kHz_cnt <= 0; clk_1kHz <= not clk_1kHz; else div_1kHz_cnt <= div_1kHz_cnt + 1; end if; end if; end process; -- ======================================================================= -- 29进制计数器(0-28) -- ======================================================================= counter_process: process(clk_1Hz, reset) begin if reset = '1' then counter <= (others => '0'); carry_out <= '0'; elsif rising_edge(clk_1Hz) then if counter = MAX_COUNT then -- 达到29(0-28) counter <= (others => '0'); carry_out <= '1'; else counter <= counter + 1; carry_out <= '0'; end if; end if; end process; -- ======================================================================= -- 状态寄存器 -- ======================================================================= state_register: process(clk_1Hz, reset) begin if reset = '1' then current_state <= S_RED; elsif rising_edge(clk_1Hz) then current_state <= next_state; end if; end process; -- ======================================================================= -- 状态转移逻辑 -- ======================================================================= state_transition: process(current_state, carry_out, counter) begin case current_state is when S_RED => -- 红灯持续29秒后切换为绿灯 if carry_out = '1' and counter = MAX_COUNT then next_state <= S_GREEN; else next_state <= S_RED; end if; when S_GREEN => -- 绿灯持续24秒后切换为黄灯 if counter = to_unsigned(23, 8) then next_state <= S_YELLOW; else next_state <= S_GREEN; end if; when S_YELLOW => -- 黄灯持续5秒后切换为红灯 if counter = MAX_COUNT then next_state <= S_RED; else next_state <= S_YELLOW; end if; end case; end process; -- ======================================================================= -- 输出控制逻辑 -- ======================================================================= output_control: process(current_state) begin -- 默认关闭所有灯 red_led <= '0'; green_led <= '0'; yellow_led <= '0'; case current_state is when S_RED => red_led <= '1'; -- 红灯亮 when S_GREEN => green_led <= '1'; -- 绿灯亮 when S_YELLOW => yellow_led <= '1'; -- 黄灯亮 end case; end process; -- ======================================================================= -- 倒计时显示值计算 -- ======================================================================= display_value: process(current_state, counter) variable max_time : UNSIGNED(7 downto 0); variable remaining : UNSIGNED(7 downto 0); begin case current_state is when S_RED => max_time := MAX_COUNT + 1; -- 29秒 remaining := max_time - counter; when S_GREEN => max_time := to_unsigned(24, 8); -- 24秒 remaining := max_time - counter; when S_YELLOW => max_time := to_unsigned(5, 8); -- 5秒 remaining := to_unsigned(5, 8) - (MAX_COUNT - counter); end case; -- 转换为二进制 display_val <= STD_LOGIC_VECTOR(remaining); end process; -- ======================================================================= -- 显示值转换为BCD(用于数码管显示) -- ======================================================================= bin2bcd: process(display_val) variable value : integer range 0 to 29; variable tens : integer range 0 to 2; variable units : integer range 0 to 9; begin value := to_integer(unsigned(display_val)); tens := value / 10; units := value mod 10; bcd_tens <= STD_LOGIC_VECTOR(to_unsigned(tens, 4)); bcd_units <= STD_LOGIC_VECTOR(to_unsigned(units, 4)); end process; -- ======================================================================= -- 数码管扫描控制 -- ======================================================================= digit_scanner: process(clk_1kHz) begin if rising_edge(clk_1kHz) then -- 切换数码管显示(两位动态扫描) if digit_select = 1 then digit_select <= 0; else digit_select <= 1; end if; end if; end process; -- ======================================================================= -- 数码管段选输出 -- ======================================================================= seg7_display: process(digit_select, bcd_tens, bcd_units) begin case digit_select is when 0 => -- 显示个位 an <= "10"; -- 低位选通 case bcd_units is when "0000" => seg_data <= "1000000"; -- 0 when "0001" => seg_data <= "1111001"; -- 1 when "0010" => seg_data <= "0100100"; -- 2 when "0011" => seg_data <= "0110000"; -- 3 when "0100" => seg_data <= "0011001"; -- 4 when "0101" => seg_data <= "0010010"; -- 5 when "0110" => seg_data <= "0000010"; -- 6 when "0111" => seg_data <= "1111000"; -- 7 when "1000" => seg_data <= "0000000"; -- 8 when "1001" => seg_data <= "0010000"; -- 9 when others => seg_data <= "1111111"; -- 全灭 end case; when 1 => -- 显示十位 an <= "01"; -- 高位选通 case bcd_tens is when "0000" => seg_data <= "1000000"; -- 0 when "0001" => seg_data <= "1111001"; -- 1 when "0010" => seg_data <= "0100100"; -- 2 when others => seg_data <= "1000000"; -- 0 (3以上不可能) end case; end case; end process; end Behavioral;”以上代码报错,请帮我修改。
最新发布
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值