资讯

精准传达 • 有效沟通

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

java购物订单模块代码 java订单与支付模块

用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代码

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

}

}

怎样用Java swing 来做一个点餐系统里面的订单模块,只需要窗体,不需要其他效果。菜鸟求代码

绑定一个事件到被点击的窗体或控件,点击后获取控件信息,然后传参给一个自定义的窗体类的构造函数,如A = new oneDialog(参数1,参数2....);然后A.setVisible(true)。大概就是这个样子,有不懂得可以继续问

JAVA 购物车示例代码

import java.awt.*;

import java.awt.event.*;

class ShopFrame extends Frame implements ActionListener

{ Label label1,label2,label3,label4;

Button button1,button2,button3,button4,button5;

TextArea text;

Panel panel1,panel2;

static float sum=0.0f;

ShopFrame(String s)

{ super(s);

setLayout(new BorderLayout());

label1=new Label("面纸:3元",Label.LEFT);

label2=new Label("钢笔:5元",Label.LEFT);

label3=new Label("书:10元",Label.LEFT);

label4=new Label("袜子:8元",Label.LEFT);

button1=new Button("加入购物车");

button2=new Button("加入购物车");

button3=new Button("加入购物车");

button4=new Button("加入购物车");

button5=new Button("查看购物车");

text=new TextArea("商品有:"+"\n",5,10);

text.setEditable(false);

addWindowListener(new WindowAdapter()

{ public void windowClosing(WindowEvent e)

{ System.exit(0);

}

}

);

button1.addActionListener(this);

button2.addActionListener(this);

button3.addActionListener(this);

button4.addActionListener(this);

button5.addActionListener(this);

panel1=new Panel();

panel2=new Panel();

panel1.add(label1);

panel1.add(button1);

panel1.add(label2);

panel1.add(button2);

panel1.add(label3);

panel1.add(button3);

panel1.add(label4);

panel1.add(button4);

panel2.setLayout(new BorderLayout());

panel2.add(button5,BorderLayout.NORTH);

panel2.add(text,BorderLayout.SOUTH);

this.add(panel1,BorderLayout.CENTER);

this.add(panel2,BorderLayout.SOUTH);

setBounds(100,100,350,250);

setVisible(true);

validate();

}

public void actionPerformed(ActionEvent e)

{ if(e.getSource()==button1)

{ text.append("一个面纸、");

sum=sum+3;

}

else if(e.getSource()==button2)

{ text.append("一只钢笔、");

sum=sum+5;

}

else if(e.getSource()==button3)

{ text.append("一本书、");

sum=sum+10;

}

else if(e.getSource()==button4)

{ text.append("一双袜子、");

sum=sum+8;

}

else if(e.getSource()==button5)

{

text.append("\n"+"总价为:"+"\n"+sum);

}

}

}

public class Shopping {

public static void main(String[] args) {

new ShopFrame("购物车");

}

}

我没用Swing可能显示不出来你的效果。不满意得话我在给你编一个。


网站名称:java购物订单模块代码 java订单与支付模块
文章URL:http://cdkjz.cn/article/dddpogi.html
多年建站经验

多一份参考,总有益处

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

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

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220