迷你ATM应用程序 [英] Mini ATM application

查看:70
本文介绍了迷你ATM应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在创建一个迷你ATM应用程序,我遇到了一些问题。

1.我要求它撤销后循环

2.不携带整个计划中的newBalance

3.我需要除提款,存款和展示余额之外的额外功能



我尝试过的:



So I am creating a mini ATM application and I have a few problems with it.
1. It loops after I ask it to withdraw
2. doesnt carry newBalance throughout the program
3.I need an extra feature other than withdraw, deposit and display balance

What I have tried:

import java.util.*;
public class ATM {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input=new Scanner (System.in);
		String acctNum,password,orignalBalance="error";
		int mainMenu=0;
		int counter=3;
		double x=0;
		do
		{
			System.out.println("Enter the account number:");
			acctNum=input.next();
			System.out.println("Enter the pin:");
			password=input.next();
			orignalBalance=validation(acctNum,password);
			counter--;
			if(counter==0)
			{
				System.out.println("Maximum amount of attempts");
				break;
			}
			else if(!(orignalBalance.equals("error")))
			{
				break;
			}
		}while(orignalBalance.equals("error"));
		{
		double balance=Double.parseDouble(orignalBalance);
		mainMenu=mainMenuOption();
		while(!(mainMenu==4))
		if (mainMenu==1)
		{
			x=withdrawl(balance);
			System.out.println("Balance= $"+x);
		}
		else if (mainMenu==2)
		{
			x=deposit(balance);
			System.out.println("Balance= $"+x);
		}
	}
}

	public static double deposit(double balance) {
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);
		double deposit=0;
		double newBalance=0;
		System.out.println("How much money would you like to input?");
		deposit=input.nextDouble();
		newBalance=balance+deposit;
		return newBalance;
	}
	public static int mainMenuOption() {
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);
		int userInput=0;
		System.out.println("\nWhat would you like to do today?");
		System.out.println("1. Withdrawl");
		System.out.println("2. Deposit");
		System.out.println("3. Bank Balance");
		System.out.println("4. Recipt Bank Balance");
		System.out.println("5. Exit");
		userInput=input.nextInt();
		return userInput;
	}
	public static double withdrawl(double balance) {
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);
		double withdrawAmt=0;
		double newBalance=0;
		System.out.println("How much money would you like to withdraw today");
		withdrawAmt=input.nextDouble();
		if(withdrawAmt<balance)
		{
			newBalance=balance-withdrawAmt;
		}
		return newBalance;
	}
	public static String validation(String acctNum,String password) {
		// TODO Auto-generated method stub
		String a="123456 mypassword 54.6";
		String b="723456 anotherpassword 900.0";
		String c="823456 bestpassword 438.32";
		String result = "error";
		if (acctNum.equals(a.substring(0, a.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" "))))
            return result = a.substring(a.lastIndexOf(" ") + 1);
		if (acctNum.equals(a.substring(0, b.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" "))))
            return result = a.substring(a.lastIndexOf(" ") + 1);
		if (acctNum.equals(a.substring(0, c.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" "))))
            return result = a.substring(a.lastIndexOf(" ") + 1);
		else
		{
			System.out.println("Wrong username or password");
		}
		return result;

	}
	

}

推荐答案

+ x) ;
}
else if(mainMenu == 2)
{
x = deposit(balance);
System.out.println(Balance =
"+x); } else if (mainMenu==2) { x=deposit(balance); System.out.println("Balance=


+ x);
}
}
}

公共静态双重存款(双重余额){
// TODO自动生成方法stub
扫描器输入=新扫描器(System.in);
double deposit = 0;
double newBalance = 0;
System.out.println(你要输入多少钱?);
deposit = input.nextDouble();
newBalance =余额+存款;
返回newBalance;
}
public static int mainMenuOption(){
// TODO自动生成的方法stub
扫描器输入= new Scanner(System.in);
int userInput = 0;
System.out .println(\\\
你今天想做什么?);
System.out.println(1。Withdrawl);
System.out.println(2。存款) ;
System.out.println(3.银行余额);
的System.out.println(4。 Recipt Bank Balance);
System.out.println(5. Exit);
userInput = input.nextInt();
return userInput;
}
public static double withdrawl(double balance){
// TODO自动生成的方法stub
扫描器输入= new Scanner(System.in);
double withdrawAmt = 0;
double newBalance = 0;
System.out.println(你想今天要提取多少钱);
withdrawAmt = input.nextDouble();
if(withdrawAmt< balance)
{
newBalance = balance-withdrawAmt;
}
返回newBalance;
}
public static字符串验证(String acctNum,String password){
// TODO自动生成的方法stub
String a =123456 mypassword 54.6;
String b =723456 anotherpassword 900.0;
String c =823456 bestpassword 438.32;
String result =error;
if(acctNum.equals(a.substring(0,a.indexOf()))&& password.equals(a.substring(a.indexOf) ()+ 1,a.lastIndexOf())))
return result = a.substring(a.lastIndexOf()+ 1);
如果(acctNum.equals(a.substring(0,b.indexOf( )))及;&安培; password.equals(a.substring(a.indexOf()+ 1,a.lastIndexOf ())))
返回结果= a.substring(a.lastIndexOf()+ 1);
if(acctNum.equals(a.substring(0,c.indexOf()))&& password.equals(a.substring(a.indexOf()+ 1,a.lastIndexOf ())))
返回结果= a.substring(a.lastIndexOf()+ 1);
else
{
System.out.println(用户名或密码错误);
}
返回结果;

}


}
"+x); } } } public static double deposit(double balance) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); double deposit=0; double newBalance=0; System.out.println("How much money would you like to input?"); deposit=input.nextDouble(); newBalance=balance+deposit; return newBalance; } public static int mainMenuOption() { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int userInput=0; System.out.println("\nWhat would you like to do today?"); System.out.println("1. Withdrawl"); System.out.println("2. Deposit"); System.out.println("3. Bank Balance"); System.out.println("4. Recipt Bank Balance"); System.out.println("5. Exit"); userInput=input.nextInt(); return userInput; } public static double withdrawl(double balance) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); double withdrawAmt=0; double newBalance=0; System.out.println("How much money would you like to withdraw today"); withdrawAmt=input.nextDouble(); if(withdrawAmt<balance) { newBalance=balance-withdrawAmt; } return newBalance; } public static String validation(String acctNum,String password) { // TODO Auto-generated method stub String a="123456 mypassword 54.6"; String b="723456 anotherpassword 900.0"; String c="823456 bestpassword 438.32"; String result = "error"; if (acctNum.equals(a.substring(0, a.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" ")))) return result = a.substring(a.lastIndexOf(" ") + 1); if (acctNum.equals(a.substring(0, b.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" ")))) return result = a.substring(a.lastIndexOf(" ") + 1); if (acctNum.equals(a.substring(0, c.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" ")))) return result = a.substring(a.lastIndexOf(" ") + 1); else { System.out.println("Wrong username or password"); } return result; } }


1。它在我要求它撤回后循环

看起来好像你没有回到主菜单。如果你存款,它可能会做同样的事情。



2。在整个程序中不携带 newBalance

您在哪里将方法结果转移到余额?
1. It loops after I ask it to withdraw
Doesn't look like you ever return to the main menu. It will probably do the same thing if you do a deposit.

2. doesnt carry newBalance throughout the program
Where are you transferring the method results to the balance?
double x=0;
double balance=Double.parseDouble(orignalBalance);
// snipped for brevity
mainMenu=mainMenuOption();
while(!(mainMenu==4))
{  if (mainMenu==1)
   {
      x=withdrawl(balance);
      System.out.println("Balance=


这篇关于迷你ATM应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆