求解答 Java作业
4个回答
展开全部
import java.math.BigDecimal;
public class BankUser {
private String userName;
private String passWord;
private BigDecimal balance;
public BankUser(String userName, String passWord, BigDecimal balance) {
this.userName = userName;
this.passWord = passWord;
this.balance = balance;
}
/**
* 存款
* @param userName 用户名
* @param passWord 密码
* @param num 钱数
*/
public String deposit(String userName,String passWord,BigDecimal num){
boolean flag = this.checkUserAndPassword(userName, passWord);
if(flag){
this.setBalance(balance.add(num));
return "操作成功,当前余额为:" +this.getBalance();
}else{
return "请检查用户名及密码";
}
}
/**
* 取款
* @param userName 用户名
* @param passWord 密码
* @param num 钱数
*/
public String withdrawMoney(String userName,String passWord,BigDecimal num){
boolean flag = this.checkUserAndPassword(userName, passWord);
if(flag){
this.setBalance(this.balance.subtract(num));
return "操作成功,当前余额为:" +this.getBalance();
}else{
return "请检查用户名及密码";
}
}
/**
* 转账
* @param userName 用户名
* @param passWord 密码
* @param num 钱数
*/
public String transferAccounts (String userName,String passWord,BigDecimal num,BankUser toUser){
boolean flag = this.checkUserAndPassword(userName, passWord);
if(flag){
this.setBalance(this.balance.subtract(num));
toUser.deposit(toUser.getUserName(), toUser.getPassWord(), num);
return "操作成功,当前余额为:" +this.getBalance();
}else{
return "请检查用户名及密码";
}
}
/**
* 校验用户名密码
* @param userName
* @param passWord
* @return
*/
private boolean checkUserAndPassword(String userName,String passWord){
if(userName!=null && passWord!=null
&& userName.equals(this.userName) && passWord.equals(this.passWord) ){
return true;
}else{
return false;
}
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public BigDecimal getBalance() {
return balance;
}
public void setBalance(BigDecimal balance) {
this.balance = balance;
}
}
没做过银行的业务,自己临时瞎写的 应付作业应该没有太大问题。
批量创建用户你自己写吧。
展开全部
public class BankUser {
String username;
String password;
double balance;
public BankUser(String username, String password, double balance) {
super();
this.username = username;
this.password = password;
this.balance = balance;
}
public String saveMoney(double money, String pwd) {
if (this.password == pwd) {
this.balance += money;
return "存款成功";
} else {
return "密码错误";
}
}
public String drawMoney(double money, String pwd) {
if (this.password == pwd) {
this.balance -= money;
return "取款成功";
} else {
return "密码错误";
}
}
public String transferMoney(BankUser user, double money, String pwd) {
if (this.password == pwd) {
this.balance -= money;
user.balance += money;
return "转账成功";
} else {
return "密码错误";
}
}
}
String username;
String password;
double balance;
public BankUser(String username, String password, double balance) {
super();
this.username = username;
this.password = password;
this.balance = balance;
}
public String saveMoney(double money, String pwd) {
if (this.password == pwd) {
this.balance += money;
return "存款成功";
} else {
return "密码错误";
}
}
public String drawMoney(double money, String pwd) {
if (this.password == pwd) {
this.balance -= money;
return "取款成功";
} else {
return "密码错误";
}
}
public String transferMoney(BankUser user, double money, String pwd) {
if (this.password == pwd) {
this.balance -= money;
user.balance += money;
return "转账成功";
} else {
return "密码错误";
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你好,作业的代码量有点点大啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
影响多不好
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询