资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java小超市项目的代码 超市购物小程序java

需要一JAVA写成的超市管理系统!主要就是超市货品的添加,查询功能等!

/**

成都创新互联公司公司2013年成立,先为当阳等服务建站,当阳等地企业,进行企业商务咨询服务。为当阳企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

* 超市管理系统

* @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("--欢迎登录超市管理系统--");

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("提示:抱歉,模块正在开发中");

}

} 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:程序可能还有点问题,自己调试一下吧。改天有空我再来更新。

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) {

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("您消费共计:"+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("请输入商品的编号:");

int num = input.nextInt();

System.out.println("请输入商品的数量");

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; i  times; i++) {

System.out.print(" ");

}

System.out.print(row2);

for (int i = 0; i  10; i++) {

System.out.print(" ");

}

System.out.print(row3);

System.out.println("\n");

}

}

//测试结果:

-------超市计价系统-------

编号            商品          价格

1     可口可乐          3.0¥

2     爆米花          5.0¥

3     益达          10.0¥

请输入商品的编号:

3

请输入商品的数量

5

您消费共计:50.0¥

跪求一个小型超市管理系统,用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();

}

}


文章标题:java小超市项目的代码 超市购物小程序java
转载注明:http://cdkjz.cn/article/dophohc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220