www.pudn.com > Wallet.java.rar > Wallet.java, change:2005-12-27,size:2190b


 
 
import java.io.*; 
 
public class Wallet 
 
{ 
 
        private int money;  
 
      public void Wallet()  
 
        { 
 
           money = 0; 
 
        } 
 
       // 往钱包中存钱 
 
        public void saveMoney(int inputMoney)  
 
        {           money = money + inputMoney; 
 
        } 
 
       //从钱包中取钱 
 
        public void loadMoney(int inputMoney) 
 
        { 
 
           money = money - inputMoney; 
 
        } 
 
       //检查钱包中资金余额,并打印 
 
        public void checkAvailable() 
 
        { 
 
           System.out.println("余额为"+money); 
 
        } 
 
        public static void main(String[] args) throws IOException 
 
        { 
 
           Wallet wt = new Wallet(); 
           Boolean b; 
          do{ 
            
           System.out.println("存钱按1,取钱按2,查询余额请按3"); 
 
        BufferedReader reader1 = new BufferedReader(new InputStreamReader(System.in));  
 
           String s=reader1.readLine(); 
 
          Integer in=new Integer(s); 
 
                           switch(in) 
 
                   {    
       
                    case 1:        { System.out.println("你要存入多少钱?"); 
 
                    BufferedReader reader2 = new BufferedReader(new InputStreamReader(System.in));  
 
                    String s1=reader2.readLine(); 
 
                    Integer in1=new Integer(s1); 
 
                    wt.saveMoney(in1);}    break; 
 
                    case 2: {      System.out.println("你要取出多少钱?"); 
 
 
                    BufferedReader reader3 = new BufferedReader(new InputStreamReader(System.in));  
                         String s1=reader3.readLine(); 
 
                      Integer in2=new Integer(s1); 
 
                    wt.loadMoney(in2);}    break; 
                     case 3:wt.checkAvailable(); 
                    
                    } 
              System.out.println("如果要继续请按“E”键,退出直接ENTER"); 
                         BufferedReader r3=new BufferedReader(new InputStreamReader(System.in)); 
                         String s3=r3.readLine();  
                          b=(s3.equals("e"));       
            }while(b); 
 
        } 
 
}