package javaBasic;
import java.text.SimpleDateFormat;
import java.util.*;
public class StudentCard {
public static void main(String[] args) {
StuCard sc = new StuCard("20191677","Moliy",'g',100,2018,11,21);
sc.printInfo();
System.out.println();
sc.consume(8);
sc.printInfo();
System.out.println();
sc.save(50);
sc.printInfo();
}
}
class StuCard{
private String id;
private String name;
private char sex;
private double money;
private Date consumeDate;
private GregorianCalendar gc;//表示日期
StuCard(String id,String name,char sex,double money,int year,int month,int day){
this.id = id;
this.name = name;
this.sex = sex;
this.money = money;
gc = new GregorianCalendar(year,month,day);
consumeDate = gc.getTime();
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public char getSex() {
return sex;
}
public double getMoney() {
return money;
}
public Date getConsumeDate() {
return consumeDate;
}
public String getStringofConsumeDate() {
return new SimpleDateFormat("yyyy-MM-dd").format(consumeDate).toString();
}
public void consume(double m) {
money = money - m;
System.out.println("consume "+m);
}
public void save(double m) {
money = money + m;
System.out.println("save "+m);
}
public void printInfo() {
System.out.println("id:"+getId()+"\nname:"+getName()+"\nsex:"+getSex()+"\nmoney:"+getMoney()+"\ngetIdDay:"+getStringofConsumeDate());
}
}