购物结算的java代码,购物结算的java代码

如何用Java语言编写购物结算系统

import java.util.Scanner;

目前创新互联已为成百上千家的企业提供了网站建设、域名、雅安服务器托管、网站托管、服务器租用、企业网站设计、巫山网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

//看这样的行吗?

public class StoreCharge {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("输入应付金额:");

double x = sc.nextDouble();

Price p1 = ampayable(x);

System.out.println(p1.toString());

System.out.println("输入实付金额:");

double y = sc.nextDouble();

Price p2 = ampaid(y);

System.out.println(p2.toString());

System.out.println("找零:"+charge(p1,p2).toString());

charge(p1,p2);

}

public static Price charge(Price p1,Price p2){//p1总货价 p2收款

int c,b;

if(p2.connerp1.conner){

b = p2.conner+10-p1.conner;

p2.element = p2.element-1;

}else

b = p2.conner-p1.conner;

c = p2.element - p1.element;

return new Price(c,b);        

}

public static Price ampayable(double x){//应付金额

Price a = new Price();

a.element = (int)x;

a.conner  = (int)(x*10 -((int)x)*10);

return a;

}

public static Price ampaid(double x){//实付金额

Price a = new Price();

a.element = (int)x;

a.conner  = (int)(x*10 -((int)x)*10);

return a;

}

}

class Price{

int element;//元

int conner;//角

public Price(){}

public Price(int e,int c){

element = e;

conner = c;

}

public String toString(){

return element+"元"+conner+"角";

}

}

Java购物结算,卡在不懂do...while跳出循环和最后的总金额。求解决,谢谢

刚帮你调测了一下,当你输入"n"的时候,已经跳出循环了,只不过你没有输出提示,以为没出来,

又输入字符了所有报错了,应该是输入金额的,我帮你加了下输出你可以看下结果;

public static void main(String args[]){

System.out.println("********************");

System.out.println("");

System.out.println("请选择购买商品编号:");

System.out.println("1.T恤(¥245.0) 网球鞋(¥570.0) 网球拍(¥500.0)");

System.out.println("********************");

System.out.println("");

double s=0;

String d;

do{

System.out.println("请输入商品编号:");

Scanner input=new Scanner(System.in);

int a=input.nextInt();

if(a==1){

System.out.println("请输入购买数量:");

int b=input.nextInt();

double c=245*b;

System.out.println("T恤¥245.0 数量:"+b+" "+"合计:"+c);

s=s+c;

}

else if(a==2){

System.out.println("请输入购买数量:");

int b=input.nextInt();

double c=570*b;

System.out.println("网球鞋¥245.0 数量:"+b+" "+"合计:"+c);

s=s+c;

}

else if(a==3){

System.out.println("请输入购买数量:");

int b=input.nextInt();

double c=500*b;

System.out.println("网球拍¥245.0 数量:"+b+" "+"合计:"+c);

s=s+c;

}

else {System.out.println("无此商品");}

System.out.println("否继续(y/n)");

d=input.next();

}while(d.equals("y"));

System.out.println("===========付款===========");

System.out.println("=====输入金额=====");

Scanner input=new Scanner(System.in);

int x=input.nextInt();

double m=s*0.8;

System.out.println("折扣:0.8");

System.out.println("应付金额:"+m);

System.out.println("实际金额:"+x);

double p=x-m;

System.out.println("找钱:"+p);

}

用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编程,模拟网上购物(结算)

结算联系到好几个文件哦。上上个星期我们刚把网上购物车系统做完。下面是Servlet里的一段,希望对你有用!

else if (command.equalsIgnoreCase("modifybookcount")) {

int bookCartID = (Integer) session.getAttribute("bookcartID");

int operBookID = Integer.valueOf((String) request

.getParameter("operBookID"));

// 获得购物车中原有数量

int bookCount = Integer.valueOf((String) request

.getParameter("bookCount"));

// 获得需要会员修改的数量

int operBookCount = Integer.valueOf((String) request

.getParameter("operBookCount"));

// 得到图书数量增量

int bookCountIncrement = operBookCount - bookCount;

// 得到图书价格的增量

double bookPriceIncrement = bookCountIncrement

* Double.valueOf((String) request.getParameter("disPrice"));

CartListDAO cartlist = new CartListDAO();

// 更新购物车中图书的总数量和总价格

cartlist

.updateBookCount(bookCartID, operBookID, bookCountIncrement);

BookCartDAO bookcart = (BookCartDAO) session

.getAttribute("bookcart");

bookcart.updateCartData(bookCartID, bookPriceIncrement,

bookCountIncrement);

targetPage = "/cartlist.jsp";

RequestDispatcher dispatcher = request

.getRequestDispatcher(targetPage);

dispatcher.forward(request, response);

}

用java编程实现网上超市购物结算功能代码

哎,我还是自己代码黏贴给你吧!免得总通不过!装不下这么多字,详情自己找我。 连接数据库类(添加修改会员信息) package com.to.java; import java.util.Scanner; import java.sql.*; public class Vds { Scanner Input=new Scanner(System.in); ZhuCK1 zhuck1=new ZhuCK1(); public void x(){ try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt); System.out.println("----------查询结果---------"); System.out.println(); System.out.println("会员号--密码"); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id+" "+mm); } con.close(); stmt.close(); }catch(Exception e){ System.out.println(e);} System.out.println("是否返回上级菜单"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("欢迎下次再次使用");System.exit(-1);}; break; }} public void j(){ try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id+" "+mm); } Scanner input=new Scanner(System.in); System.out.println("请输入会员信息:"); System.out.println("请输入会员号:"); String f=input.next(); System.out.println("请输入密码:"); String q=input.next(); String sqlst="insert into gg values('"+f+"','"+q+"')"; Statement tatement=con.createStatement(); int result=tatement.executeUpdate(sqlst); System.out.println("操作成功!"); con.close(); stmt.close(); }catch(Exception e){ System.out.println(e); } System.out.println("是否返回上级菜单"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("欢迎下次再次使用");System.exit(-1);}; break; } } public void xg(){ try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id+" "+mm); } Scanner input=new Scanner(System.in); System.out.println("请输入会员信息:"); System.out.println("请输入要修改的会员号:"); String f=input.next(); System.out.println("请输入修改的密码:"); String q=input.next(); String sqlst="update gg set mm='"+q+"' where id='"+f+"'"; Statement tatement=con.createStatement(); int result=tatement.executeUpdate(sqlst); System.out.println("操作成功!"); con.close(); stmt.close(); }catch(Exception e){ System.out.println(e); } System.out.println("是否返回上级菜单"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("欢迎下次再次使用");System.exit(-1);}; break; } } } package com.to.java; import java.util.Scanner; public class KeHu { Vds sj=new Vds(); public void kehu1(){ Scanner Input=new Scanner(System.in); ZhuCK1 zhuck1=new ZhuCK1(); System.out.println("******************************************************"+"\n\n"); System.out.println("1.显示所有客户信息"); System.out.println("2.添加客户信息"); System.out.println("3.修改客户信息"); System.out.println("4.查询客户信息"); System.out.println("5.返回上级菜单"); System.out.println("******************************************************"+"\n\n"); System.out.println("请输入数字:"); int a=Input.nextInt(); switch(a){ case 1: sj.x(); break; case 2: sj.j(); break; case 3: sj.xg(); break; case 4: sj.x();break; case 5: zhuck1.ZhucK1();break; } } } package com.to.java; public class GouWuXiTong { public static void main(String[] args){ ZhuCK zhuck=new ZhuCK(); zhuck.ZhucK(); } } package com.to.java; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Scanner; public class ZhuCK { Scanner Input=new Scanner(System.in); public void ZhucK(){ ZhuCK1 zhuck1=new ZhuCK1(); System.out.println("\t\t"+"欢迎使用我心我素购物系统"); System.out.println("******************************************************"+"\n\n"); System.out.println("\t\t"+"1.登陆系统"); System.out.println(); System.out.println("\t\t"+"2.退出"+"\n\n"); System.out.println("******************************************************"); int d=1; while(d!=2){ System.out.println("请输入会员号:"); String p=Input.next(); System.out.println("请输入密码:"); String f=Input.next(); try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select * from gg"; rs=stmt.executeQuery(sqlstmt); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); if(id.equals(p)mm.equals(f)){ { System.out.println("请输入数字:"); int a=Input.nextInt(); switch(a){ case 1: zhuck1.ZhucK1(); break; case 2: break; }d=2; } } } }catch(Exception e){ System.out.println(e);} {System.out.println("输入错误请再次输入:");d=1;} } }} }


文章题目:购物结算的java代码,购物结算的java代码
网站地址:http://pwwzsj.com/article/dsiesos.html