用JAVA编(这是类和对象后的题)
编写程序,模拟银行账户功能。要求如下:属性:账号、储户姓名、地址、存款余额、最小余额。方法:存款、取款、查询。根据用户操作显示储户相关信息。如存款操作后,显示储户原有余额...
编写程序,模拟银行账户功能。要求如下:
属性:账号、储户姓名、地址、存款余额、最小余额。
方法:存款、取款、查询。
根据用户操作显示储户相关信息。如存款操作后,显示储户原有余额、今日存款
数额及最终存款余额;取款时,若最后余额小于最小余额,拒绝收款,并显示“
至少保留余额XXX” 展开
属性:账号、储户姓名、地址、存款余额、最小余额。
方法:存款、取款、查询。
根据用户操作显示储户相关信息。如存款操作后,显示储户原有余额、今日存款
数额及最终存款余额;取款时,若最后余额小于最小余额,拒绝收款,并显示“
至少保留余额XXX” 展开
2个回答
展开全部
package com.sorce.bankSys;
import java.util.Scanner;
import sun.security.action.GetBooleanAction;
public class BankSys {
private int uId; //这写好像用不上,你自己看着加吧
private String uName;
private String address;
private double minMon=0.50;
private double money=1000.50;
public static void main(String[] args) {
String answer;
// TODO Auto-generated method stub
System.out.println("欢迎进入存取款系统!");
System.out.println("---------------------");
do{
System.out.println("1.取款 \t2.查询余额\t3.存款");
Scanner sc=new Scanner(System.in);
BankSys bank=new BankSys();
int num=sc.nextInt();
switch (num) {
case 1:
bank.get();
break;
case 2:
bank.search();
break;
case 3:
bank.deposit();
break;
default:
break;
}
System.out.println("是否继续?(y/n)");
answer=sc.next();
}while(answer.equals("y"));
System.out.println("程序结束");
}
public void deposit(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入存款金额:");
double input=sc.nextInt();
System.out.println("您的帐户原有余额为:"+money+"元");
System.out.println("已存入:"+input+"元");
money+=input;
System.out.println("您的帐户最终存款余额为:"+money+"元");
}
public void search(){
System.out.println("您的帐户余额为:"+money+"元");
}
public void get(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入取款金额:");
double input=sc.nextInt();
if (money<input){
System.out.println("您的帐户余额不足!");
}else{
System.out.println("您本次取出:"+input+"元");
money-=input;
System.out.println("剩余金额为:"+money+"元");
}
}
}
import java.util.Scanner;
import sun.security.action.GetBooleanAction;
public class BankSys {
private int uId; //这写好像用不上,你自己看着加吧
private String uName;
private String address;
private double minMon=0.50;
private double money=1000.50;
public static void main(String[] args) {
String answer;
// TODO Auto-generated method stub
System.out.println("欢迎进入存取款系统!");
System.out.println("---------------------");
do{
System.out.println("1.取款 \t2.查询余额\t3.存款");
Scanner sc=new Scanner(System.in);
BankSys bank=new BankSys();
int num=sc.nextInt();
switch (num) {
case 1:
bank.get();
break;
case 2:
bank.search();
break;
case 3:
bank.deposit();
break;
default:
break;
}
System.out.println("是否继续?(y/n)");
answer=sc.next();
}while(answer.equals("y"));
System.out.println("程序结束");
}
public void deposit(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入存款金额:");
double input=sc.nextInt();
System.out.println("您的帐户原有余额为:"+money+"元");
System.out.println("已存入:"+input+"元");
money+=input;
System.out.println("您的帐户最终存款余额为:"+money+"元");
}
public void search(){
System.out.println("您的帐户余额为:"+money+"元");
}
public void get(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入取款金额:");
double input=sc.nextInt();
if (money<input){
System.out.println("您的帐户余额不足!");
}else{
System.out.println("您本次取出:"+input+"元");
money-=input;
System.out.println("剩余金额为:"+money+"元");
}
}
}
展开全部
import java.text.SimpleDateFormat;
import java.util.Date;
public class Bank {
private String account = "";
private String name = "";
private String address = "";
private long balance = 0l;
private final long minBalance = 100l;// 最少存款应该是固定的
public Bank() {
}
public Bank(String account, String name, String address, long balance) {
this.account = account;
this.name = name;
this.address = address;
this.balance = balance;
}
public String query() {
String result = "尊敬的客户您好!你的账号为:" + account + ",户主:" + name + ",卡中的余额为:" + minBalance;
return result;
}
public void fetchMoney(long money) {
if (balance < minBalance) {
System.out.println("尊敬的客户您好!您账号的余额不足"+ minBalance+"不能取款");
} else {
balance = balance-money;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("尊敬的客户您好!您在"+dateFormat.format(new Date())+"取款"+money+"元,账号中的余额为:"+balance+"元");
}
}
public void deposit(long money) {
balance = balance+money;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("尊敬的客户您好!您在"+dateFormat.format(new Date())+"存款"+money+"元,账号中的余额为:"+balance+"元");
}
public static void main(String[] args) {
Bank bank = new Bank("123456789","wangwenjun","Beijing",10000);
bank.query();
bank.deposit(1000);
bank.query();
bank.fetchMoney(1000);
bank.query();
bank.fetchMoney(10000);
bank.query();
bank.fetchMoney(10000);
}
}
////////////////////////////测试如下
尊敬的客户您好!您在2009-04-09 16:53:40存款1000元,账号中的余额为:11000元
尊敬的客户您好!您在2009-04-09 16:53:40取款1000元,账号中的余额为:10000元
尊敬的客户您好!您在2009-04-09 16:53:40取款10000元,账号中的余额为:0元
尊敬的客户您好!您账号的余额不足100不能取款
import java.util.Date;
public class Bank {
private String account = "";
private String name = "";
private String address = "";
private long balance = 0l;
private final long minBalance = 100l;// 最少存款应该是固定的
public Bank() {
}
public Bank(String account, String name, String address, long balance) {
this.account = account;
this.name = name;
this.address = address;
this.balance = balance;
}
public String query() {
String result = "尊敬的客户您好!你的账号为:" + account + ",户主:" + name + ",卡中的余额为:" + minBalance;
return result;
}
public void fetchMoney(long money) {
if (balance < minBalance) {
System.out.println("尊敬的客户您好!您账号的余额不足"+ minBalance+"不能取款");
} else {
balance = balance-money;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("尊敬的客户您好!您在"+dateFormat.format(new Date())+"取款"+money+"元,账号中的余额为:"+balance+"元");
}
}
public void deposit(long money) {
balance = balance+money;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("尊敬的客户您好!您在"+dateFormat.format(new Date())+"存款"+money+"元,账号中的余额为:"+balance+"元");
}
public static void main(String[] args) {
Bank bank = new Bank("123456789","wangwenjun","Beijing",10000);
bank.query();
bank.deposit(1000);
bank.query();
bank.fetchMoney(1000);
bank.query();
bank.fetchMoney(10000);
bank.query();
bank.fetchMoney(10000);
}
}
////////////////////////////测试如下
尊敬的客户您好!您在2009-04-09 16:53:40存款1000元,账号中的余额为:11000元
尊敬的客户您好!您在2009-04-09 16:53:40取款1000元,账号中的余额为:10000元
尊敬的客户您好!您在2009-04-09 16:53:40取款10000元,账号中的余额为:0元
尊敬的客户您好!您账号的余额不足100不能取款
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询