Java基础实验二 T2

创建银行账号Account类,实现存款(balance)的存(deposit)、取(withdraw)和查询(getbala)等功能。

package Test_2;
import java.util.Scanner;

public class Account {

	private double Money;
	
	public double getMoney() {
		return Money;
	}
	
	public void setMoney(double money) {
		Money = money;
	}
	
	public Account()
	{
		this.Money = 0.0;
	}//默认构造函数
	
	public Account(double a)
	{
		this.Money = a;
	}//重载构造函数
	
	public void Deposit(double a,Account n)
	{
		n.Money += a;
	}//存
	
	public void Withdraw(double a,Account n)
	{
		n.Money -= a;
	}//取

	public void getbalance(Account n)
	{
		System.out.println("您的账户余额为:" + n.Money + "元");
	}
	
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Account account = new Account();
		
		System.out.println("输入您的初始金额:");
		Scanner in=new Scanner(System.in);
		double a1 = in.nextDouble();
		account.setMoney(a1);
		account.getbalance(account);
		
		boolean flag = true;
		while(flag)
		{
			System.out.println("选择您办理的业务:");
			System.out.println("存款请输入1/取款请输入2/查询请输入3/退出请输入0");
			int judge = in.nextInt();
			if(judge == 0)
				flag = false;
			else if(judge == 1)
			{
				System.out.println("输入您所存的金额:");
				double dep = in.nextDouble();
				account.Deposit(dep, account);
				
			}
			else if(judge == 2)
			{
				System.out.println("输入您所取的金额:");
				double with = in.nextDouble();
				account.Withdraw(with, account);
			}
			else if(judge == 3)
			{
				account.getbalance(account);
			}
			else 
			{
				System.out.println("输入有误,请重新输入");
			}
		}
		
		
	}

}

写得太僵硬了。
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值