import java.util.*;
import java.text.*;
public class PersonageMain
{
public static List<Person> openMember(){
List<Person> list=new ArrayList<Person>();
Person person=new Person();
person.setName("lisi");
person.setPassword("123456");
person.setSex("男");
person.setPhone("15812345678");
person.setCardNumber("23688195609091234");
person.setBalance(20.0);
person.setState(false);
list.add(person);
for(Person p:list){
System.out.println("用户:"+p.getName());
System.out.println("密码:"+p.getPassword());
System.out.println("性别:"+p.getSex());
System.out.println("手机号码:"+p.getPhone());
System.out.println("身份证号码:"+p.getCardNumber());
System.out.println("账户余额:"+p.getBalance());
if(person.getState()==false){
System.out.println("用户状态:未上机");
}else{
System.out.println("用户状态:上线中");
}
}
return list;
}
public static void begin(List<Person> list){
Scanner scanner=new Scanner(System.in);
for(Person person:list){
int a=0;
int b=0;
for(int i =0;i<3;i++){
System.out.print("账户:");
String name=scanner.next();
if(person.getName().equals(name)){
System.out.println("账号输入正确");
break;
}else{
a++;
System.out.println("账号输入有误"+a+"次"+",请重新输入");
}
}
for(int i =0;i<3;i++){
System.out.print("密码:");
String password=scanner.next();
if(person.getPassword().equals(password)){
System.out.println("密码输入正确");
break;
}else{
b++;
System.out.println("密码输入有误"+b+"次"+",请重新输入");
}
}
person.setState(true);
if(person.getBalance()<=0){
System.out.println("您的账户余额不足,请充值!");
topUp(list);
}
timerStart(list);
}
}
public static double topUp(List<Person> list){
double d=0.0;
for(Person person:list){
Scanner scanner =new Scanner(System.in);
if(person.getState()==false){
System.out.print("请输入充值用户:");
String name=scanner.next();
if(name.equals(person.getName())){
double f1=0.0;
double money1=0.0;
while(true){
System.out.print("是否要充值y/n:");
String str=scanner.next();
if(str.equals("y")){
System.out.print("请输入充值金额:");
money1=scanner.nextDouble();
f1=person.getBalance()+money1;
person.setBalance(f1);
d+=person.getBalance();
System.out.println("账户余额:"+person.getBalance());
}else if(str.equals("n")){
break;
}
}
}else{
System.out.println("账号错误!");
}
}else {
double f1=0.0;
double money1=0.0;
while(true){
System.out.print("是否要充值y/n:");
String str=scanner.next();
if(str.equals("y")){
System.out.print("请输入充值金额:");
money1=scanner.nextDouble();
f1=person.getBalance()+money1;
person.setBalance(f1);
d+=person.getBalance();
System.out.println("账户余额:"+person.getBalance());
}else if(str.equals("n")){
break;
}
}
}
}
return d;
}
public static void timerStart(List<Person> list){
Date d1=;
for(Person person:list){
if(person.getBalance()>0){
d1 =new Date();
MonitoringThread mt=new MonitoringThread(d1,list);
mt.start();
if(monitoring(d1,list)){
if(person.getState()){
System.out.println("用户状态:上线中");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try
{
String d12 = df.format(d1);
System.out.println("上线时间:"+d12);
}
catch (Exception e)
{
e.printStackTrace();
}
}
timerFinish(d1,list);
break;
}
}else{
System.out.println("余额不足请充值");
topUp(list);
}
}
}
public static void timerFinish(Date d1,List<Person> list){
Scanner scanner =new Scanner(System.in);
for(Person person:list){
if(monitoring(d1,list)!=true){
Date d2=new Date();
person.setState(false);
System.out.println("您已强制下线");
startFinishTimer(d1,d2,list);
break;
}
System.out.print("是否要下线y/n:");
String st=scanner.next();
if(st.equals("y")){
Date d2=new Date();
person.setState(false);
System.out.println("您已下线");
startFinishTimer(d1,d2,list);
break;
}else if(st.equals("n")){
System.out.println("继续上线");
}
}
}
public static void startFinishTimer(Date d1,Date d2,List<Person> list){
String timeT=;
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try
{
long diff = d2.getTime() - d1.getTime();
System.out.println("下线时间:"+df1.format(d2));
long days = diff / (1000 * 60 * 60 * 24);
long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
long ss = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60)-minutes*(1000*60))/(1000);
System.out.println("本次上机时间为:"+days+"天"+hours+"小时"+minutes+"分"+ss+"秒");
timeT=days+"-"+hours+"-"+minutes;
}catch (Exception e){}
consumption(timeT,list);
}
public static void consumption(String timeT,List<Person> list){
try{
String d[]=timeT.split("-");
String days=d[0];
String hours=d[1];
String minutes=d[2];
String timeK=days+"天"+hours+"时"+minutes+"分钟";
int da=Integer.parseInt(days);
int h=Integer.parseInt(hours);
int m=Integer.parseInt(minutes);
double fei_d=100;
double fei_h=5.0;
double fei_m=10;
System.out.println("上机总时间:"+timeK);
for(Person p:list){
if(da>=1){
double newFei=da*fei_d;
if(p.getBalance()>=newFei){
double sy=p.getBalance()-newFei;
p.setBalance(sy);
System.out.println(da+"天"+"*"+fei_d+"元/天\n"+"消费:"+newFei+"元");
}else{
System.out.println("余额不足");
topUp(list);
}
}
if(h>=1){
double newFei=h*fei_h;
if(p.getBalance()>=newFei){
double sy=p.getBalance()-newFei;
p.setBalance(sy);
System.out.println(h+"时"+"*"+fei_h+"元/时\n"+"消费:"+newFei+"元");
}else{
System.out.println("余额不足");
topUp(list);
}
}
if(m>=1){
double newFei=m*fei_m;
if(p.getBalance()>=newFei){
double sy=p.getBalance()-newFei;
p.setBalance(sy);
System.out.println(m+"分钟"+"*"+fei_m+"元/分钟\n"+"消费:"+newFei+"元");
}else{
System.out.println("余额不足");
topUp(list);
}
}
System.out.println("下机剩余金额:"+p.getBalance());
}
}catch(NullPointerException e){
e.printStackTrace();
}
}
public static boolean monitoring(Date d,List<Person> list){
DateFormat df= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeT=;
try
{
String d2 = df.format(new Date());
Date d4=df.parse(d2);
long diff = d4.getTime() - d.getTime();
long days = diff / (1000 * 60 * 60 * 24);
long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
long ss = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60)-minutes*(1000*60))/(1000);
System.out.println("本次上机时间为:"+days+"天"+hours+"小时"+minutes+"分"+ss+"秒");
timeT=days+"-"+hours+"-"+minutes;
}catch (Exception e){
}
String str[]=timeT.split("-");
String days=str[0];
String hours=str[1];
String minutes=str[2];
String timeK=days+"天"+hours+"时"+minutes+"分钟";
int da=Integer.parseInt(days);
int h=Integer.parseInt(hours);
int m=Integer.parseInt(minutes);
double fei_d=100;
double fei_h=5.0;
double fei_m=10;
System.out.println("上机总时间:"+timeK);
double new_sum=0.0;
double sum=0.0;
for(Person p:list){
if(sum<=p.getBalance()){
if(da>=1){
double newFei=da*fei_d;
if(p.getBalance()>=newFei){
new_sum+=newFei;
System.out.println(da+"天"+"*"+fei_d+"元/天\n"+"消费:"+newFei+"元");
}else{
System.out.println("余额不足");
topUp(list);
}
}
if(h>=1){
double newFei=h*fei_h;
if(p.getBalance()>=newFei){
new_sum+=newFei;
System.out.println(h+"时"+"*"+fei_h+"元/时\n"+"消费:"+newFei+"元");
}else{
System.out.println("余额不足");
topUp(list);
}
}
if(m>=1){
double newFei=m*fei_m;
if(p.getBalance()>=newFei){
new_sum+=newFei;
System.out.println(m+"分钟"+"*"+fei_m+"元/分钟\n"+"消费:"+newFei+"元");
}else{
System.out.println("余额不足");
topUp(list);
}
}
}
sum=new_sum-sum;
System.out.println("监控消费"+sum);
System.out.println("余额"+p.getBalance());
if(sum>=p.getBalance()){
System.out.println("监控。。。本次消费余额不足");
return false;
}
}
return true;
}
public static void welcome(){
List<Person> list=openMember();
Scanner scanner =new Scanner(System.in);
String str=;
do{
System.out.println("<=============>");
System.out.println("欢迎进入网咖系统");
System.out.println("<=============>");
System.out.print("1.登录\n2.充值\n0.退出\n请输入编号:");
int i=scanner.nextInt();
switch(i){
case 1:
begin(list);
break;
case 2:
topUp(list);
break;
case 0:
break;
}
System.out.print("是否继续 y/n:");
str=scanner.next();
}while(str.equals("y"));
if(str.equals("n")){
System.out.println("退出");
}
}
public static void main(String[] args)
{
welcome();
}
}
class MonitoringThread extends Thread
{
PersonageMain p=new PersonageMain();
Date date;
List<Person> list;
public MonitoringThread(Date date,List<Person> list){
this.date=date;
this.list=list;
}
@Override
public void run()
{
try{
while(true){
if(p.monitoring(date,list)){
}else{
System.out.println("监控。。。账户余额不足");
p.timerFinish(date,list);
break;
}
try{
Thread.sleep(63000);
}catch(Exception e){}
}
}catch(NullPointerException e){
e.printStackTrace();
}
}
}
class Person{
String name="";
String password="";
String sex="";
String cardNumber="";
String phone="";
double balance=0.0;
boolean state =false;
public String getName(){
return this.name;
}
public void setName(String name){
this.name=name;
}
public String getPassword(){
return this.password;
}
public void setPassword(String password){
this.password=password;
}
public String getSex(){
return this.sex;
}
public void setSex(String sex){
this.sex=sex;
}
public String getCardNumber(){
return this.cardNumber;
}
public void setCardNumber(String cardNumber){
this.cardNumber=cardNumber;
}
public String getPhone(){
return this.phone;
}
public void setPhone(String phone){
this.phone=phone;
}
public double getBalance(){
return this.balance;
}
public void setBalance(double balance){
this.balance=balance;
}
public boolean getState(){
return this.state;
}
public void setState(boolean state){
this.state=state;
}
}
class StateText extends Thread
{
@Override
public void run()
{
super.run();
for(int i=0;i<60;i++){
System.out.println(i);
try{
this.sleep(1000);
}catch(Exception e){
}
}
}
}