试试这个吧
创新互联公司10多年企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,企业网站建设及推广,对成都加固等多个领域拥有丰富的网站制作经验的网站建设公司。
DecimalFormat df = new DecimalFormat("0");
String kkzh = df.format(pksj.getKkzh());
str += kkzh+",";
import java.util.Random;
public class Test2 {
private static void cal(Player winner, Player[] losers) {
int win = 0;
for (Player loser : losers) {
if (loser.money winner.money) {
loser.money -= winner.money;
win += winner.money;
} else {
win += loser.money;
loser.money = 0;
}
}
winner.money += win;
}
public static void main(String[] args) {
Random random = new Random();
Player A = new Player("A", random.nextInt(1000));
Player B = new Player("B", random.nextInt(1000));
Player C = new Player("C", random.nextInt(1000));
Player D = new Player("D", random.nextInt(1000));
System.out.println("计算前");
System.out.println(A.name + ":" + A.money);
System.out.println(B.name + ":" + B.money);
System.out.println(C.name + ":" + C.money);
System.out.println(D.name + ":" + D.money);
Player[] losers = new Player[3];
losers[0] = B;
losers[1] = C;
losers[2] = D;
cal(A, losers);
losers = new Player[2];
losers[0] = C;
losers[1] = D;
cal(B, losers);
losers = new Player[1];
losers[0] = D;
cal(C, losers);
System.out.println("计算后");
System.out.println(A.name + ":" + A.money);
System.out.println(B.name + ":" + B.money);
System.out.println(C.name + ":" + C.money);
System.out.println(D.name + ":" + D.money);
}
}
class Player {
public String name;
public int money;
public Player(String name, int money) {
this.name = name;
this.money = money;
}
}
public class Test extends PhoneKouFei{
public Test(String startTime, String stopTime) {
super(startTime, stopTime);
}
public static void main(String[] args) {
String start = "00:12:23";
String stop = "00:15:23";
new Test(start,stop);
}
}
abstract class PhoneKouFei{
private final double fei = 1.5;//1分钟扣1毛5
public String startTime; //通话开始时间
public String stopTime; //通话结束时间
public PhoneKouFei(String startTime, String stopTime){
this.startTime = startTime;
this.stopTime = stopTime;
System.out.println("通话时常:" +getKouFei()+ "分钟");
System.out.println("应扣费:" + (double)getKouFei() * fei);
}
//扣费方法
private final long getKouFei(){
java.text.SimpleDateFormat sim = new java.text.SimpleDateFormat("HH:mm:ss");
try {
java.util.Date start = sim.parse(this.startTime);
java.util.Date stop = sim.parse(this.stopTime);
return (stop.getTime() - start.getTime()) / 60000;
} catch (java.text.ParseException e) {
throw new RuntimeException("时间格式错误..");
}
}
}
//输出结果:
通话时常:3分钟
应扣费:4.5
首先得这个Java程序得常年在后台运行。每天都进行如下操作:
检测到当天日期,如果不是1月1日,则将标志变量置0.
如果是1月1日,检测标志变量,
如果是0:进行一次扣费,然后标志变量置1;
如果是1,不进行任何操作。