I need to do an assignment with the question requirement as follow.
-The system to maintain a list up to 20 accounts. Each account has a unique account number and account balance.
-Need to perform the following tasks repeatedly until he quits.(add account, search account and display account).
Your program should include the following:
-Two arrays, one to store the account number and the other to store the account balance.
-The method displayMenu() to display the following menu:
Menu
1. Add an account
2. Search an account with the given account number
3. Display accounts below the given balance
0. Exit
- The method addAccount() to add an account to the system. This method should receive
as the parameters the two arrays mentioned above and an integer number that keeps track
of the number of accounts so far. It prompts and reads the account number and account
balance from the user and adds it to the system. The method should return the total
number of accounts. You are required to ensure that the number of accounts in the system
is less than 20 before prompting for input. You are also required to ensure that the
account number is unique (note: you may use the search() method written below for
the validation).
- The method search() to search for an account with the account number entered by the
user. The method should return the index of the account in the array if it is found, or -1 if
it is not found.
- The method displayAccounts() to display all the accounts that has the balance
below the amount entered by the user.
- The main() method that calls the desired method to perform the task according to the
user's selection. You are required to use switch statement here.
This is my code until so far. i am stuck till the add account.
Really appreciate if any pro out there can help me with this.
import java.util.*;
public class Qn3{
public static void main(String[]args){
Scanner scn = new Scanner(System.in);
int [] accNum = new int[20];
double [] accBal = new double[20];
new Qn3();
switch ( scn.nextInt() ) {
case 1:
System.out.println ( "You picked option 1" );
addAccount(accNum);
case 2:
System.out.println ( "You picked option 2" );
break;
case 3:
System.out.println ( "You picked option 3" );
break;
default:
System.err.println ( "Unrecognized option" );
break;
}
}
public void displayMenu(){
System.out.println("Menu");
System.out.println("1. Add an account");
System.out.println("2. Search an account with the given account number");
System.out.println("3. Display accounts below the given balance");
System.out.println("0. Exit");
}
public static void addAccount(int[] accNum, double [] accBal){
Scanner scn = new Scanner(System.in);
for (int n=0; n<accNum.length; n++)
{
if(accNum[n] == 0){
System.out.print("Enter account Number " + (n+1) + ": ");
accNum[n] = scn.nextInt();
}
}
}
public Qn3(){
displayMenu();
}
}