2016/3/30 ATM机

必须把整个循环放入方法中      有int  或者 long 必须设成公共数

package NO03;

import java.util.Scanner;
        
public class No1ATM {
public static   long shen = 150000;
public static   int y = 0, k=0,t=0;
public static void  case03(){
    while(y>0) {
   if (k==1&&t==2) {
    System.out.println("请选择业务:   1.查询余额     2.取款    3.存款     4退出 ");
    Scanner yewu = new Scanner(System.in);
    int xuanze = yewu.nextInt();

    switch (xuanze) {
    case 1:
     System.out.println(shen);
     break;
    case 2:
     System.out.println("请输入取走金额");
     Scanner quqian = new Scanner(System.in);
     long qu = quqian.nextLong();
     if (qu <= 0) {
      System.out.println("数额不能为零和负数");
     }

     else if (qu % 100 != 0) {
      System.out.println("输入的数不是100的倍数");
      break;
     }  else if (qu > 200000) {
      System.out.println("c超出最大金额");
      break;
     }

     else {
      shen -= qu;
     }
     break;

    case 3:
     System.out.println("请放入钞票");
     Scanner cunqian = new Scanner(System.in);
     long cun = cunqian.nextLong();
     if (cun <= 0) {
      System.out.println("数额不能为零和负数");
     }

     else if (cun % 100 != 0) {
      System.out.println("输入的数不是100的倍数");
      break;
     }

     else if (cun > shen) {
      System.out.println("大于用户余额");
      break;
     }

     else if (cun > 200000) {
      System.out.println("c超出最大金额");
      break;
     }
     
     if (cun + shen > 200000) {
      System.out.println("超出存储总上限");
     }  shen += cun;
     break;
    case 4:
     System.exit(0);
     break;
    }
   }

   else {
    System.out.print("登录失败 请重新登录");
   }
   ;}
}
public static void  case02(){
 Scanner zhuye = new Scanner(System.in);
 
 
 while (y < 3) {
  y++;
  System.out.println("请输入用户名");
  String yonghu = zhuye.next();
  System.out.println("请输入密码");
  String mima = zhuye.next();
  if(yonghu.equals("233") && mima.equals("666")){
   k=1;t=2;break;
  }else if(y==3){System.exit(0);}
 }
}
 
 
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  /* 用户为666 密码为233 */
  System.out.println("欢迎使用¥ATM机");// System.out.println()显示括号内的文字
  System.out.println("请选择操作——1.登录——2.退出");
  Scanner s = new Scanner(System.in);// Scanner(System.in) 将输入信息赋予s
  int i = s.nextInt();
  if (i == 1) {
   case02();
   case03();

  }

 }

}

原文地址:https://www.cnblogs.com/waxlh/p/5338971.html