java-入门:模拟网络购物支付系统

时间:2021-07-26 10:46:18


1.用户登录后,判断是否是VIP/非VIP用户。如果是VIP用户,则总价=80%总价,非VIP用户,则无打折。

2.输出总价信息,以及总共购买的商品总数量。

3.不需要界面,纯Java编程。

Number.java

<pre class="java" name="code">public class Number {
private double amount;

public double getAmount() {
return amount;
}

public double setAmount(double amount) {
return this.amount = amount;
}


}

}
 

Price.java

public class Price {
double price=5.0;
public double vip(double price){
this.price=price;
return 0.8*price;
}
public double common(double price){
this.price=price;
return price;
}
}
</pre><pre class="java" name="code">
</pre><pre class="java" name="code">主函数:

import java.util.*;
public class Zhu {

public static void main(String[] args) {
int n;
String vip;
Price price=new Price();
Number number=new Number();
/*
*
*
*
* */
Scanner scanner=new Scanner(System.in);
System.out.print("请问您是否为Vip用户? 是:Y 否:N");
vip=scanner.next();
System.out.print("请问您购买的数量:?");
n=Integer.parseInt(scanner.next());
number.setAmount(n);
if(vip.equals("Y")){
System.out.print("vip总消费:"+(number.getAmount())*price.vip());
//System.out.print("vip总消费:"+(n*price.vip(10));
}
if(vip.equals("N")){
System.out.print("普通用户总消费:"+number.getAmount()*price.common());
//System.out.print("普通用户总消费:"+n*price.common(10));
}
}

}