1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2013
Posts
1
Rep Power
0

#### Help with question

Hi everyone I'm new here, and if I do something out of line please let me know. I am a QA software tester and am trying to help the wife who is not a fluent English speaker yet. I am not a developer and am not able to help and her communications with the professor have been difficult.

Here is the assignment:

1. Modify the Account class to include both balance and accountID as the instance variables. Add necessary methods.

2. Write a Bank class with main method. In the main method, ask the user to input how many accounts (say numOfAccount) to be generated in the bank. Then create an array to hold these numOfAccount of Account objects. For each Account object, generate a random balance in the range of 0.0-1000.0 and generate a random 4 digits accountID.

3. Assume that your GSU campus ID is abc-de-fghi and an integer m is set as: m = numOfAccount /2. For the m(th) account in the array, set its balance to be abcde/100.0 (i.e., your first 5 digits of your campus ID divided by 100.0) and set its accountID to be fghi (the last four digits of your campus ID).

4. Find the average account balance of all the accounts in the array and print it out.

5. Find the account with the largest balance, print out its accountID and balance.

6. Find the account with the lowest balance, print out its accountID and balance.
==========================

Number 3 is where she is having problems. I will post the code that she has done

//Account.java

Code:
```public class Account {

// Instance variables
private double balance;
private String accountID;

// Constructors
public Account(double initialBalance) {
balance = initialBalance;
}

public Account() {
balance = 0.0;
}

public Account(String ID, double initialBalance){
accountID = ID;
balance = initialBalance;
}

// Instance methods

public String getID() {
return accountID;
}

public void deposit(double amount) {
balance += amount;
}

public void withdraw(double amount) {
balance -= amount;
}

public double getBalance() {
return balance;
}

public void close() {
balance = 0.0;
}

// Find The largest Balance

public double getLargestBalance(int[] accountID, double[] balance)  {
double largestBalance;
largestBalance = balance[0];
for (int b=0; b < balance.length; b++){
if (balance[b] > largestBalance)
largestBalance = balance[b];
}
return largestBalance;
}

// Find The Lowest Balance

public double getLowestBalance(int[] accountID, double[] balance)  {
double lowestBalance;
lowestBalance = balance[0];
for (int b=0; b < balance.length; b++){
if (balance[b] < lowestBalance)
lowestBalance = balance[b];
}
return lowestBalance;
}

// Find average balance

public double getAverageBalance (double[] balance){
double averageBalance = 0;
double sum = 0;
for ( int c = 0; c < balance.length;) {
sum = sum + balance[c];
averageBalance = sum/(c+1);
}
return averageBalance;
}
}```

//Bank.java

Code:
```import java.util.Random;
import java.util.Scanner;

public class Bank {

public static void main(String[] args) {

System.out.print("Enter number of accounts to generate:");
Scanner userInput = new Scanner (System.in);
int numOfAccount = userInput.nextInt();

//Create an array to hold the number of accounts of Account objects

Account[] numAccount = new Account[numOfAccount];

//generate random 4 digits accountID

Random generator = new Random();
int accountID = 1 + generator.nextInt(9999);

// Generate random balance between 0.0 - 1000.0
double balance = Math.abs(generator.nextDouble()) % 100000 / 100f;

}
}```

She says she understands that m = numOfAccount /2 but has no idea about how to set the balance "for the m th account.."

3. Assume that your GSU campus ID is abc-de-fghi and an integer m is set as: m = numOfAccount /2. For the m(th) account in the array, set its balance to be abcde/100.0 (i.e., your first 5 digits of your campus ID divided by 100.0) and set its accountID to be fghi (the last four digits of your campus ID).

Thanks very much for any input.
2. Please edit the post and wrap the code in code tags:
[code]
THE CODE HERE
[/code]