java充值余额代码 java话费充值代码

用java编译一段程序,包括开户,存款,取款,显示余额4个部分,急啊,若回答够快,可加分!急啊!!!

User.java

创新互联专注于山西企业网站建设,成都响应式网站建设公司,商城开发。山西网站建设公司,为山西等地区提供建站服务。全流程定制网站设计,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

public class User {

private String userName; // 账号

private double amount; // 金额

public String getUserName() {

return userName;

}

public void setUserName(String userName) {

this.userName = userName;

}

public double getAmount() {

return amount;

}

public void setAmount(double amount) {

this.amount = amount;

}

}

BankService.java

import com.bank.po.User;

public interface BankService {

//用户选择操作类型

public void userChoose(String serialNumber);

//开户

public User addUser();

//存款

public User addAmount(User user);

//取款

public User withdrawal(User user);

//查询余额

public void lookBalance(User user);

}

BankServiceImpl.java

import com.bank.po.User;

import com.bank.service.BankService;

import com.bank.util.InputUtil;

public class BankServiceImpl implements BankService{

private static User user;

public void userChoose(String serialNumber){

System.out.println("Please choose the type of operation(Input serial number):");

System.out.println("1 : 开户(Add user)");

System.out.println("2 : 存款(deposit)");

System.out.println("3 : 取款(withdrawals)");

System.out.println("4 : 查询余额(Inquires the balance)");

serialNumber = InputUtil.input();

if("1".equalsIgnoreCase(serialNumber)){

user = addUser();

}else{

if(null != user){

if("2".equalsIgnoreCase(serialNumber)){

user = addAmount(user);

System.out.println("Deposit success !");

}

if("3".equalsIgnoreCase(serialNumber)){

user = withdrawal(user);

System.out.println("Withdrawals success !");

}

if("4".equalsIgnoreCase(serialNumber))

lookBalance(user);

else{

System.out.println("Input is wrong, please input anew !");

}

}else{

System.out.println("Please first open an account");

}

}

userChoose(null);

}

public User addUser() {

User user = new User();

System.out.println("Welcome to use: please first accounts !");

System.out.println("Please enter your user name :");

String userName = InputUtil.input();

System.out.println("Please input amount(please input digital) :");

String amount = InputUtil.input();

user.setUserName(userName);

user.setAmount(Double.parseDouble(amount));

return user;

}

public User addAmount(User user) {

System.out.println("Please input amount(please input digital) :");

String amount = InputUtil.input();

user.setAmount(user.getAmount() + Double.parseDouble(amount));

return user;

}

public User withdrawal(User user) {

System.out.println("Please input amount(please input digital) :");

String amount = InputUtil.input();

user.setAmount(user.getAmount() - Double.parseDouble(amount));

return user;

}

public void lookBalance(User user) {

System.out.println("Your balance for :" + user.getAmount());

}

}

InputUtil.java

public class InputUtil {

public static String input(){

Scanner sc = new Scanner(System.in);

String input = sc.next();

return input;

}

}

测试类

Test.java

import com.bank.service.BankService;

import com.bank.service.impl.BankServiceImpl;

public class Test {

public static void main(String[] args) {

BankService bank = new BankServiceImpl();

bank.userChoose(null);

}

}

java 创建账户类,定义存钱取钱,查询余额方法,并自定义两个异常

main方法不对啊

少了public

public static void main(String[] args) {}

这次是对的

怎么实现用java编写使用余额付款

abstract class BankCard {

protected String name;

protected String cardNo;

protected double money;

public BankCard(String name, String cardNo, double money) {

super();

this.name = name;

this.cardNo = cardNo;

this.money = money;

}

public String getName() {

return name;

}

public String getCardNo() {

return cardNo;

}

public double getMoney() {

return money;

}

public abstract void unputMoney(int someMoney);

public void putMoney(int someMoney) {

this.money += someMoney;

}

}

java 定义一个类实现银行账户 包括变量 "帐号""存款余额",方法:"存款","取款"和"查询

private double money=0L ;

public void addMoney(double money){

this.money=this.money+ money;

System.out.println("余额"+this.money);

}

public void outMoney(double money){

if(moneythis.money){

System.out.println("余额不足!");

}else{

this.money=this.money- money;

System.out.println("取出"+money+"元,余额"+this.money);

}

}

public void getMoney(){

System.out.println("余额"+this.money);

}


当前文章:java充值余额代码 java话费充值代码
分享路径:http://ybzwz.com/article/doccggd.html