Demo entry 6782166

1

   

Submitted by 22 on Jan 09, 2019 at 12:48
Language: Java. Code size: 6.5 kB.

package com.ys.m1d8.mapshopping;  
  
import java.io.FileInputStream;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import java.io.ObjectInputStream;  
import java.io.ObjectOutputStream;  
import java.util.Scanner;  
  
  
  
class Menu{  
    ShoppingUser su = new ShoppingUser();  
    User u = new User();  
    Goods g = new Goods();  
    Operator o = new Operator();  
    Scanner sc = new Scanner(System.in);  
    //开始  
    public void start() {  
          
        System.out.println("\t-商品列表-");  
        System.out.println("---------------------");  
        System.out.println("商品编号\t" + "商品名称\t" + "商品价格\t" );  
        FileOutputStream fout = null;  
        ObjectOutputStream objfout = null;  
          
        try {  
            fout = new FileOutputStream("f:/data/Goods.txt");  
            objfout = new ObjectOutputStream(fout);  
            for (Goods g:new Operator().getList()) {  
                objfout.writeObject(g);  
            }  
        } catch (FileNotFoundException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }finally {  
            try {  
                objfout.close();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        FileInputStream fin = null;  
        ObjectInputStream objfin = null;  
        try {  
            fin = new FileInputStream("f:/data/Goods.txt");  
            objfin = new ObjectInputStream(fin);  
            for(int i = 0;i < o.getList().size();i++) {  
                Goods good =(Goods)objfin.readObject() ;   
                System.out.println(good.getNo() + "\t" + good.getName() + "\t" + good.getPrice());  
            }  
              
        } catch (FileNotFoundException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        } catch (ClassNotFoundException e) {  
            e.printStackTrace();  
        }finally {  
            try {  
                objfin.close();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
          
        System.out.println("---------------------");  
        menu();  
    }  
    //登录  
    public void menuSign() {  
        System.out.println("*************************首页***********************");  
        System.out.println("   1.登录 2.注册 3.查询账号信息 4.注销 5.退出");  
        System.out.println("请选择:");  
        int no = sc.nextInt();  
        switch (no) {  
        case 1:  
            System.out.println("-----登录-----");  
            System.out.println("--账号:");  
            u.setAcount(sc.next());  
            System.out.println("--密码:");  
            u.setPassword(sc.next());  
            su.sign(u);  
            break;  
        case 2:  
            System.out.println("-----注册-----");  
            System.out.println("输入姓名:");  
            u.setName(sc.next());  
            System.out.println("输入账号:");  
            u.setAcount(sc.next());  
            System.out.println("输入密码:");  
            u.setPassword(sc.next());  
            su.register(u);  
            menuSign();  
            break;  
        case 3:  
            su.show();  
            menuSign();  
            break;  
        case 4:  
            System.out.println("----注销----");  
            System.out.println("--账号:");  
            u.setAcount(sc.next());  
            System.out.println("--密码:");  
            u.setPassword(sc.next());  
            su.cancellation(u);  
            break;  
        case 5:  
            System.out.println("成功退出!");  
            return;  
        default:  
            System.out.println("输入错误");  
            break;  
        }  
          
    }  
    //菜单  
    public void menu() {  
        ShoppingUser su = new ShoppingUser();  
        ShoppingUser.Administrators sadmin = su.new Administrators();    
        System.out.println("\t*菜单选择*");  
        System.out.println(" 1.添加 2.修改 3.删除 4.查询 5.退出");  
        System.out.println("*************************************");  
        System.out.println("--输入菜单编号:");  
        int n1 = sc.nextInt();  
        switch (n1) {  
        case 1:  
            System.out.println("请输入要购买的商品编号:");  
            int n = sc.nextInt();  
            g.setNo(n);  
            System.out.println("请输入购买数量:");  
            int count = sc.nextInt();   
            o.add(g, count);  
            //仓库数货物数量减少  
            /*for(int i = 0;i < o.getList().size();i++ ) { 
                if(o.getList().get(i).getNo()==n) { 
                    sadmin.getM2().replace(o.getList().get(i),sadmin.getM2().get(o.getList().get(i)) - count ); 
                    break; 
                }    
            }*/  
              
            menu();  
            break;  
        case 2:  
            System.out.println("请输入要修改商品的编号:");  
            int no = sc.nextInt();  
            System.out.println("请输入要修改的数量:");  
            int num = sc.nextInt();  
            o.change(no, num);  
            /*for(Goods good: o.getList()) { 
                if(good.getNo()==no) { 
                    //仓库货物数量修改 
                    sadmin.getM2().replace(good,sadmin.getM2().get(good) -(num - o.getM().get(good))); 
                    break; 
                }    
            }*/  
              
            menu();  
            break;  
        case 3:  
            System.out.println("请输入要删除商品的编号:");  
            int no1 = sc.nextInt();  
            o.delete(no1);  
            /*for(Goods good: o.getList()) { 
                if(good.getNo()==no1) { 
                    //仓库货物数量增加 
                    sadmin.getM2().replace(good,sadmin.getM2().get(good) - o.getM().get(good)); 
                    break; 
                }    
            }*/  
            menu();  
            break;  
        case 4:  
            o.show();  
            menu();  
            break;  
        case 5:  
            return;  
        default:  
            System.out.println("选择错误,重新选择~");  
            menu();  
            break;  
        }  
    }  
}  
public class TestMenu {  
    public static void main(String[] args) {  
        new Menu().menuSign();;   
    }  
}  

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).