- Feb 9, 2005
- 25
- 0
- 0
Ok I posted this a few days ago. Here is what I need the program to do. 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 what I have: First part of the program (there are two):
class Salesman
{
public class Salesman()
{
String name;
double Sale;
int numOfSales;
int totalSales;
int Commission;
}
}
OK now second program:
import java.io.*;
class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader inFile;
PrintWriter outFile;
inFile = new BufferedReader(new FileReader("newsales.txt"));
outFile = new PrintWriter(new FileWriter("newsales.txt"));
int numOfSalesman = 0;
Salesman[] records = new Salesman[20];
String name=inFile.readLine();
While (name!=null);
{
for(int i = 0;i <= numOfSalesman;i++)
{
if(name.equals(records.name))
{
double Sale = Double.parseDouble(inFile.readLine());
//Find Commission
if (Sale > 1000.00 && <= 2500.00)
{
int Commission = Sale*0.05;
}
else if (Sale > 2500.00 && < 5000.00)
{
int Commission = Sale*0.10;
}
else if (Sale > 5000.00)
{
int Commission = (1500*0.05) + (Sale-2500)*0.10;
}
}
else
{
numOfSalesman++;
double Sale = Double.parseDouble(inFile.readLine());
//Find Commission
if (Sale > 1000.00 && <= 2500.00)
{
int Commission = Sale*0.05;
}
else if (Sale > 2500.00 && < 5000.00)
{
int Commission = Sale*0.10;
}
else if (Sale > 5000.00)
{
int Commission = (1500*0.05) + (Sale-2500)*0.10;
}
//Create new salesman
Salesman = new Salesman(name, Sale, Commission);
}
}
}
}
}
I can give you the data file you need it. The salespeople are colors. We used colors instead of names for some reason...irrelevant. Anyways, I have it sort the names and it will go through the data file and read it. While going through the data file, if it finds the same name twice, I need it to store the amount of money it made. So say first time its see yellow made 500, and then second time it sees it made 1000, I need it to add the two together for 1500. Also, I need it to print out all this information. All help is greatly aprreciated. And for some reason, I keep getting
Also, does anyone see any problems with my Salesman program because I keep getting errors in it, its says im missing the { and the }. Also if you notice any errors in the other please point them out.
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 what I have: First part of the program (there are two):
class Salesman
{
public class Salesman()
{
String name;
double Sale;
int numOfSales;
int totalSales;
int Commission;
}
}
OK now second program:
import java.io.*;
class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader inFile;
PrintWriter outFile;
inFile = new BufferedReader(new FileReader("newsales.txt"));
outFile = new PrintWriter(new FileWriter("newsales.txt"));
int numOfSalesman = 0;
Salesman[] records = new Salesman[20];
String name=inFile.readLine();
While (name!=null);
{
for(int i = 0;i <= numOfSalesman;i++)
{
if(name.equals(records.name))
{
double Sale = Double.parseDouble(inFile.readLine());
//Find Commission
if (Sale > 1000.00 && <= 2500.00)
{
int Commission = Sale*0.05;
}
else if (Sale > 2500.00 && < 5000.00)
{
int Commission = Sale*0.10;
}
else if (Sale > 5000.00)
{
int Commission = (1500*0.05) + (Sale-2500)*0.10;
}
}
else
{
numOfSalesman++;
double Sale = Double.parseDouble(inFile.readLine());
//Find Commission
if (Sale > 1000.00 && <= 2500.00)
{
int Commission = Sale*0.05;
}
else if (Sale > 2500.00 && < 5000.00)
{
int Commission = Sale*0.10;
}
else if (Sale > 5000.00)
{
int Commission = (1500*0.05) + (Sale-2500)*0.10;
}
//Create new salesman
Salesman = new Salesman(name, Sale, Commission);
}
}
}
}
}
I can give you the data file you need it. The salespeople are colors. We used colors instead of names for some reason...irrelevant. Anyways, I have it sort the names and it will go through the data file and read it. While going through the data file, if it finds the same name twice, I need it to store the amount of money it made. So say first time its see yellow made 500, and then second time it sees it made 1000, I need it to add the two together for 1500. Also, I need it to print out all this information. All help is greatly aprreciated. And for some reason, I keep getting
Also, does anyone see any problems with my Salesman program because I keep getting errors in it, its says im missing the { and the }. Also if you notice any errors in the other please point them out.