Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Output not correct
mike hew
Greenhorn
Posts: 27
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I've gotten the code down almost 99%, but my problem is getting the lowest term and highest term print ln to display just to the right of the output data, any idea?
public class Piecework { public static void main(String args[]) { MyCsvFile myFile = new MyCsvFile("piecesCompletedByEmployee,v00.txt"); String employeeName[] = new String[myFile.getCountOfRecords()]; int piecesCompleted[] = new int[myFile.getCountOfRecords()]; String myFields[]; int lowestPiecesCompleted = Integer.MAX_VALUE; int highestPiecesCompleted = Integer.MIN_VALUE; int indexOfLowestProducer = 0; int indexOfHighestProducer = 0; String lowestHigestProducerMessage; int index; myFile.readARecord(); while(myFile.getEofFound() == false) { index = (myFile.getCurrentRecordNumber()-1); myFields = myFile.getCsvRecordFieldArray(); employeeName[index] = myFields[0]; piecesCompleted[index] = Integer.parseInt(myFields[1]); if (piecesCompleted[index] < lowestPiecesCompleted) lowestPiecesCompleted = piecesCompleted[index]; indexOfLowestProducer = index; // end if if (piecesCompleted[index] > highestPiecesCompleted) highestPiecesCompleted = piecesCompleted[index]; indexOfHighestProducer = index; // end if myFile.readARecord(); } // end while ProducePieceworkCalculationReport(employeeName, piecesCompleted, indexOfLowestProducer, indexOfHighestProducer, myFile.getCountOfRecords(), myFile.getFilePath(), myFile.getFileName()); System.out.println("\nEnd of program"); } // end main method private static void ProducePieceworkCalculationReport(String employeeName[], int piecesCompleted[], int indexOfLowestProducer, int indexOfHighestProducer, int countOfRecords, String filePath, String fileName) { double sumOfEarnings = 0.0; int sumOfPiecesCompleted = 0; String lowestHighestProducerMessage; double thisEmployeePerPiecePayRate; double thisEmployeeEarnings; int index; System.out.println("Piecework Calculation\n"); System.out.printf("\t\t\t Pieces\tPay Per\t\tAmount\n"); System.out.printf(" Employee Name\tCompleted\t Piece\t\tEarned\n\n"); for(index = 0; index <= employeeName.length -1; index++) { thisEmployeePerPiecePayRate = (PerPiecePayRate(piecesCompleted[index])); thisEmployeeEarnings = (piecesCompleted[index] * thisEmployeePerPiecePayRate); sumOfPiecesCompleted = sumOfPiecesCompleted + piecesCompleted[index]; sumOfEarnings = sumOfEarnings + thisEmployeeEarnings; System.out.printf("%-16s %,5d $ %,.2f\t $ %,8.2f\n ", employeeName[index], piecesCompleted[index], thisEmployeePerPiecePayRate, thisEmployeeEarnings); lowestHighestProducerMessage = (" "); if(index == indexOfLowestProducer){ lowestHighestProducerMessage = ("Lowest Producer"); }// end if if(index == indexOfHighestProducer){ if(lowestHighestProducerMessage.equals(" ")) lowestHighestProducerMessage = ("Highest Producer"); else lowestHighestProducerMessage = ("Lowest and Highest Producer"); } //end if if (!lowestHighestProducerMessage.equals (" ")){ System.out.printf("%s",lowestHighestProducerMessage); }//end if } // end for System.out.printf("\n\nTotal Pieces Completed\t %,d\n", sumOfPiecesCompleted); System.out.printf("Average Pieces Completed %,.2f\n\n", (double)sumOfPiecesCompleted / countOfRecords); System.out.printf("Total Amount Earned\t\t\t\t $%,.2f\n", sumOfEarnings); System.out.printf("Average Amount Earned\t\t\t\t $ %,.2f\n\n", sumOfEarnings / countOfRecords); System.out.printf("The information in the above report is from the 26 records in the following file:\n\t" + "Path to file: %s\n\tName of file: %s\n\n", filePath, fileName); } // end class ProducePieceworkCalculationReport private static double PerPiecePayRate(int piecesCompleted) { final double perPiecePayRate1 = 0.50; final double perPiecePayRate2 = 0.55; final double perPiecePayRate3 = 0.60; final double perPiecePayRate4 = 0.65; final int maximumPiecesCompletedForPayRate1 = 199; final int maximumPiecesCompletedForPayRate2 = 399; final int maximumPiecesCompletedForPayRate3 = 599; if(piecesCompleted <= maximumPiecesCompletedForPayRate1) return perPiecePayRate1; else if(piecesCompleted <= maximumPiecesCompletedForPayRate2) return perPiecePayRate2; else if(piecesCompleted <= maximumPiecesCompletedForPayRate3) return perPiecePayRate3; else return perPiecePayRate4; } // end class PerPiecePayRate } // end class Piecework
Edwin Dalorzo
Ranch Hand
Posts: 961
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have not tested your code, but at first sight, there is a problem with some of your "ifs".
You wrote
if (piecesCompleted[index] < lowestPiecesCompleted) lowestPiecesCompleted = piecesCompleted[index]; indexOfLowestProducer = index; // end if if (piecesCompleted[index] > highestPiecesCompleted) highestPiecesCompleted = piecesCompleted[index]; indexOfHighestProducer = index;// end if
And it should have been
if (piecesCompleted[index] < lowestPiecesCompleted) { lowestPiecesCompleted = piecesCompleted[index]; indexOfLowestProducer = index; }// end if if (piecesCompleted[index] > highestPiecesCompleted) { highestPiecesCompleted = piecesCompleted[index]; indexOfHighestProducer = index; }// end if
You have to use brackets or just the first sentence will be included in the if.
[ November 05, 2006: Message edited by: Edwin Dalorzo ]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
might not have been initialized
cannot find symbol
Exeception in thread
the instance variable shapes
enhanced for loop hangup?
More...