I'm having trouble with an assignment for a class. I need to be able to print a sales report after inputting certain data and figured the best way to keep track of everything was to use arrays.
I have been trying to figure this out for hours and I'm stumped. Any help would be appreciated.
For reference, the user needs to input:
- the employee name
- year to date sales
- a transaction number
- transaction type
- transaction amount
Then it should loop back to transaction number and continue that loop until the value 0 is given as input for transaction number.
Then it should loop back to employee name and continue back through that loop until Done is given as input for employee name.
Here is the code (I think this is the only relevant portion, but if you want to see the whole piece of code I can post it.)
Thanks again for all your help or suggestions!
void salesData() throws IOException {
for (int i = 0; i < 100; i++) {
System.out.print("Enter Name: ");
n = stdin.readLine();
if (n.equalsIgnoreCase("done")) {
break;
}
else {
System.out.print("Enter Transaction Number: ");
t = Integer.parseInt(stdin.readLine());
if (t == 0) {
break;
}
else {
System.out.print("Enter Transaction Type: ");
tp = stdin.readLine();
System.out.print("Enter Transaction Amount: ");
a = Double.parseDouble(stdin.readLine());
totSales = totSales + a;
totYtd = totYtd + a;
empTotal = empTotal + a;
empBonus = empBonus + (a * 0.05);
name[i] = n;
ytd[i] = y;
tNum[i] = t;
type[i] = tp;
amount[i] = a;
outputUpdate();
calcSalesData();
}
}
}
outputSalesData();
}
Ok, so i've been working on this thanks to your guys' help and I've made a lot of progress. Still having one issue though. The array is only saving the trans number, type, and amount for the LAST transaction entered for each employee instead of EACH transaction.
I believe the error is that i need to iterate the arrays for tNum, type, and amount at a different rate than the name and ytd arrays?
Having a bit of trouble still so any help is appreciated... here is my updated code as well as the print statement at the end.
void salesData() throws IOException {
for (int i = 0; i < 100; i++) {
System.out.print("Enter Name: ");
n = stdin.readLine();
if (n.equalsIgnoreCase("done")) {
outputSalesData();
}
System.out.print("Enter Year to Date Sales: ");
y = Double.parseDouble(stdin.readLine());
ytdSales = ytdSales + y;
totYtd = totYtd + ytdSales;
while (t != 0) {
System.out.print("Enter Transaction Number: ");
t = Integer.parseInt(stdin.readLine());
if (t == 0) {
t = 1;
empBonus = 0;
ytdSales = 0;
break;
}
else {
System.out.print("Enter Transaction Type: ");
tp = stdin.readLine();
System.out.print("Enter Transaction Amount: ");
a = Double.parseDouble(stdin.readLine());
totSales = totSales + a;
totYtd = totYtd + a;
ytdSales = ytdSales + a;
empTotal = empTotal + a;
empBonus = empBonus + (a * 0.05);
name[i] = n;
ytd[i] = y;
tNum[i] = t;
type[i] = tp;
amount[i] = a;
outputUpdate();
calcSalesData();
tCount++;
}
}
}
}
and here is the print:
void rptOut() {
System.out.println("");
System.out.println("--------------------------------------------");
System.out.println("Employee:\tYTD:\t\tT #:\tType:\tAmount:");
while (index < tCount)
{
System.out.println(name[index] + "\t\t$" + df2.format(ytd[index]) + "\t" + tNum[index] + "\t" + type[index] + "\t$" + amount[index]);
index++;
}
System.out.println("--------------------------------------------");
System.out.println("Total Food & Soft Drink Sales: \t$" + df2.format(totF));
System.out.println("Total Alcohol Sales: \t\t$" + df2.format(totA));
System.out.println("Total Sundries Sales: \t$" + df2.format(totS));
System.out.println("--------------------------------------------");
System.out.println("Total Sales for Day: \t$" + df2.format(totSales));
System.out.println("Total YTD: \t\t$" + df2.format(totYtd));
System.out.println("--------------------------------------------");
System.out.println("Highest Trans Amount: \t$" + df2.format(hiTrans));
System.out.println("Employee w/ Highest Trans: \t" + hiEmp);
System.out.println("--------------------------------------------");
//System.exit(0);
}
i5loop? You may as well just useif (i3 > 0)instead of the for loop, since it won't loop.