Counting

This may be a really simple question, but I cant figure it out for the life of me. at the end of the program after I ask the user to enter a value and then I print the salesmen who have sold hire than that amount. I am supposed to put a count and print it on how many did. Right now I have the list set up and the whole program works I just need some help with the count of that. Can anyone help?

// ****************************************************************

// Sales.javaAuthor: Kehr,John

//

// Reads in and stores sales for each of 5 salespeople. Displays

// sales entered by salesperson id and total sales for all salespeople.

//

// ****************************************************************

import java.util.Scanner;

publicclass Sales

{

publicstaticvoid main(String[] args)

{

int sum, average, max, min, uservalue, total, salespeople, SALESPEOPLE;

Scanner scan =new Scanner(System.in);

System.out.println("How many salespeople; ");

salespeople = scan.nextInt();

SALESPEOPLE = salespeople;

int[] sales =newint[SALESPEOPLE];

for (int i=0; i<sales.length; i++)

{

System.out.print("Enter sales for salesperson " + (i+1) +": ");

sales[i] = scan.nextInt();

}

System.out.println("\nSalespersonSales");

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

sum = 0;

max = sales[0];

min = sales[0];

for (int i=0; i><sales.length; i++)

{

System.out.println("" + (i+1) +" " + sales[i]);

sum += sales[i];

if (sales[i] > max)

{

max = sales[i];

}

if (min > sales[i])

{

min = sales[i];

}

}

System.out.println("\nTotal sales: " + sum);

average = sum/SALESPEOPLE;

System.out.println("\nAverage sales: " + average);

System.out.println("\nMaximum sale: " + max);

System.out.println("\nMinimum sale: " + min);

System.out.println("\nPlease enter a value: ");

uservalue = scan.nextInt();

total = 0;

System.out.println("These salesman have exceeded sales entered");

System.out.println("\nSalespersonSales");

for (int i=0; i<sales.length; i++)

{

if (sales[i] > uservalue)

{

System.out.println("" + (i+1) +" " + sales[i]);

}

}

}

}

[4075 byte] By [slidelljakea] at [2007-11-27 10:37:37]
# 1

Perhaps you should try to put a bit more effort in expressing yourself more clearly. It could be just me, but normally, I understand the questions posted here without much effort.

> I print the salesmen who have sold hire than

> that amount.

?

> I am supposed to put a count

?

> and print it on how many did.

?

> I just need some help with the count of that.

?

prometheuzza at 2007-7-28 18:49:20 > top of Java-index,Java Essentials,Java Programming...
# 2

create an int counter variable (I called salespersonsExceedingValue), place it above the last for loop, increase it by one (salespersonsExceedingValue++) each time a salesman exceeds the cut-off (do this within the if block inside the for loop), and you're there. Just display the results AFTER the for loop has ended.

Also, try to empty all that code clutter out of your main method. You need sub-methods in a bad way.

Message was edited by:

petes1234

petes1234a at 2007-7-28 18:49:20 > top of Java-index,Java Essentials,Java Programming...
# 3

Ok, sorry about that, reading over it again i feel like an idiot.

So the program stores and prints n number of salesmen and there gross sales

Then the program prompts the user to enter in a target sales amount.

The program then prints out the salesmen and there gross sales if they have exceeded the target sales. What Im trying to do is then to print the total number of salesmen who have exceeeded the target amount(ex. "5 salesmen have exceeded the amount)

Sorry about my first post again.

slidelljakea at 2007-7-28 18:49:20 > top of Java-index,Java Essentials,Java Programming...
# 4

> Ok, sorry about that, reading over it again i feel

> like an idiot.

Don't beat yourself up too badly. That's OUR job. Your new at java and at posting here. Both will improve.

petes1234a at 2007-7-28 18:49:20 > top of Java-index,Java Essentials,Java Programming...
# 5

> Ok, sorry about that, reading over it again i feel

> like an idiot.

> So the program stores and prints n number of salesmen

> and there gross sales

> Then the program prompts the user to enter in a

> target sales amount.

> The program then prints out the salesmen and there

> gross sales if they have exceeded the target sales.

> What Im trying to do is then to print the total

> number of salesmen who have exceeeded the target

> amount(ex. "5 salesmen have exceeded the amount)

> Sorry about my first post again.

No problem.

Ok, so your salesmen seem to be represented as an array of integers. To find out how many salesmen have sold more than a certain amount, create an int variable N to store the number of salesmen in that exceed that certain number X and simple loop over your array and compare each element from your array with X. If it's more than X, increase N with one.

prometheuzza at 2007-7-28 18:49:20 > top of Java-index,Java Essentials,Java Programming...
# 6

> No problem.

> Ok, so your salesmen seem to be represented as an

> array of integers. To find out how many salesmen have

> sold more than a certain amount, create an int

> variable N to store the number of salesmen in

> that exceed that certain number X and simple

> loop over your array and compare each element from

> your array with X. If it's more than X,

> increase N with one.

hm, that answer looks familiar to me ;)

petes1234a at 2007-7-28 18:49:20 > top of Java-index,Java Essentials,Java Programming...
# 7

> ...

> hm, that answer looks familiar to me ;)

Oi, didn't see you sneak in with reply #2!

; )

prometheuzza at 2007-7-28 18:49:21 > top of Java-index,Java Essentials,Java Programming...