
正文
java购物管理系统代码 java在线购物系统
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
有谁有用JAVA编写的小型超市管理系统的源代码啊 数据库用mysql 急啊
作业吧?找个类似的图书馆一类的东西改一下数据库不就行了?
相关问答
Q1: 购物车的Java代码
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;public class ShoppingCartManager {
HashMapString, String hm=new HashMapString, String();
float totlePrice=0;
//添加book到购物车
public void addBook(String bookId,String bookQuantity){
if(hm.containsKey(bookId)){
int value=Integer.parseInt(hm.get(bookId));
value+=Integer.parseInt(bookQuantity);
hm.put(bookId, value+"");
}else{
hm.put(bookId, bookQuantity);
}
}
//修改数量
public void updateQuantity(String bookId,String bookQuantity){
hm.put(bookId, bookQuantity);
}
//获取购物车的所有信息 并计算总价
public ArrayListBookBean getShoppingCart(){
ArrayListBookBean al=new ArrayListBookBean();
IteratorString i=hm.keySet().iterator();
String ids="";
BookTableManager btm=new BookTableManager();
while(i.hasNext()){
ids=ids+","+i.next();
}
al= btm.selectByBookIds(ids);
totlePrice=0; //清空总价,防止无限累计
for(int j=0;jal.size();j++){
BookBean bb=al.get(j);
totlePrice+=bb.getPrice()*Integer.parseInt(getQuantityById(bb.getBookId()+""));
}
return al;
}
//获取总价
public float getTotlePrice(){
return totlePrice;
}
//根据ID获取数量
public String getQuantityById(String id){
String quantity=hm.get(id);
return quantity;
}
//清空购物车
public void clear(){
hm.clear();
}
//删除购物车中的一本书
public void deleteById(String id){
hm.remove(id);
}
}
Q2: 跪求一个小型超市管理系统,用java编写的,急~ 只要源代码。。可以发我邮箱
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conn {
private static final String driver="com.mysql.jdbc.Driver";
private static final String url="jdbc:mysql://localhost:3306/blog?user=rootpassword=root";
//获得数据库连接
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
if(conn != null){
System.out.print("成功");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
//关闭Resultset
public static void closeResultSet(ResultSet rs)
{
try
{
if(rs != null)
{
rs.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//关闭Statement
public static void closeStatement(Statement st)
{
try
{
if(st != null)
{
st.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//关闭Connection
public static void closeConnection(Connection conn)
{
try
{
if(conn != null)
{
conn.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//测试数据库连接是否成功
public static void main(String[] args) {
Conn.getConnection();
}
}
Q3: 用java语言写个超市管理系统的程序
package c;
import java.util.Scanner;
public class SuperMarket {
static Scanner scan = new Scanner(System.in);
public static String str;
public static void main(String[] args) {
showMsg();
while (scan.hasNext()) {
switch (scan.nextInt()) {
case 1:
commodityManage();
break;
case 2:
customerManage();
break;
case 3:
orderManage();
break;
case 4:
exitSystem();
break;
default:
System.out.println("输入错误java购物管理系统代码,请重新输入java购物管理系统代码!");
break;
}
}
scan.close();
}
/**
* 显示信息
*/
public static void showMsg() {
System.out.println("===================================");
System.out.println("\t超 市 库 存 管 理 系 统\t");
System.out.println("===================================");
System.out.println("1、商品管理");
System.out.println("2、客户管理");
System.out.println("3、订单管理");
System.out.println("4、退出系统");
System.out.println("===================================");
System.out.println("请输入您的选择(1-4):");
}
/**
* 选项 1、商品管理
*/
public static void commodityManage() {
str = "商品管理";
showWelcom(str);
System.out.println("以上为商品管理的信息!\n是否继续?(按1继续/其他结束):");
exitOrShow(1);
}
/**
* 选项 2、客户管理
*/
public static void customerManage() {
str = "客户管理";
System.out.println("以上为客户管理的信息!\n是否继续?(按2继续/其他结束):");
exitOrShow(2);
}
/**
* 选项 3、订单管理
*/
public static void orderManage() {
str = "订单管理";
System.out.println("以上为订单管理的信息!\n是否继续?(按3继续/其他结束):");
exitOrShow(3);
}
/**
* 选项 4、退出系统
*/
public static void exitSystem() {
System.exit(0);
}
public static void showWelcom(String str) {
System.out.println("欢迎进入"+ str +"模块");
System.out.println("===================================");
}
public static void exitOrShow(int nextInt) {
if (scan.nextInt() != nextInt) {
exitSystem();
} else {
showMsg();
}
}
}
Q4: 用JAVA编程的通过SQL连接数据库的商品库存管理系统的源代码
package com.company.dao;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class BaseDao {
// 数据库驱动
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//url
String url = "jdbc:sqlserver://数据库ip:端口号;databaseName=数据库名;";
//用户名
String uname = "数据库用户名";
//密码
String pwd = "数据库密码";
/**
* 获得连接对象
* @return
*/
protected Connection getCon(){
//返回的连接
Connection con = null;
try {
//载入驱动
Class.forName(driver);
//得到连接
con = DriverManager.getConnection(url, uname, pwd);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
/**
* 关闭数据库
* @param con
* @param stmt
* @param rs
*/
protected void closeDB(Connection con, Statement stmt, ResultSet rs){
if(rs != null){
try {
//关闭结果集
rs.close();
rs = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(stmt != null){
try {
//关闭语句对象
stmt.close();
stmt = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(con != null){
try {
//关闭连接对象
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
protected void closeDB(Connection con, PreparedStatement pstmt, ResultSet rs){
if(rs != null){
//关闭结果集
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(pstmt != null){
try {
pstmt.close();
pstmt = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(con != null){
try {
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
这个是java购物管理系统代码我写的一个基本的连接sql2005数据库的代码,.! 不知道java购物管理系统代码你能不能用,! 你看一下吧, 连接的时候需要sqljdbc.jar数据库驱动,!
Q5: 如何编写Myshopping管理系统java程序代码
import java.util.Scanner;
public class AddCustomer{
public static void main(String[] args){
System.out.printIn("MyShopping管理系统 客户信息管理 添加客户信息\n");
int custNo; //会员号
int birthday; //会员生日
int points = 0; //会员积分
Scanner input=new Scanner(System.in);
for(int i=0;i3;i++){ //循环录入会员信息
System.out.printIn("请输入会员号(4位整数):");
custNo = input.nextInt();
System.out.printIn("请输入会员生日(月\日用两位整数表示):");
custNo = input.next();
System.out.printIn("请输入会员积分:");
custNo = input.nextInt();
if(custNo1000||custNo9999){ //会员号无效则跳出
System.out.printIn("客户号"+custNo+"是无效会员号!");
System.out.printIn("录入信息失败\n");
contiune;
}
System.out.printIn("您录入的会员信息是:");
System.out.printIn(custNo+" "+birthday+" "+points+ "\n");
}
System.out.printIn("程序结束!");
}
}
java购物管理系统代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java在线购物系统、java购物管理系统代码的信息别忘了在本站进行查找喔。







