本文实例为大家分享了Java实现购物管理系统的具体代码,供大家参考,具体内容如下
重点内容
JAVA分支结构练习
动态数组
注册表读写删
代码:
package Endless;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
public class persion {
static int s;
static boolean huiyuan,xhuiyuan;
static String bke="百事可乐",ke="500ml可乐一瓶",m="5公斤面粉",ss="1个苏泊尔炒菜锅",o="欧莱雅爽肤水一瓶";
static ArrayListarray=new ArrayList();
static Preferences goodsnodes = Preferences.systemRoot().node("goods"); //创建节点
static Preferences goodschildnode = goodsnodes.node( "goods"); //创建子节点
public static void main(String []args) {
outline();
System.out.println("t欢迎使用购物管理系统");
System.out.println("t1.登陆系统nt2.退出程序n ");
outline();
int n =scanint();
if(n == 1){
login();
}else if( n== 2){
System.out.println("已退出");
System.exit(0);
}else {
System.out.println("请重新选择:");
main(null);
}
}
public static void outline(){
System.out.println("* * * * * * * * * * * * * * * * * * * * * * *n");
}
public static int scanint(){
int x = 0;
try {
Scanner scan =new Scanner(System.in);
x = scan.nextInt();
} catch (Exception e) {
System.out.println("输入有误,请输入数字:");
}
return x;
}
public static String scanStr(){
String x = null;
try {
Scanner scan =new Scanner(System.in);
x = scan.next();
} catch (Exception e) {
System.out.println("输入有误,请输入字符串:");
}
return x;
}
public static void login(){
System.out.println(" * * * * * * * * * 登陆 * * * * * * * * * * * *n请输入密码n:");
int n1 =scanint();
if(n1==(123123)){
System.out.println("登陆成功n");
showMain();
}else{
System.out.println("密码错误");
System.out.println("请重新输入密码n:");
login();
}
}
private static void showMain() {
System.out.println("nnt欢迎使用购物管理系统n");
outline();
System.out.println("tt 1. 会 员 信 息 管 理n");
System.out.println("tt 2. 货 物 信 息 管 理n");
System.out.println("tt 3. 购 物 结 算n");
System.out.println("tt 4. 注 销n");
outline();
System.out.print("请选择,输入数字:");
int n2 =scanint();
switch (n2) {
case 1:
new user();
break;
case 2:
goods();
break;
case 3:
jiesuan();
break;
case 4:
System.out.println("注销成功");
main(null);
default:
System.out.println("没有您要的选项请重新输入");
showMain();
break;
}
}
private static void goods() {
//商品管理 :添加商品: 编号 品名 价格
// 删除:选择标号删除
outline();
System.out.println("tt商品信息管理n");
System.out.println("tt1,显示商品n");
System.out.println("tt2,添加物品n");
System.out.println("tt3,删除商品n");
System.out.println("tt4,返回上级n");
outline();
int n = scanint();
if (n==1){
showgoods();
}else if(n==2){
addgoods();
}else if(n ==3){
delgoods();
}else if(n==4) {
showMain();
}else {
goods();
}
}
private static void delgoods() {
System.out.println("请选择要删除商品的ID:n按0返回上级");
try {
Scanner scan =new Scanner(System.in);
int x = scan.nextInt();
boolean remove=false;
for (int i=0;i=52){
out(bke,s+2);
}else{
Err();
}
case 2:
if(s>=103){
out(ke,s+3);
}else{
Err();
}
break;
case 3:
if(s>=110){
out(m,s+10);
}else{
Err();
}
break;
case 4:
if(s>=210){
out(ss,s+10);
}else{
Err();
}
break;
case 5:
if(s>=220){
out(o,s+20);
}else{
Err();
}
break;
default:
System.out.println("请重新选择");
os();
}
}
static void Err(){
System.out.println("金额不足n");
main(null);
}
static class user{
static ArrayListarray=new ArrayList<>();
static Preferences nodes = Preferences.systemRoot().node("user"); //创建节点
static Preferences childnode = nodes.node( "user"); //创建子节点
public user() {
outline();
System.out.println("tt1,添加用户");
System.out.println("tt2,删除用户");
System.out.println("tt3,显示用户");
System.out.println("tt4,返回上级");
outline();
try {
int x=scanint();
switch (x) {
case 1:
add();
break;
case 2:
deluser();
break;
case 3:
show();
break;
case 4:
showMain();
break;
default:
System.out.println("没有您要的选项!请重新选择");
new user();
break;
}
} catch (Exception e) {
new user();
}
}
private void deluser() throws BackingStoreException {
System.out.println("请选择要删除用户的ID:n按0返回上级");
try {
Scanner scan =new Scanner(System.in);
int x = scan.nextInt();
boolean remove=false;
for (int i=0;i
更多学习资料请关注专题《管理系统开发》。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



