如何用Java语言编写购物结算系统
答案:1 悬赏:50
解决时间 2021-01-14 02:45
- 提问者网友:眉目添风霜
- 2021-01-13 19:01
如何用Java语言编写购物结算系统
最佳答案
- 二级知识专家网友:风格不统一
- 2021-01-13 19:28
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.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+"角";
}
}
//看这样的行吗?
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.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+"角";
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息