Design a software system that simulates a real world system
Solution
public class AtmMachine {
Scanner input;
int[] validId;
Atm createOne;
// AtmMachine constructor
AtmMachine() {
input = new Scanner(System.in);
createOne=new Atm();
validId = new int[10];
}
void performOperations() {
int choice;
double withdraw,balance;
for(int i=0; i<validId.length; i++){
//Prompt user to enter the identification number(ID)
System.out.print(\"Enter an id: \");
validId[i]=createOne.setId(input.nextInt());
//Prompt user to enter the correct identification number(ID)
while((validId[i]<0)||(validId[i]>9)){
System.out.println(\"\ Invalid id! Please enter your id again.\");
System.out.print(\"\ Enter an id: \");
validId[i]=createOne.setId(input.nextInt());
}
while(true){
displayMenu();
//Prompt user to enter the choice
System.out.print(\"Enter a choice: \");
choice=createOne.setChoice(input.nextInt());
balance=createOne.getBalance();
//Display the choice results
switch(choice){
case 1:System.out.println(\"\ The balance is \"+balance);
break;
case 2:System.out.print(\"\ Enter an amount to withdraw: \");
withdraw=createOne.setWithdraw(input.nextDouble());
if(createOne.setBalance(balance)>=withdraw){
createOne.getWithdraw();
}
else{
System.out.println(\"\ Not enough balance. Balance is \"+createOne.setBalance(balance));
}
break;
case 3:System.out.print(\"\ Enter an amount to deposit: \");
double deposit=createOne.setDeposit(input.nextDouble());
createOne.getDeposit();
break;
case 4:System.out.print(\"\ Enter an id: \");
validId[i]=createOne.setId(input.nextInt());
while(validId[i]<0||validId[i]>9){
System.out.println(\"\ Invalid id! Please enter your id again.\");
System.out.print(\"\ Enter an id: \");
validId[i]=createOne.setId(input.nextInt());
}
break;
case 5: return;
default:System.out.println(\"\ Invalid selection. Please select your choice again.\");
}
}
}
}
private void displayMenu() {
//Display the main menu
System.out.println(\"\ \ Main menu\ \");
System.out.println(\" 1:check balance\ \");
System.out.println(\" 2:withdraw\ \");
System.out.println(\" 3:deposit\ \");
System.out.println(\" 4:exit\ \");
System.out.println(\" 5:logout\ \");
}
/**This program is created to simulate an ATM Machine.
main method*/
public static void main(String[] args) {
AtmMachine am = new AtmMachine(); // line 1
am.performOperations(); // line 2
} // <---- that\'s it !!!
}


