消费金额的java代码 消费金额的java代码是什么
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编写程序计算打折后金额
public static void main(String[] args) {
double amount = 1200;// 消费金额
boolean isTeacherOrOld = true; // 是否有教师资格证或者老人标识
BigDecimal discountEightFive = new BigDecimal("0.85");// 85折
BigDecimal discountNine = new BigDecimal("0.9");// 95折
BigDecimal discountNineFive = new BigDecimal("0.95");// 95折
BigDecimal bdAmount = new BigDecimal(Double.toString(amount));
BigDecimal calcAmount = new BigDecimal("0.00");
if (amount = 2000) {
calcAmount = bdAmount.multiply(discountEightFive);
} else if (amount 1000 amount 2000) {
calcAmount = bdAmount.multiply(discountNine);
} else {
calcAmount = new BigDecimal(Double.toString(amount));
}
if (isTeacherOrOld amount = 1000) {
System.out.println("消费金额:" + calcAmount.multiply(discountNineFive).toString());
} else {
System.out.println("消费金额:" + calcAmount.toString());
}
}
java代码
import java.util.Scanner;
/**
* @author a href="mailto:116982086@qq.com"/a
*/
public class Demo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入消费金额");
double sum = scanner.nextDouble();
String what = null;
// 如果消费金额大于50才提示换购
if (sum = 50) {
System.out.println("是否参加优惠换购活动:");
System.out.println("1:满50元,加2元换购百事可乐饮料一瓶");
if (sum = 100) {
System.out.println("2:满100元,加3元换购500ml可乐一瓶");
System.out.println("3:满100元,加3元换购500ml可乐一瓶");
}
if (sum = 200) {
System.out.println("4:满200元,加10元可换购1歌苏泊尔炒菜锅");
System.out.println("5:满200元,加20元可换购欧莱雅爽肤水一瓶");
}
System.out.println("0:不换购");
System.out.println("请选择:");
int choice = scanner.nextInt();
int add = 0;
switch (choice) {
case 1:
add = 2;
what = "500ml可乐一瓶";
break;
case 2:
add = 3;
what = "500ml可乐一瓶";
break;
case 3:
add = 3;
what = "5公斤面粉";
break;
case 4:
add = 10;
what = "一个歌苏泊尔炒菜锅";
break;
case 5:
add = 20;
what = "欧莱雅爽肤水一瓶";
break;
default:
break;
}
sum += add;
}
System.out.println("本次消费总金额: " + sum);
if (null != what) {
System.out.println("成功换购 " + what);
}
}
}
用java写出商品打折程序
尝试解答一下,这个里面还有老年和教师的判断就省略,主要是打折的代码
import java.util.Scanner;
class Test{
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入消费的金额:");
double oldprice = sc.nextDouble();
double newprice;
if(oldprice = 2000){
newprice = oldprice * 0.85;
}else if(oldprice = 1000 oldprice 2000){
newprice = oldprice * 0.9;
}else
newprice = oldprice;
Judge jud = new Judge();
if(jud.isTeacher()|| jud.isOldman())
newprice = newprice * 0.95;
System.out.println("打折后的价格是:" + newprice);
System.out.println("折扣的程度是: " + newprice / oldprice);
}
}
class Judge{
public boolean isTeacher(){
boolean isTeacher = false;
return isTeacher;
}
public boolean isOldman(){
boolean isOld = false;
return isOld;
}
}
今天刚学的,用java实现输入任意金额,达到用户想知道什么信息就知道什么信息,
publicintgetMaxRepeatTime(Strings){inttime=0;String[]list=s.split("");for(Stringtemp:list){intcount=0;for(Stringi:list){if(temp.equals(i)){count+=1;}}if(counttime){time=count;}}returntime;}这个方法可以获取某个输入字符串中重复最多字符的重复数。你可以按你的需要进行修改,获得这个字符,或者是获得指定字符重复的次数等等。。你早点把题目说清楚嘛。。你这个需求就更简单了:publicStringgetRepeatChar(Strings){Stringoutput="";String[]list=s.split("");for(Stringtemp:list){intcount=0;for(Stringi:list){if(temp.equals(i)){count+=1;}}if(count1){output+=temp+"";}}returnoutput;}
编写一个java消费单算出折扣怎么写如图
没有理解你的问题,是想打印出图上的效果,还是说告诉我原价和折后价让我算折扣?
网站名称:消费金额的java代码 消费金额的java代码是什么
网页路径:http://azwzsj.com/article/dodssic.html