重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
package demo;
目前创新互联已为近千家的企业提供了网站建设、域名、网页空间、网站托管、企业网站设计、泾川网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
import java.util.Scanner;
public class Test3 {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
int cnt=3;
String username = null;
String password = null;
double money = 1000;
String targetName = "admin33";
double targetMoney = 1000;
while(true){
if(username!=nullpassword!=null){
if("admin".equals(username) "123".equals(password)){
System.out.println("欢迎光临");
while(true){
System.out.println("请选择您的操作 1 取钱 2 存钱 3 转账 4 查询 5 退出 ");
int n = scanner.nextInt();
if(n==1){//取钱
System.out.println("请输入金额");
int getter = scanner.nextInt();
if(getter=0){
if(getter=5000){
if(getter=money){
money-=getter;
}else{
System.out.println("余额不足");
}
}else{
System.out.println("单笔只能取5000及以下");
}
}else{
System.out.println("银行不到给");
}
}else if(n==2){//存钱
System.out.println("请输入金额");
int save = scanner.nextInt();
if(save=0){
money+=save;
}
}else if(n==3){//转账
System.out.println("请输入目标账户");
String target = scanner.next();
if(target.equals(targetName)){
System.out.println("请输入金额");
int getter = scanner.nextInt();
if(getter=0){
if(getter=5000){
if(getter=money){
money-=getter;
targetMoney+=getter;
}else{
System.out.println("余额不足");
}
}else{
System.out.println("单笔只能取5000及以下");
}
}else{
System.out.println("银行不到给");
}
}
}else if(n==4){//查询
System.out.println(money);
}else if(n==5){//退出
System.exit(0);
}else{
System.out.println("没有该项服务");
}
}
}else{
cnt--;
System.out.println("输入错误,您还有"+cnt+"次机会");
username=null;
password=null;
if(cnt=0){
System.out.println("对不起,您的账号被冻结,请到最近的营业厅解除冻结");
System.exit(0);
}
}
}else{
System.out.println("请输入您的账号");
username = scanner.next();
System.out.println("请输入您的密码");
password = scanner.next();
}
}
}
}
import java.util.*;
public class ATM {
static int people=123456;
static int mima=123456;
static int yue=10000;
static Scanner in=null;
public ATM(int people,int mima){
this.mima=mima;
}
public static void main(String[] args) {
chongxindenglu();
int count=1;
while(count!=0){
System.out.println("1、查询余额");
System.out.println("2、取款");
System.out.println("3、存款");
System.out.println("4、修改密码");
System.out.println("5、重新登录");
count=in.nextInt();
switch(count){
case 1: System.out.println(10000); System.out.println(); break;
case 2: quKuan(); break;
case 3: cunKuan(); break;
case 4: xiugai(); break;
case 5: chongxindenglu();
}
}
}
public static void quKuan(){
System.out.println("请输入取款金额:");
int qukuanjine=in.nextInt();
if(qukuanjine5000){
System.out.println("取款金额不能大于5000"+"\n");
}else{
if(qukuanjine%100!=0){
System.out.println("取款金额必须为100的整数倍"+"\n");
}else{
yue=yue-qukuanjine;
System.out.println("您取出了"+qukuanjine+"元,您现在的余额为:"+yue+"元"+"\n");
}
}
}
public static void cunKuan(){
System.out.println("请输入存款金额");
int cunkuanjine=in.nextInt();
if(cunkuanjine0){
System.out.println("存款金额不能小于0");
}else{
yue=yue+cunkuanjine;
System.out.println("您已成功存入:"+cunkuanjine+"元,您现在总余额为:"+yue+"元"+"\n");
}
}
public static void xiugai(){
System.out.println("请输入您的密码:");
int mima1=in.nextInt();
if(mima1==mima){
System.out.println("请输入新密码:");
mima=in.nextInt();
System.out.println("您的密码已修改为:"+mima+"\n");
}else{
System.out.println("密码输入错误:"+"\n");
}
}
public static void chongxindenglu(){
in=new Scanner(System.in);
System.out.println("请输入登录帐号:");
int denglupeople=in.nextInt();
System.out.println("请输入登录密码:");
int denglumima=in.nextInt();
if(denglupeople==people denglumima==mima)
System.out.println("帐号登录成功"+"\n");
else
System.out.println("密码输入错误,登录失败"+"\n");
}
}
参考了别人的代码。略作修改,已经很简单了:
InfoATM.java:
public class InfoATM {
double money = 0;
public InfoATM(double cash) {
super();
this.money = cash;
}
// 存款的方法
public void save(double count) {
money += count;
}
// 取款的方法
public void draw(double count) {
money -= count;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
TestATM.java:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class TestATM extends JFrame {
private static final long serialVersionUID = 2531222181184935595L;
// 主面板pnBasic是用来装pnDate和标签文字的。
private JPanel pnBasic;
// 添加到主面板中的中间 pnDate面板是为了装表单的。
private JPanel pnDate;
// 添加到主面板中的北边 pnLabel面板是为了装欢迎词的
private JPanel pnLabel;
InfoATM atm = new InfoATM(0);
public TestATM() {
pnBasic = new JPanel();
// 主面板pnBasic是用来装pnDate和标签文字的。
pnDate = new JPanel(new GridLayout(2, 2));
// pnDate面板是为了装表单的。
pnLabel = new JPanel();
JLabel top = new JLabel("欢迎来到中国银行!");
pnLabel.add(top);
// 先将数值添加在一个容器中并设置其在容器的右边,在将容器添加在网格的第一格
JPanel jp1 = new JPanel();
JLabel number = new JLabel("数值:");
final JTextField box = new JTextField(5);
jp1.add(number);
jp1.add(box);
JPanel jp2 = new JPanel();
JButton create = new JButton("新建银行账户");
jp2.add(create);
JButton take = new JButton("取款");
JButton in = new JButton("存款");
pnDate.add(jp1);
pnDate.add(jp2);
pnDate.add(take);
pnDate.add(in);
// 加一句下面的就好了
JPanel jpS = new JPanel();
final JLabel total = new JLabel("您现在的账户余额是:0 元");
jpS.add(total);
pnBasic.setLayout(new BorderLayout());
pnBasic.add(pnLabel, BorderLayout.NORTH);
pnBasic.add(pnDate, BorderLayout.CENTER);
pnBasic.add(jpS, BorderLayout.SOUTH);
setContentPane(pnBasic);
setBounds(400, 250, 500, 500);
pack();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
pack();
in.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (box.getText() != null box.getText() != "") {
try {
double count = Double.parseDouble(box.getText());
if (count 0) {
atm.save(count);
total.setText("您现在的账户余额是:" + atm.getMoney() + "元");
box.setText("");
}
} catch (Exception e1) {
System.out.println("您输入的数值必须是数字");
}
}
}
});
take.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (box.getText() != null box.getText() != "") {
try {
double count = Double.parseDouble(box.getText());
if (count = 0 count = atm.getMoney()) {
atm.draw(count);
total.setText("您现在的账户余额是:" + atm.getMoney() + "元");
box.setText("");
} else {
System.out.println("你的余额不足,取款失败");
}
} catch (Exception e1) {
System.out.println("您输入的数值必须是数字");
}
}
}
});
create.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
total.setText("您现在的账户余额是:0元");
atm.setMoney(0);
box.setText("");
}
});
}
public static void main(String[] args) {
new TestATM();
}
}
/** * @author admin * 该程序的功能为实现模拟银行ATM自动取款机提款,查询等功能. */ import Java.io.*; /*该类为实现客户信息及部分功能*/ class Account { private String code =null; //信用卡号 private String name =null; //客户姓名 private String password=null; //客户密码 private double money =0.0; //卡里金额 public Account(String code,String name,String password,double money) { this.code=code; this.name=name; this.password=password; this.money=money; } protected String get_Code() { return code; } protected String get_Name() { return name; } protected String get_Password() { return password; } public double get_Money() { return money; } /*得到剩余的钱的数目*/ protected void set_Balance(double mon) { money -= mon; } } /**********实现具体取款机功能*********/ class ATM { Account act; // private String name; // private String pwd; public ATM() { act=new Account("000000","Devil","123456",50000); } /***********欢迎界面***********/ protected void Welcome() { String str="---------------------------------"; System.out.print(str "\n" "欢迎使用Angel模拟自动取款机程序.\n" str "\n"); System.out.print(" 1.取款." "\n" " 2.查询信息." "\n" " 3.密码设置." "\n" " 4.退出系统." "\n"); } /**********登陆系统**********/ protected void Load_Sys() throws Exception { String card,pwd; int counter=0; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); do { System.out.println("请输入您的信用卡号:"); card=br.readLine(); System.out.println("请输入您的密码:"); pwd=br.readLine(); if(!isRight(card,pwd)) { System.out.println("您的卡号或密码输入有误."); counter ; } else SysOpter(); }while(counter3); Lock_Sys(); } 回复获取全部