[训练5]信用卡消费记录
使用静态变量定义信用卡消费的总次数,控制台先输出使用信用卡消费时的每一条交易信息,
再输出使用信用卡消费的次数.运行结果如下:
您有一笔大额消费,交易金额:1555.0元
您有一笔大额消费,交易金额:1920.0元
您有一笔大额消费,交易金额:1979.0元
您有一笔大额消费,交易金额:2259.0元
您有一笔大额消费,交易金额:1835.0元
您有一笔大额消费,交易金额:1799.0元
您有一笔大额消费,交易金额:2688.0元
最近有7笔交易。
/* [训练5]信用卡消费记录
* 使用静态变量定义信用卡消费的总次数,控制台先输出使用信用卡消费时的每一条交易信息,
* 再输出使用信用卡消费的次数.运行结果如下:
* 您有一笔大额消费,交易金额:1555.0元
* 您有一笔大额消费,交易金额:1920.0元
* 您有一笔大额消费,交易金额:1979.0元
* 您有一笔大额消费,交易金额:2259.0元
* 您有一笔大额消费,交易金额:1835.0元
* 您有一笔大额消费,交易金额:1799.0元
* 您有一笔大额消费,交易金额:2688.0元
* 最近有7笔交易。
* */
package Lhdx;
public class Xl5 {
public static int cs = 0;//总次数
double amount;
public Xl5(double amount){
//构造方法
cs++;
this.amount = amount;
}
public void output() {
//成员方法
System.out.println("您有一笔大额消费,交易金额:" + amount +"元");
}
public static void main (String[] args) {//double自动保留一位小数
Xl5 c1 = new Xl5(1555);
c1.output();
Xl5 c2 = new Xl5(1920);
c1.output();
Xl5 c3 = new Xl5(1979);
c1.output();
Xl5 c4 = new Xl5(2259);
c1.output();
Xl5 c5 = new Xl5(1835);
c1.output();
Xl5 c6 = new Xl5(1799);
c1.output();
Xl5 c7 = new Xl5(2688);
c1.output();
System.out.println("最近有"+ Xl5.cs +"笔交易。");
}
// public Xl5(double amount) {
// cs++;
// System.out.println("您有一笔大额消费,交易金额:" + amount +"元");
// }
//
// public static void main(String[] args) {
// // TODO 自动生成的方法存根
// Xl5 xf1 = new Xl5(1555.0);
// Xl5 xf2 = new Xl5(1920.0);
// Xl5 xf3 = new Xl5(1979.0);
// Xl5 xf4 = new Xl5(2259.0);
// Xl5 xf5 = new Xl5(1835.0);
// Xl5 xf6 = new Xl5(1799.0);
// Xl5 xf7 = new Xl5(2688.0);
// System.out.println("最近有"+ Xl5.cs +"笔交易。");
//
// }
}