标签:sed import 错误 show str class 电话费 == print
主函数测试方法:
public class TestATM {
public static void main(String[] args) {
ABCATM a = new ABCATM();
//ICBCImpl icbc = new ICBCImpl(3000, "123456");//工商卡号
ABCImpl abc = new ABCImpl(3000, "123456");//农行卡号
//a.insertCard(icbc);
a.insertCard(abc);
a.allMenu();
}
}
ABCATM类
import java.util.Scanner;
public class ABCATM {
private UnionPay card;
public void insertCard(UnionPay userCard){
if(card == null){
card = userCard;
}
}
private void outCard(){
card = null;
}
private void showBalance(){
System.out.println("当前余额为:"+card.getBalance());
}
private void takeMoney(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入取款数目:");
double num = Double.parseDouble(sc.next());
if(card.drawMoney(num)){
System.out.println("取款成功");
}else{
System.out.println("取款失败");
}
}
private void payTelBill(){
Scanner sc = new Scanner(System.in);
if(card instanceof ABC){
ABC abcCard = (ABC)card;
System.out.println("请输入电话号码:");
String telNum = sc.next();
System.out.println("请输入缴费金额:");
double num = Double.parseDouble(sc.next());
if(abcCard.payTelBill(telNum, num)){
System.out.println("缴费成功");
}else{
System.out.println("缴费失败");
}
}else{
System.out.println("您的卡有误");
}
}
public void allMenu(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入密码:");
String pwd = sc.next();
if(card.checkPwd(pwd)){
System.out.println("请选择功能:\n 1.查看余额 2.取款 3.交电话费");
int choice = Integer.parseInt(sc.next());
switch(choice){
case 1:
showBalance();
break;
case 2:
takeMoney();
break;
case 3:
payTelBill();
break;
default:
System.out.println("非法输入");
}
}else{
System.out.println("密码错误");
}
this.outCard();
}
}
功能效果
标签:sed import 错误 show str class 电话费 == print
原文地址:http://www.cnblogs.com/ls00/p/6928460.html