超市收银台
public class SupermarketCashier {
static Scanner scanner = new Scanner ( System. in ) ;
static int index = 0 ;
static Map< String, String> map = new HashMap < > ( ) ;
static ArrayList< Object[ ] > arrayList = new ArrayList < > ( ) ;
static Date d = new Date ( ) ;
static SimpleDateFormat sdf = new SimpleDateFormat ( "yyyyMMddHHmmss" ) ;
static String string = "" ;
static int shifu = 0 ;
public static void program ( ) {
System. out. println ( "--------欢迎使用蓝鸥超市收银系统--------" ) ;
System. out. println ( "1.设置门店信息" ) ;
System. out. println ( "2.顾客结账" ) ;
System. out. println ( "3.退出系统" ) ;
System. out. print ( "请按序号选择要使用的功能:" ) ;
}
public static void store ( ) {
System. out. println ( "请输入门店名称:" ) ;
String name = scanner. nextLine ( ) ;
System. out. println ( "请输入门店联系电话:" ) ;
String telephone = scanner. nextLine ( ) ;
map. put ( name, telephone) ;
System. out. println ( "门店名称:" + name) ;
System. out. println ( "门店电话:" + telephone) ;
System. out. println ( "门店信息设置成功!!!" ) ;
program ( ) ;
}
public static void function ( ) {
System. out. println ( "1.添加商品 2.付款方式 3.生成小票 4.收款金额 5.回到主菜单" ) ;
System. out. println ( "请按功能菜单选择序号:" ) ;
}
public static void closing ( ) {
boolean b = true ;
while ( b) {
function ( ) ;
int sc = scanner. nextInt ( ) ;
switch ( sc) {
case 1 :
Tenaga ( ) ;
break ;
case 2 :
paymentMain ( ) ;
break ;
case 4 :
shiFu ( ) ;
break ;
case 3 :
smallticket ( ) ;
break ;
case 5 :
program ( ) ;
return ;
}
}
}
public static void shiFu ( ) {
System. out. println ( "请输入客户付款金额:" ) ;
shifu = scanner. nextInt ( ) ;
}
public static void Tenaga ( ) {
System. out. println ( "请输入商品名称:" ) ;
String name = scanner. next ( ) ;
System. out. println ( "请输入商品单价:" ) ;
double price = scanner. nextDouble ( ) ;
System. out. println ( "请输入购买数量:" ) ;
int num = scanner. nextInt ( ) ;
double zongjia = price * num;
Object[ ] objects = new Object [ 4 ] ;
objects[ 0 ] = name;
objects[ 1 ] = price;
objects[ 2 ] = num;
objects[ 3 ] = zongjia;
arrayList. add ( objects) ;
}
public static void paymentMain ( ) {
System. out. println ( "请选择付款方式;1.(支付宝) 2.(微信) 3.(现金)" ) ;
int mode = scanner. nextInt ( ) ;
if ( mode == 1 ) {
string = "支付宝" ;
} else if ( mode == 2 ) {
string = "微信" ;
} else if ( mode == 3 ) {
string = "现金" ;
}
}
public static void smallticket ( ) {
SimpleDateFormat sdf1 = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
System. out. println ( map. keySet ( ) ) ;
System. out. println ( "订单编号(OUT TRADE NO):" ) ;
System. out. println ( sdf. format ( d) ) ;
System. out. println ( "************************" ) ;
System. out. println ( "欢迎光临 TEL:" + map. values ( ) ) ;
System. out. println ( "品名 售价 数量 金额" ) ;
System. out. println ( "-------------------------" ) ;
double money = 0.0 ;
for ( Object[ ] goods : arrayList) {
money += ( double) goods[ 3 ] ;
for ( Object good : goods) {
System. out. print ( good. toString ( ) + " " ) ;
}
System. out. println ( ) ;
}
System. out. println ( "共计" + arrayList. size ( ) + "项商品" ) ;
System. out. println ( "购物总金额:" + money) ;
System. out. println ( string + "实付:" + shifu) ;
double zhaoling = shifu - money;
System. out. println ( "找零:" + zhaoling) ;
System. out. println ( "付款时间:" + sdf1. format ( d) ) ;
System. out. println ( "蓝鸥收款机:" + map. values ( ) ) ;
}
public static void signOut ( ) {
System. out. println ( "系统已成功退出!!!" ) ;
}
}
public class SupermarketCashierMain {
public static void main ( String[ ] args) {
cash ( ) ;
}
public static void cash ( ) {
boolean a = true ;
SupermarketCashier scCashier = new SupermarketCashier ( ) ;
scCashier. program ( ) ;
Scanner scanner = new Scanner ( System. in ) ;
while ( a) {
int select = scanner. nextInt ( ) ;
if ( select >= 1 && select <= 3 ) {
switch ( select) {
case 1 :
scCashier. store ( ) ;
break ;
case 2 :
scCashier. closing ( ) ;
break ;
case 3 :
scCashier. signOut ( ) ;
return ;
}
}
}
}
}