Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[ Assignment3_yourlastname.cs ] Create a program that includes the following req

ID: 3532096 • Letter: #

Question

[Assignment3_yourlastname.cs]  Create a program that includes the following requirements:

1.    Create an accounts class  

2.    Private class members for:

1.    an array of 5 account numbers

2.    an array of 5 account balances (currency)

3.    an array of 5 account names (last name)

3.    Public class methods:

1.    a method to fill all three parallel arrays by keyboard inputs

2.    a method to search the account number array and display

1.    when found, the account number entered at the keyboard along with the corresponding balance and last name

2.    if nothing is found for the account number entered display

Explanation / Answer

import java.io.Console;

import java.util.Scanner;



public class Accounts

{

private int accountNumbers[];

private double balance[];

private String lastNames[];


public void fillAccounts()

{

accountNumbers=new int[5];

balance=new double[5];


lastNames=new String[5];

Scanner inI=new Scanner(System.in);

Scanner inS=new Scanner(System.in);

Scanner inD=new Scanner(System.in);


for(int i=0;i<5;i++)

{

System.out.print("Enter the integer account number ");

accountNumbers[i]=inI.nextInt();

System.out.print("Enter the account balance ");

balance[i]=inD.nextDouble();


System.out.print("Enter the account holder last name ");

lastNames[i]=inS.nextLine();


}

System.out.println();


}


public void searchAccounts(int account)

{


for(int i=0;i<5;i++)

if(accountNumbers[i]==account)

System.out.println("Account # "+accountNumbers[i]+ " has a balance of "+balance[i]+" for customer "+lastNames[i]);


System.out.println("account not found");

}

public void averageAccounts()

{

double average=0.0;

for(int i=0;i<5;i++)

average=average+balance[i];


System.out.println("The average dollar amount for the accounts is: $"+average/5);


}


public static void main(String args[])

{ char choice;

Scanner in=new Scanner(System.in);

Scanner in1=new Scanner(System.in);

String ch;

Accounts obj=new Accounts();

try

{

obj.fillAccounts();


do

{

System.out.println("*****************************************");

System.out.println("enter an a or A to search account numbers");

System.out.println("enter a b or B to average the accounts");

System.out.println("enter an x or X to exit program");

System.out.println("*****************************************");

System.out.print("Enter an option->>");


ch=in.nextLine();


if(ch.equalsIgnoreCase("a"))

{

System.out.println("Enter an account number to search for: ");

int account=in1.nextInt();


obj.searchAccounts(account);

}

else if(ch.equalsIgnoreCase("b"))

{

obj.averageAccounts();

}

else

{

System.out.println("you entered an incorrect option");

}

}while(!ch.equalsIgnoreCase("x"));

}catch(Exception ex)

{

System.out.println("some error has occured either due to wrong input or some internal bugs");

}

}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote