㈠ 急,寫一個購物車的代碼
我好像有一個類似的,購物車,回去給你找找,報個QQ,
㈡ 求JSP大神幫小弟看看這個簡易購物車應用代碼應該怎麼寫。
session.setAttribute(「attribute」,value);
session.getAttribute();
這不就是?
㈢ java簡單的購物車代碼
packageTest;
importjava.util.LinkedHashMap;
importjava.util.Map;
importjava.util.Map.Entry;
importjava.util.Scanner;
publicclassTest{
publicstaticvoidmain(String[]args){
init();//初始化
Map<String,String>map=newLinkedHashMap<>();
while(true){
Scannerin=newScanner(System.in);
map=buy(in,map);//選擇
System.out.println();
System.out.println("還要繼續購物嗎?(Y/N)");
Stringjx=in.nextLine();
if(jx.equals("N")){
break;
}
}
print(map);
}
publicstaticvoidprint(Map<String,String>m){
System.out.println("
******************");
System.out.println("購物車清單");
Integerhj=0;
for(Entry<String,String>entry:m.entrySet()){
Stringkey=entry.getKey();
Stringvalue=entry.getValue();
if(key.equals("1")){
hj+=Integer.parseInt(value)*3;
System.out.println("哇哈哈純凈水:"+value+"件,合計:¥"+Integer.parseInt(value)*3);
}elseif(key.equals("2")){
hj+=Integer.parseInt(value)*5;
System.out.println("康師傅方便麵:"+value+"件,合計:¥"+Integer.parseInt(value)*5);
}elseif(key.equals("3")){
hj+=Integer.parseInt(value)*4;
System.out.println("可口可樂:"+value+"件,合計:¥"+Integer.parseInt(value)*4);
}
}
System.out.println("合計金額:¥"+hj);
}
publicstaticvoidinit(){
System.out.println("******************");
System.out.println(" 商品列表
");
System.out.println("商品名稱價格");
System.out.println("1.哇哈哈純凈水¥3");
System.out.println("2.康師傅方便麵¥5");
System.out.println("3.可口可樂¥4");
System.out.println("******************");
}
publicstaticMap<String,String>buy(Scannerscan,Map<String,String>m){
System.out.print("請輸入編號:");
Stringbh=scan.nextLine();
System.out.print("請輸入購買數量:");
Stringnum=scan.nextLine();
if(m.size()>0&&m.keySet().contains(bh)){
m.put(bh,(Integer.parseInt(bh)+Integer.parseInt(num))+"");
}else{
m.put(bh,num);
}
returnm;
}
}
㈣ 求用javascript編寫的簡易購物車小程序如圖所示:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
/*
*@author Caoshun
*@計算 合計費用
*/
function countMethod(){
var num=document.getElementById("num").value;
var unitPrice=document.getElementById("unitPrice").value;
var freight=document.getElementById("freight").value;
document.getElementById("result").value=parseFloat((num*unitPrice))+parseFloat(freight);
}
</script>
</head>
<body>
<table border="1" cellpadding="1" cellspacing="1" background="#red" style="text-align: center;">
<tr><td colspan="5" align="center">簡易購物車</td></tr>
<tr>
<td>商品名稱</td>
<td>數量(件)</td>
<td>單價(美元)</td>
<td>運費(美元)</td>
<td><input type="button" value="合計" onclick="countMethod();"></td>
</tr>
<tr>
<td>跑跑道具</td>
<td><input type="text" size="6" id="num"></td>
<td><input type="text" size="6" id="unitPrice"></td>
<td><input type="text" size="6" id="freight"></td>
<td><input type="text" size="6" id="result"></td>
</tr>
</table>
</body>
</html>
㈤ MVC模式編寫購物車代碼
需求寫的不錯啊。可以實現了,首先看下需要什麼表,根據實體建表,然後對這些表進行增刪改查就ok了。
購物車要注意處理事務。
㈥ 購物車代碼怎麼寫php
寫就行了,跟普通的一樣,不就是資料庫的增刪改查嗎
㈦ 你好,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可能顯示不出來你的效果。不滿意得話我在給你編一個。
㈧ C#中的購物車,誰給個簡單代碼
IList<int> list=new IList<int>; //設置一個INT類型的泛型
list.add(commodityId);//往list里加商品的ID
Session["shop"]=list;//把list放到內Session里
這個session就是一個購物車了容
要把東西取出來
IList<int> list = (Session as IList<int>);
就可以了
㈨ 想做一個簡單的購物車界面,非常簡單就行有代碼!用div+css做就可以
購物車外是可以的 但是核心最好還是用程序本來的核心如果自己寫,很有單獨
㈩ JS代碼 做一個簡易的購物車 效果圖如下
樓主是想要點擊合計就是出數值還是什麼?如果說點擊合計就算出值的話如下
<tablewidth="400"border="1">
<tr>
<throws="5">簡易購物車</th>
</tr>
<tr>
<td>商品名稱</td>
<td>數量(件)</td>
<td>單價(美元)</td>
<td>運費(美元)</td>
<td><buttononclick="fun()">合計</button></td>
</tr>
<tr>
<td><inputtype="text"name="goodsName"/></td>
<td><inputtype="text"name="num"id="num"/></td>
<td><inputtype="text"name="price"id="price"/></td>
<td><inputtype="text"name="freight"id="freight"/></td>
<td><inputtype="text"name="total"id="total"/></td>
</tr>
</table>
<script>
functionfun(){
varnum=document.getElementById("num").value;
varprice=document.getElementById("price").value;
varfreight=parseInt(document.getElementById("freight").value);
vartotal=(price*num)+freight;
document.getElementById("total").value=total;
}
</script>