Background
The close reasons have recently been changed, this includes the removal of the old close reason:
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work
This was the close reason used for requirement dumps amongst other things. Within the comments of that answer it was suggested that a subset of those questions could still be closed under "unclear what you're asking" if they were not phrased as a question, but not if they were just requirements.
Question
What would be the requirements for a question to be considered as a true question, rather than a list of requirements. Are (relatively small) pure requirement questions, with an explicit question as to how to achieve those requirements on topic. For example would the following question now be on topic (assume for the purposes of this question that it would not be a duplicate).
I'm looking to create a program to replicate bank account management. How would I write a program in which it was possible to hold several accounts, each with an account number and balance, where I can debit, credit and check the balance on each account through keyboard input?
The program that I'm thinking of would work in the following way
- You would type in the account number of the account you want to manage
- Once you were managing an account you would be given the options to debit or credit the account or print balance
- After choosing the option the program would do that then return to the main menu
- Each account would be an object and would be held in an arraylist
How would I achieve that?
tags: [java][class][arraylist][ObjectOriented]
And the typical answer that people are looking for with this question would be something like the following (relatively short) program:
public class Main {
static ArrayList<BankAccount> listOfAccounts=new ArrayList<BankAccount>();
static String[] mainOptionList={"1) Create New Account","2) Access account", "3) Exit"};
static String[] accessOptionList={"1) PrintBalance","2) Debit account","3) Credit account", "4)Exit" };
public static void main(String args[]){
boolean mainExit=false;
Scanner scan=new Scanner(System.in);
while(!mainExit){
for(String option:mainOptionList){
System.out.println(option);
}
int reply=scan.nextInt(); //consider scan.hasNextInt to protect against non integer input
switch (reply){
case 1:
System.out.println("Enter account number");
int newAcNo=scan.nextInt(); //consider scan.hasNextInt to protect against non integer input
listOfAccounts.add(new BankAccount(newAcNo,0));
break;
case 2:
boolean innerExit=false;
BankAccount managedAccount=null;
while(managedAccount==null){
System.out.println("Enter account number");
int oldAcNo=scan.nextInt();
for(BankAccount bankAccount:listOfAccounts){
if (bankAccount.isAcNo(oldAcNo)){
managedAccount=bankAccount;
}
}
}
while (!innerExit){
for(String option:accessOptionList){
System.out.println(option);
}
int accessReply=scan.nextInt();
switch(accessReply){
case 1:
System.out.println(managedAccount.getBalance());
break;
case 2:
System.out.println("Enter amount to debit");
int debit=scan.nextInt();
managedAccount.debit(debit);
break;
case 3:
System.out.println("Enter amount to debit");
int credit=scan.nextInt();
managedAccount.credit(credit);
break;
case 4:
default:
innerExit=true;
}
}
break;
case 3:
default:
mainExit=true;
}
}
}
}
public class BankAccount {
int accountNumber;
int balanceInPence;
public BankAccount(int accountNumber, int balanceInPence) {
this.accountNumber = accountNumber;
this.balanceInPence = balanceInPence;
}
public void credit(int creditInPence){
balanceInPence+=creditInPence;
}
public void debit(int creditInPence){
balanceInPence-=creditInPence;
}
public String getBalance(){
return balanceInPence/100 + "£" + balanceInPence%100;
}
boolean isAcNo(int testAcNo) {
return testAcNo==accountNumber;
}
}
That program seems quite a lot smaller than some answers that I would consider not too broad