小白Java作业求助QAQ,创建一个BankCard类
发布网友
发布时间:2022-04-20 14:18
我来回答
共2个回答
热心网友
时间:2023-11-10 11:38
public class BankCard {
int cardNumber;
String name;
int passWord;
int balance;
int idNumber;
public BankCard (int idNumber, String name) {
this.idNumber = idNumber;
this.name = name;
passWord = 666666;
balance = 0;
cardNumber = 62208888;
}
public boolean changePwd (int passWord) {
this.passWord = passWord;
return true;//修改密码成功
}
public boolean deposit (int moneyIn) {
this.balance += moneyIn;
return true;//存款成功
}
public boolean drawMoney (int moneyOut) {
this.balance -= moneyOut;
return true;//取款成功
}
public void printInformation () {
System.out.println("卡号:" + cardNumber +
"\n姓名:" + name +
"\n身份证号:" + idNumber +
"\n卡内余额:" + balance +
"\n当前密码:" + passWord);
}
}
希望可以给个采纳,谢谢
热心网友
时间:2023-11-10 11:38
package cn.itcast.redis;
import java.util.Scanner;
public class BankCard {
private String user;
private String name;
private String password;
private double yu_e;
private String sfz;
public static Scanner sc = new Scanner(System.in);
public BankCard(String name, String sfz) {
this.name = name;
this.sfz = sfz;
}
public BankCard() {
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = "62208888";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = "666666";
}
public double getYu_e() {
return yu_e;
}
public void setYu_e(double yu_e) {
this.yu_e = 0;
}
public String getSfz() {
return sfz;
}
public void setSfz(String sfz) {
this.sfz = sfz;
}
//修改密码
public void changPwd() {
System.out.println("请输入新的密码:");
password = sc.next();
System.out.println("修改成功新的密码为:" + password);
}
public void deposit() {
System.out.println("请输入存储金额:");
double cun = sc.nextInt();
yu_e = cun;
System.out.println("成功存储" + cun + "总金额为:" + yu_e);
}
public void drawMoney() {
System.out.println("请输入取款金额:" );
double qu=sc.nextInt();
if (qu>yu_e){
System.out.println("您的余额不足");
}else {
yu_e -= qu;
System.out.println( "以取出:"+qu+"元,余额:"+yu_e);
}
}
public static void main(String[] args){
BankCard b=new BankCard();
while (true) {
System.out.println("修改密码请按1 存储金额请按2 取款请按3 退出请按0");
String a = sc.next();
switch (a){
case "1":b.changPwd();break;
case "2":b.deposit();break;
case "3":b.drawMoney();break;
case "0":return;
}
}
}
}
有什么需要改进的 自己改一下 用笔记本写的 不容易!