本帖最后由 645420297 于 2013-4-21 10:47 编辑
- class FamilyAccount
- {
- public static void main(String[] args)
- {
- int balance = 10000;
- String details="收支\t账户金额\t收支金额\t说明";
- boolean loopFlag=true;
- int h = 0;
- String s1="";
- do
- {
- System.out.println("\n--------------------家庭收支 记账软件--------------------");
- System.out.println();
- System.out.println("\t"+ "1 收支明细");
- System.out.println("\t"+ "2 登记收人");
- System.out.println("\t"+ "3 登记支出");
- System.out.println("\t"+ "4 退 出");
- System.out.println();
- System.out.println();
- System.out.print("\t"+"请选择(1-4):");
- //从键盘上读取1,2,3,4四个字符
- char c=Utility.readMenuSelection();
- switch(c){
- case'1':
- System.out.println("--------------------当前收支明细记录---------------------");
- System.out.println( details+"\n"+"收入"+"\t"+balance+"\t\t"+h+"\t\t"+s1);
- System.out.println();
- System.out.println();
- break;
- case'2':
- System.out.print("本次收人金额:");
- int n=Utility.readNumber();
- //账户金额累加
- //怎样用更简单的方法把已经累加的结果返回到details中?
- balance+=n;
- h=balance-10000;
- System.out.print("本次收支说明");
- String s=Utility.readString();
- s1+=s;
- break;
- case'3':
- System.out.print("本次支出金额:");
- int z=Utility.readNumber();//读取支出的金额
- System.out.println("本次支出说明");
- String o=Utility.readString();
- break;
- case'4':
- System.out.print("确认是否退出(Y/N):");
- char m=Utility.readConfirmSelection();
- //如果Y,将标志位反转,当运行到While循环末尾时
- //条件不成立,故跳出循环
- if (m=='Y')
- {
- loopFlag=false;
- }
- break;
- }
- } while (loopFlag);
- }
- }
复制代码 |