Need Help
My program is working except for one part. I have to modify my program a little. Instead of reading in sales amounts, I have to ask the user for the number of sales people and then create an array that is just the right size. I have enter the number of sales but can't figure out the next part with the array. Can somebody help me. Thanks
publicclass Sales
{
publicstaticvoid main(String[] args)
{
int[] sales =newint[SALESPEOPLE];
int sum = 0;
int avg = 0;
int max = 0;
int min = 0;
int position = 0;
int position2 = 0;
int exceeds = 0;
int greater = 0;
int number = 0;
Scanner scan =new Scanner(System.in);
System.out.println("Enter the number of sales people: ");
number = scan.nextInt();
for (int i = 0; i < sales.length; i++)
{
System.out.print("Enter sales for salesperson " + (i + 1) +": ");
sales[i] = scan.nextInt();
}
min = sales[0];
max = sales[0];
System.out.println("\nSalespersonSales");
System.out.println("--");
sum = 0;
for (int i = 0; i < sales.length; i++)
{
System.out.println("" + i +"" + sales[i]);
//sum = total
sum += sales[i];
//find the max
if (sales[i] < min)
{
min = sales[i];
position = i;
}
//find the min
if (sales[i] > max)
{
max = sales[i];
position2 = i;
}
}
//find avg, min, max, and total
System.out.println();
avg = sum / sales.length;
System.out.println("The average sale " + avg);
System.out.println("The salesperson id with the lowest amount is: " + position +" the amount " + min);
System.out.println("The salesperson id with the highest amount is: " + position2 +" the amount " + max);
System.out.println("\nTotal sales: " + sum);
System.out.println();
System.out.println("Please enter a value");
exceeds = scan.nextInt();
for (int i = 0; i< sales.length; i++)
{
if (exceeds < sales[i])
{
greater++;
System.out.println("Salesperson is " + i +" amount is " + sales[i]);
}
}
System.out.println("Total salespeople who exceeded amount is " + greater);
}
[4151 byte] By [
tmlucky13a] at [2007-11-27 2:24:44]

> My program is working except for one part. I have to
> modify my program a little. Instead of reading in
> sales amounts, I have to ask the user for the number
> of sales people and then create an array that is just
> the right size. I have enter the number of sales but
> can't figure out the next part with the array. Can
> somebody help me. Thanks
>
>
> > public class Sales
> {
>public static void main(String[] args)
> {
> int[] sales = new int[SALESPEOPLE];
> int sum = 0;
> int avg = 0;
> int max = 0;
> int min = 0;
> int position = 0;
> int position2 = 0;
> int exceeds = 0;
> int greater = 0;
> int number = 0;
>
> Scanner scan = new Scanner(System.in);
>
> System.out.println("Enter the number of sales
> es people: ");
> number = scan.nextInt();
>
> for (int i = 0; i < sales.length; i++)
> {
> System.out.print("Enter sales for salesperson " +
> " + (i + 1) + ": ");
> sales[i] = scan.nextInt();
> }
> min = sales[0];
> max = sales[0];
>
> System.out.println("\nSalespersonSales");
> System.out.println("--");
> sum = 0;
>
> for (int i = 0; i < sales.length; i++)
> {
> System.out.println("" + i + "" +
> " + sales[i]);
>
> //sum = total
> sum += sales[i];
>
> //find the max
> if (sales[i] < min)
> {
> min = sales[i];
> position = i;
> }
>
> //find the min
> if (sales[i] > max)
> {
> max = sales[i];
> position2 = i;
> }
> }
> //find avg, min, max, and total
> System.out.println();
> avg = sum / sales.length;
> System.out.println("The average sale " + avg);
> System.out.println("The salesperson id with the
> the lowest amount is: " + position + " the amount " +
> min);
> System.out.println("The salesperson id with the
> the highest amount is: " + position2 + " the amount "
> + max);
> System.out.println("\nTotal sales: " + sum);
>System.out.println();
>
>System.out.println("Please enter a value");
> exceeds = scan.nextInt();
>
> for (int i = 0; i< sales.length; i++)
> {
>
> if (exceeds < sales[i])
> {
> greater++;
> System.out.println("Salesperson is " + i + "
> + " amount is " + sales[i]);
> }
>
> }
> System.out.println("Total salespeople who exceeded
> ded amount is " + greater);
>
>}
> de]
use something like this...
[code]System.out.println("Enter the number of sales people: ");
int number_people = // = input from user
int[] intnumber = new int[number_people];
~Kaeloc