Im writing this in netbeans. Here is the code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package accounttoolssilverberg;

/**
 *
 * @author Administrator
 */
public class accountToolsSilverberg {

    double a[];
    int i;

    public accountToolsSilverberg() {

        a = new double[1000];

        for (i = 0; i < 1000; i++) {
            a[i] = Math.random() * 1000000;
        }
    }

    public double[] getArray() {
        return a;
    }



    public double myMax() {
        double max = 0;
        for (i = 0; i < 1000; i++) {
            if (max < a[i]) {
                max = a[i];

            }
        }
        return max;
    }

    public double myMin() {
        double min = 0;
        for (i = 0; i < 1000; i++) {
            if (min > a[i]) {
                min = a[i];
            }
        }
        return min;
    }
    public double myAVG(){
        double sum = 0;
        for (i = 0; i < 1000; i++){
            sum = sum + a[i];
        }
    double avg;
    avg = sum/1000;
    return avg;
    }



        }


                public class accountTooltestsilverberg {

    public static void main(String[] args) {
        accountToolsSilverberg test = new accountToolsSilverberg();
        test.getArray();
        System.out.println("Maximum account balance: $"+test.myMax());
        System.out.println("Minimum account balance: $"+test.myMin());
        System.out.println("Average account balance: $"+test.myAVG());


    }

}

It is a program getting account balances from random numbers and showing max min and average. I need to know how to make the output display in dollar amount for example: 452323.00, and not 3344312.092389.

Also, I don't think that minimum calculation for that is correct.

Im writing this in netbeans. Here is the code:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package accounttoolssilverberg;

/**
*
* @author Administrator
*/
public class accountToolsSilverberg {

double a[];
int i;

public accountToolsSilverberg() {

a = new double[1000];

for (i = 0; i < 1000; i++) {
a = Math.random() * 1000000;
}
}

public double[] getArray() {
return a;
}

public double myMax() {
double max = 0;
for (i = 0; i < 1000; i++) {
if (max < a) {
max = a;

}
}
return max;
}

public double myMin() {
double min = 0;
for (i = 0; i < 1000; i++) {
if (min > a) {
min = a;
}
}
return min;
}
public double myAVG(){
double sum = 0;
for (i = 0; i < 1000; i++){
sum = sum + a;
}
double avg;
avg = sum/1000;
return avg;
}

}


public class accountTooltestsilverberg {

public static void main(String[] args) {
accountToolsSilverberg test = new accountToolsSilverberg();
test.getArray();
System.out.println("Maximum account balance: $"+test.myMax());
System.out.println("Minimum account balance: $"+test.myMin());
System.out.println("Average account balance: $"+test.myAVG());


}

}

It is a program getting account balances from random numbers and showing max min and average. I need to know how to make the output display in dollar amount for example: 452323.00, and not 3344312.092389.

Also, I don't think that minimum calculation for that is correct.

First of all please use code tags whenever you post a code.
For getting output upto only upto places of decimal use NumberFormat class

NumberFormat formatter = new DecimalFormat("0.00");
System.out.println("Minimum account balance: $"+formatter.format(test.myMin()));

And as far as minimum calculation is concerned, I think so you should initialize min and max with a[0] instead of 0 as it might be possible all values of array might be greater than 0(in that case min wont be correct) or all values of array might be less than 0(in that case max wont be correct)

ok one last question.
Here is the code:

public double myAVG() {
        double sum = 0;
        for (i = 0; i < 1000; i++) {
            sum = sum + a[i];
        }
        double avg;
        avg = sum / 1000;
        return avg;
    }

    public void myFlagged() {
        double ninetypercentavg;
        ninetypercentavg = 90 / 100;
        for (i = 0; i < 1000; i++) {
            if (a[i] > ninetypercentavg) {
                System.out.println("Account: " + i + "\t Balance: " + a[i]);

I want to move the avg from the getAVG method down to the getFlagged method, and make ninetypercentavg = avg*90 / 100;
instead of ninetypercentavg = 90 / 100;

Either make avg public or pass it from the main method where you might be calling your function myFlagged

awesome thanks alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.