import java.util.Scanner;
成都创新互联公司是一家集网站建设,零陵企业网站建设,零陵品牌网站建设,网站定制,零陵网站建设报价,网络营销,网络优化,零陵网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
public class GoShopping {
public static void main(String[] args) {
double sum=0;
Scanner input = new Scanner(System.in);
System.out.println("请输入消费金额:");
double money = input.nextDouble();
System.out.println("是否参加优惠活动:");
System.out.println("1:满50元,加2元可换购百事可乐饮料一瓶");
System.out.println("2:满100元,加3元可换购500ml可乐一瓶");
System.out.println("3:满100元,加10元可换购5公斤面粉");
System.out.println("4:满200元,加10元可换购1个苏泊尔炒菜锅");
System.out.println("5:满200元,加20元可换购欧莱雅爽肤水一瓶");
System.out.println("0:不换购");
System.out.println("请选择:");
int num = input.nextInt();
switch (num) {
case 0:
System.out.println("不换购!");
break;
case 1:
sum=money+2;
System.out.println("本次消费总金额:"+sum);
System.out.println("成功换购:百事可乐一瓶!");
break;
case 2:
sum=money+3;
System.out.println("本次消费总金额:"+sum);
System.out.println("成功换购:500ml可乐一瓶!");
break;
case 3:
sum=money+10;
System.out.println("本次消费总金额:"+sum);
System.out.println("成功换购:5公斤面粉!");
break;
case 4:
sum=money+10;
System.out.println("本次消费总金额:"+sum);
System.out.println("成功换购:苏泊尔炒菜锅!");
break;
case 5:
sum=money+20;
System.out.println("本次消费总金额:"+sum);
System.out.println("成功换购:欧莱雅爽肤水一瓶!");
break;
default:
System.out.println("操作有误!请核对后输入!");
break;
}
}
}
要定义一个变量来接收消费总金额 不能直接写成这样:
System.out.println("本次消费总金额:"+money+2);
这样只是把两个数连接起来(+号起连接作用) 而不是求和
算是最简单的吧
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;
}
}
}
package Test;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
init();//初始化
MapString,String map = new LinkedHashMap();
while(true){
Scanner in= new Scanner(System.in);
map = buy(in,map);//选择
System.out.println();
System.out.println("还要继续购物吗?(Y/N)");
String jx = in.nextLine();
if(jx.equals("N")){
break;
}
}
print(map);
}
public static void print(MapString, String m){
System.out.println("\n\n\n******************");
System.out.println(" 购物车清单");
Integer hj = 0;
for (EntryString, String entry : m.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if(key.equals("1")){
hj += Integer.parseInt(value)*3;
System.out.println("哇哈哈纯净水: "+value+"件,合计:¥"+Integer.parseInt(value)*3);
}else if(key.equals("2")){
hj += Integer.parseInt(value)*5;
System.out.println("康师傅方便面: "+value+"件,合计:¥"+Integer.parseInt(value)*5);
}else if(key.equals("3")){
hj += Integer.parseInt(value)*4;
System.out.println("可口可乐: "+value+"件,合计:¥"+Integer.parseInt(value)*4);
}
}
System.out.println("合计金额:¥"+hj);
}
public static void init(){
System.out.println("******************");
System.out.println("\t商品列表\n");
System.out.println(" 商品名称 价格");
System.out.println("1. 哇哈哈纯净水 ¥3");
System.out.println("2. 康师傅方便面 ¥5");
System.out.println("3. 可口可乐 ¥4");
System.out.println("******************");
}
public static MapString,String buy(Scanner scan,MapString,String m){
System.out.print("请输入编号:");
String bh = scan.nextLine();
System.out.print("请输入购买数量:");
String num = scan.nextLine();
if(m.size()0 m.keySet().contains(bh)){
m.put(bh,(Integer.parseInt(bh)+Integer.parseInt(num))+"");
}else{
m.put(bh, num);
}
return m;
}
}
import java.util.Scanner; public class ChangeGoods { public static void main(String[] args) { System.out.println("输入消费金额:"); Scanner scanner = new Scanner(System.in); String money = scanner.next(); int spendMoney = Integer.parseInt(money); System.out.println( "是否参加优惠换购活动?\n" + "1:满50元,加2元换购百事可乐饮料1瓶\n" + "2:满100元,加3元换购500ml可乐一瓶\n" + "3:满100元,加10元换购5公斤面粉\n" + "4:满200元,加10元可换购1个苏泊尔炒菜锅\n" + "5:满200元,加20元可换购欧莱雅爽肤水一瓶\n" + "0:不换购\n" + "请选择:" ); Scanner scannerInput = new Scanner(System.in); String select = scanner.next(); int option = Integer.parseInt(select); switch (option) { case 0: System.out.println("本次消费总金额:" + money); break; case 1: if(spendMoney=50){ System.out.println("本次消费总金额:" + (spendMoney + 2) ); System.out.println("成功换购:百事可乐饮料1瓶"); } break; case 2: if(spendMoney=100){ System.out.println("本次消费总金额:" + (spendMoney + 3) ); System.out.println("成功换购:500ml可乐一瓶"); } break; case 3: if(spendMoney=100){ System.out.println("本次消费总金额:" + (spendMoney + 10) ); System.out.println("成功换购:5公斤面粉"); } break; case 4: if(spendMoney=200){ System.out.println("本次消费总金额:" + (spendMoney + 10) ); System.out.println("成功换购:1个苏泊尔炒菜锅"); } break; case 5: if(spendMoney=200){ System.out.println("本次消费总金额:" + (spendMoney + 20) ); System.out.println("成功换购:欧莱雅爽肤水一瓶"); } break; default: break; } } }