作者在 2016-02-22 13:04:41 发布以下内容
import java.util.Scanner;
class bankcard
{
private String name;
private long num;
private int[] password=new int[6];
private int balance;
public String bankname;
public bankcard()
{
String name="none";
num=0L;
password=new int[]{0,0,0,0,0,0};
balance=0;
bankname="none";
}
public bankcard(String name,long num,String bankname)
{
this.name=name;
this.num=num;
this.bankname=bankname;
password=new int[]{0,0,0,0,0,0};
balance=0;
}
public void deposite(int rmb)
{
if(rmb>0)
{
balance+=rmb;
}
else
{
System.out.println("存入金额有误,请重试!");
}
}
public void withdraw(int rmb)
{
if(rmb>0&&rmb<=balance)
{
this.balance-=rmb;
}
else if(rmb>balance)
{
System.out.println("您的余额不足!");
}
else
{
System.out.println("取款金额有误,请重试!");
}
}
public void show()
{
System.out.println(bankname+"为您服务");
System.out.println("您的卡号:"+num);
System.out.println("您的姓名:"+name);
System.out.println("您的余额:"+balance);
}
public void setPassword()
{
for(int i=0;i<6;i++)
{
Scanner in=new Scanner(System.in);
password[i]=in.nextInt();
}
}
private boolean inputPassword()
{
int[] inputpassword=new int[6];
for(int i=0;i<6;i++)
{
Scanner in=new Scanner(System.in);
inputpassword[i]=in.nextInt();
}
if(password[0]==inputpassword[0]&&password[1]==inputpassword[1]&&password[2]==inputpassword[2]&&password[3]==inputpassword[3]
&&password[4]==inputpassword[4]&&password[5]==inputpassword[5])
return true;
else
return false;
}
public void login()
{
System.out.println("您好,请输入密码:");
if(inputPassword())
{
System.out.println("您好,"+bankname+"正在为您服务!");
}
else
{
System.out.println("无法登陆。");
}
}
}
public class TestJava
{
public static void main(String[] args)
{
bankcard card1=new bankcard("童朝中",3000198L,"中国银行");
card1.login();
card1.show();
card1.deposite(10000);
card1.withdraw(3000);
card1.show();
}
}