import java.sql.Connection;
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名申請、虛擬主機、營銷軟件、網(wǎng)站建設(shè)、偃師網(wǎng)站維護、網(wǎng)站推廣。
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";
//獲得數(shù)據(jù)庫連接
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;
}
//關(guān)閉Resultset
public static void closeResultSet(ResultSet rs)
{
try
{
if(rs != null)
{
rs.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//關(guān)閉Statement
public static void closeStatement(Statement st)
{
try
{
if(st != null)
{
st.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//關(guān)閉Connection
public static void closeConnection(Connection conn)
{
try
{
if(conn != null)
{
conn.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//測試數(shù)據(jù)庫連接是否成功
public static void main(String[] args) {
Conn.getConnection();
}
}
import java.util.Vector; class Supermarket{ Vector market = null; Supermarket(){ market = new Vector(); } public void append(Goods g){ market.addElement(g); } public void delete(Goods g){ market.removeElement(g); } public void query(Goods g){ for(int i = 0;imarket.size();i++){ if((market.elementAt(i)).equals(g) == true){ g.showMe(); } } } } class Goods{ private String name; private double price; private int num; public Goods(String name,double price,int num){ this.name=name; this.price = price; this.num = num; } public void sale(double buyprice){ if(num==0){ System.out.println("購買商品已售空"); return; } if(buypricethis.price){ System.out.println("余額不足"); }else{ num--; } } public void add(int quantity){ num+=quantity; } public void showMe(){ System.out.println("商品名稱:"+this.name+" 商品價格:"+this.price+"$ "+"商品個數(shù):"+this.num); } } //很多地方給的不是很詳細,只能這么憑理解寫,測試main方法自己寫。
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("輸入錯誤,請重新輸入!");
break;
}
}
scan.close();
}
/**
?*?顯示信息
?*/
public?static?void?showMsg()?{
System.out.println("===================================");
System.out.println("\t超??市??庫??存??管??理??系??統(tǒng)\t");
System.out.println("===================================");
System.out.println("1、商品管理");
System.out.println("2、客戶管理");
System.out.println("3、訂單管理");
System.out.println("4、退出系統(tǒng)");
System.out.println("===================================");
System.out.println("請輸入您的選擇(1-4):");
}
/**
?*?選項?1、商品管理
?*/
public?static?void?commodityManage()?{
str?=?"商品管理";
showWelcom(str);
System.out.println("以上為商品管理的信息!\n是否繼續(xù)?(按1繼續(xù)/其他結(jié)束):");
exitOrShow(1);
}
/**
?*?選項?2、客戶管理
?*/
public?static?void?customerManage()?{
str?=?"客戶管理";
System.out.println("以上為客戶管理的信息!\n是否繼續(xù)?(按2繼續(xù)/其他結(jié)束):");
exitOrShow(2);
}
/**
?*?選項?3、訂單管理
?*/
public?static?void?orderManage()?{
str?=?"訂單管理";
System.out.println("以上為訂單管理的信息!\n是否繼續(xù)?(按3繼續(xù)/其他結(jié)束):");
exitOrShow(3);
}
/**
?*?選項?4、退出系統(tǒng)
?*/
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();
}
}
}
算是最簡單的吧
package cn.job01;
import java.util.Scanner;
public class Lx07 {
public static void choice() {
System.out.println("登陸菜單 ");
System.out.println("1登陸系統(tǒng)");
System.out.println("2退出");
}
static void choice1() {
System.out.println("購物管理系統(tǒng)客戶信息");
System.out.println("1顯示所有客戶信息");
System.out.println("2添加客戶信息");
System.out.println("3修改客戶信息");
System.out.println("4查詢客戶信息");
}
static void choice2() {
System.out.println("購物管理系統(tǒng)真情回饋");
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購物結(jié)算");
System.out.println("3真情回饋");
System.out.println("4注銷");
break;
}
System.out.println("選擇輸入數(shù)字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("購物結(jié)算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
要使用Java編寫超市購物程序,您需要使用Java數(shù)據(jù)庫編程技術(shù)來連接到您的數(shù)據(jù)庫并執(zhí)行相關(guān)的數(shù)據(jù)庫操作。在Java中,您可以使用JDBC(Java數(shù)據(jù)庫連接)API來連接到數(shù)據(jù)庫并執(zhí)行SQL語句。例如,您可以使用JDBC API來執(zhí)行以下操作:
創(chuàng)建數(shù)據(jù)庫連接
執(zhí)行增刪改查(CRUD)操作
提交或回滾事務(wù)
執(zhí)行存儲過程和函數(shù)
查詢數(shù)據(jù)庫元數(shù)據(jù)
此外,您還可以使用Java的面向?qū)ο缶幊碳夹g(shù)來封裝數(shù)據(jù)庫操作,以便更方便地在您的程序中使用。例如,您可以創(chuàng)建一個類來表示超市商品,并定義一些方法來執(zhí)行商品的增刪改查操作。這樣,您就可以在程序中通過調(diào)用這些方法來簡單地完成對數(shù)據(jù)庫的操作,而不需要編寫復(fù)雜的SQL語句。
/**
*?超市管理系統(tǒng)
*?@author?Administrator
*
*/
public?class?ChaoShiSystemManager?{
public?static?void?main(String[]?args)?{
new?HuoWuDomImpl().start();
}
}
class?HuoWu{
public?String?bianhao;?//商品編號
public?String?name;?//商品名稱
public?double?jiage;?//商品價格
}
class?HuoWuDomImpl{
private?static?java.util.ArrayListHuoWu?list?=?new?java.util.ArrayListHuoWu();
public?void?start(){
?int?num?=?0;
System.out.println("--歡迎登錄超市管理系統(tǒng)--");
System.out.println("1、添加商品");
System.out.println("2、查詢商品");
java.util.Scanner?sc?=?new?java.util.Scanner(System.in);
System.out.println("請輸入模塊名稱:");
try?{
num?=?sc.nextInt();
if(num?==?1){
setHuoWu();
new?HuoWuDomImpl().start();
}else?if(num?==?2){
getSeleteHuoWu();
new?HuoWuDomImpl().start();
}else{
throw?new?RuntimeException("提示:抱歉,模塊正在開發(fā)中");
}
}?catch?(Exception?e)?{
e.printStackTrace();
throw?new?RuntimeException("提示:對不起,您的輸入有誤!");
}finally{
sc.close();
}
}
public?void?setHuoWu(){
HuoWu?hw?=?new?HuoWu();
java.util.Scanner?sc?=?new?java.util.Scanner(System.in);
System.out.println("請輸入商品編號:");
hw.bianhao?=?sc.next();
System.out.println("請輸入商品名稱:");
hw.name?=?sc.next();
System.out.println("請輸入商品價格");
try?{
hw.jiage?=?sc.nextDouble();
}?catch?(Exception?e)?{
throw?new?RuntimeException("提示:商品價格輸入錯誤!");
}finally{
sc.close();
}
list.add(hw);
System.out.println("提示:恭喜,添加成功!");
}
public?void?getSeleteHuoWu(){
java.util.Scanner?sc?=?new?java.util.Scanner(System.in);
System.out.println("請輸入商品編號...");
String?bianhao?=?sc.next();
java.util.Iterator?it?=?list.iterator();
while(it.hasNext()){
if(bianhao.equals(((HuoWu)it.next()).bianhao)){
System.out.println("商品編號:"?+?((HuoWu)it.next()).bianhao);
System.out.println("商品名稱:"?+?((HuoWu)it.next()).name);
System.out.println("商品價格:"?+?((HuoWu)it.next()).jiage);
}
}
}
}
PS:程序可能還有點問題,自己調(diào)試一下吧。改天有空我再來更新。
網(wǎng)站題目:包含java超市系統(tǒng)代碼的詞條
分享網(wǎng)址:http://chinadenli.net/article20/hechjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計、網(wǎng)站策劃、搜索引擎優(yōu)化、企業(yè)建站、品牌網(wǎng)站建設(shè)、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)