用java编程实现网上超市购物结算功能代码哎,我还是自己代码黏贴给你吧!免得总通不过!装不下这么多字,详情自己找我 。连接数据库类(添加修改会员信息) package com.to.java; import java.util.Scanner; import java.sql.*; public class Vds { Scanner Input=new Scanner(System.in); ZhuCK1 zhuck1=new ZhuCK1(); public void x(){ try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt); System.out.println("----------查询结果---------"); System.out.println(); System.out.println("会员号--密码"); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id " " mm);} con.close(); stmt.close();}catch(Exception e){ System.out.println(e);} System.out.println("是否返回上级菜单"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("欢迎下次再次使用");System.exit(-1);}; break;}} public void j(){try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt);while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id " " mm);}Scanner input=new Scanner(System.in); System.out.println("请输入会员信息:"); System.out.println("请输入会员号:"); String f=input.next(); System.out.println("请输入密码:");String q=input.next(); String sqlst="insert into gg values('" f "','" q "')"; Statement tatement=con.createStatement();int result=tatement.executeUpdate(sqlst); System.out.println("操作成功!"); con.close(); stmt.close(); }catch(Exception e){ System.out.println(e);} System.out.println("是否返回上级菜单"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("欢迎下次再次使用");System.exit(-1);}; break;} } public void xg(){try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt);while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id " " mm);}Scanner input=new Scanner(System.in); System.out.println("请输入会员信息:"); System.out.println("请输入要修改的会员号:"); String f=input.next(); System.out.println("请输入修改的密码:");String q=input.next(); String sqlst="update gg set mm='" q "' where id='" f "'"; Statement tatement=con.createStatement();int result=tatement.executeUpdate(sqlst); System.out.println("操作成功!"); con.close(); stmt.close(); }catch(Exception e){ System.out.println(e);} System.out.println("是否返回上级菜单"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("欢迎下次再次使用");System.exit(-1);}; break;} } }package com.to.java; import java.util.Scanner; public class KeHu { Vds sj=new Vds(); public void kehu1(){Scanner Input=new Scanner(System.in); ZhuCK1 zhuck1=new ZhuCK1();System.out.println("******************************************************" "\n\n"); System.out.println("1.显示所有客户信息"); System.out.println("2.添加客户信息"); System.out.println("3.修改客户信息"); System.out.println("4.查询客户信息"); System.out.println("5.返回上级菜单"); System.out.println("******************************************************" "\n\n"); System.out.println("请输入数字:"); int a=Input.nextInt(); switch(a){ case 1: sj.x(); break; case 2: sj.j(); break; case 3: sj.xg(); break; case 4: sj.x();break; case 5: zhuck1.ZhucK1();break; } } }package com.to.java; public class GouWuXiTong { public static void main(String[] args){ ZhuCK zhuck=new ZhuCK();zhuck.ZhucK();} }package com.to.java; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Scanner; public class ZhuCK { Scanner Input=new Scanner(System.in); public void ZhucK(){ ZhuCK1 zhuck1=new ZhuCK1(); System.out.println("\t\t" "欢迎使用我心我素购物系统"); System.out.println("******************************************************" "\n\n"); System.out.println("\t\t" "1.登陆系统"); System.out.println(); System.out.println("\t\t" "2.退出" "\n\n"); System.out.println("******************************************************"); int d=1; while(d!=2){ System.out.println("请输入会员号:"); String p=Input.next(); System.out.println("请输入密码:"); String f=Input.next(); try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select * from gg"; rs=stmt.executeQuery(sqlstmt); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm");if(id.equals(p)mm.equals(f)){ { System.out.println("请输入数字:");int a=Input.nextInt(); switch(a){ case 1: zhuck1.ZhucK1(); break; case 2: break;}d=2; }}} }catch(Exception e){ System.out.println(e);} {System.out.println("输入错误请再次输入:");d=1;}} }}}
java超市计价系统代码package entity;
public class Market {
private int id;//id
private int num;//数量
private String goods;//商品
private double price;//价格
public Market(int id, int num, String goods, double price) {
【超市购物系统java代码的简单介绍】super();
this.id = id;
this.num = num;
this.goods = goods;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getGoods() {
return goods;
}
public void setGoods(String goods) {
this.goods = goods;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double calc( ){
double sum=price*num;
System.out.println("您消费共计超市购物系统java代码:" sum "¥");
return sum;
}
}
package test;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import entity.Market;
public class Test {
private static MapInteger,Market goods=new HashMapInteger, Market();
public static void main(String[] args) {
System.out.println("-------超市计价系统-------");
String goods1="可口可乐";
String goods2="爆米花";
String goods3="益达";
printTable("编号","商品","价格");
printTable("1",goods1,"3.0¥");
printTable("2",goods2,"5.0¥");
printTable("3",goods3,"10.0¥");
goods.put(1, new Market(1, 1, goods1, 3.0));
goods.put(2, new Market(2, 1,goods2, 5.0));
goods.put(3, new Market(3, 1, goods3, 10.0));
Scanner input = new Scanner(System.in);
System.out.println("请输入商品超市购物系统java代码的编号:");
int num = input.nextInt();
System.out.println("请输入商品超市购物系统java代码的数量");
int amount = input.nextInt();
Market market = goods.get(num);
market.setNum(amount);
market.calc();
}
private static void printTable(String row1,String row2,String row3 ) {
System.out.print(row1);
int times=12;
if (row2!="商品") {
times=5;
}
for (int i = 0; itimes; i) {
System.out.print(" ");
}
System.out.print(row2);
for (int i = 0; i10; i) {
System.out.print(" ");
}
System.out.print(row3);
System.out.println("\n");
}
}
//测试结果超市购物系统java代码:
-------超市计价系统-------
编号商品价格
1可口可乐3.0¥
2爆米花5.0¥
3益达10.0¥
请输入商品的编号:
3
请输入商品的数量
5
您消费共计:50.0¥
数据库如何用java写超市购物程序?要使用Java编写超市购物程序,您需要使用Java数据库编程技术来连接到您的数据库并执行相关的数据库操作 。在Java中,您可以使用JDBC(Java数据库连接)API来连接到数据库并执行SQL语句 。例如 , 您可以使用JDBC API来执行以下操作:
创建数据库连接
执行增删改查(CRUD)操作
提交或回滚事务
执行存储过程和函数
查询数据库元数据
此外,您还可以使用Java的面向对象编程技术来封装数据库操作,以便更方便地在您的程序中使用 。例如,您可以创建一个类来表示超市商品,并定义一些方法来执行商品的增删改查操作 。这样,您就可以在程序中通过调用这些方法来简单地完成对数据库的操作 , 而不需要编写复杂的SQL语句 。
用java编写实现简单购物系统package cn.job01;
import java.util.Scanner;
public class Lx07 {
public static void choice() {
System.out.println("登陆菜单");
System.out.println("1登陆系统");
System.out.println("2退出");
}
static void choice1() {
System.out.println("购物管理系统客户信息");
System.out.println("1显示所有客户信息");
System.out.println("2添加客户信息");
System.out.println("3修改客户信息");
System.out.println("4查询客户信息");
}
static void choice2() {
System.out.println("购物管理系统真情回馈");
System.out.println("1幸运大放送");
System.out.println("2幸运抽奖");
System.out.println("3生日问候");
}
public static void main(String[] args) {
choice();
Scanner input = new Scanner(System.in);
System.out.println("请输入1or2");
int num = input.nextInt();
switch (num) {
case 1:
System.out.println("主菜单");
System.out.println("1客户信息管理");
System.out.println("2购物结算");
System.out.println("3真情回馈");
System.out.println("4注销");
break;
}
System.out.println("选择输入数字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("购物结算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
去修改下
超市购物系统java代码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于、超市购物系统java代码的信息别忘了在本站进行查找喔 。
推荐阅读
- 微信不怎么显示视频号了,微信怎么不显示手机号
- excel2010如何排序,excel2010怎么排序数据
- 科技主题文章阅读公众号,科技类公众号文章
- mysql突然闪退怎么办 mysql出现闪退怎么办
- linux黑客终端命令,linux黑客命令大全
- linux可以回退命令吗,linux怎么退回
- 做饭经营小游戏安卓版,做饭类的模拟经营游戏
- mysql怎么显示表内容 mysql 显示
- P40PRO升级鸿蒙后卡,p40pro升级鸿蒙卡顿