Java help plz.....

Ruffian998

Member
Feb 9, 2005
25
0
0
Basically i need to creat a SalesPerson array the size of 20. It will read data from a txt file which follows this format (Name followed by sales on the next line). Once the program reads the line, it will see if it has any information for that salesperson in the record array and if not, it will create a new entry for that salesperson. And im going to have commission calculated like this:

0% commission on sales <= $1000.00
5% commission on sales > $1000.00 and <= $2500.00
10% commission on sales > $2500.00

And it will add this new commission to this salespersons sales and commissions.

Ex: On sales of $5000.00 the commission would be
(0% of first $1000) + (5% of $1500) + (10% of (sales -2500))

----------
This is Basically what I have so far and I dont know if its right
----------

class SalesMan
{
String name;
int total Sales;
int totalCommission;
int NumOfSales;


SalesMan[] records = new SalesMan[20];
int NumOfSalesMan = 0;

----

I wanna say that I repeat that last thing for total sales and totalcommission as well??? I'm not sure, I'm having a major brain fart right now as i have gone 18 hrs on 2 hrs of sleep now and i can barely hold my eyes open let alone think. Any help would be great. Hopefully it will hit me when i get a good nights sleep. Thanks in advacne.....
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
You're on the right track. I would set up something like this.

public class Salesman{
...private String name;
...private int totalSales;
...private int totalCommission; // you can probably leave this out, since commission can be calculated at the time you call getCommission()
...private int numOfSales;

...public String getName(){};
...public void setName(){};
...public int gettotalSales(){};
...public void addSale(int saleAmount){};
...public int getCommission(){};
}

Set up a main class that creates your array of SalesMan objects and reads the text file. For each line in the text file, search your SalesMan array for a matching name and either create a SalesMan object and add it to the array or use an existing SalesMan object. Add the sale amount to the object and move to the next line. When you're finished looping through the file, you can call getCommission().
 

SinNisTeR

Diamond Member
Jan 3, 2001
3,570
0
0
do you know file io?
Are you storing all the sales people into an array of SalesMan? ie. ArrayList<SalesMan>
how will the txt file be organized? any delimiters?
read in from file, using a scanner perhaps?