Here a snip of a java code:
PrintWriter outputFile = new PrintWriter(DATA);
do {
...
...
...
listOfItems += String.format("%10d %-15s $%.2f\n", quantity, productspec.getDescription(), quantity * productspec.getPrice());
...
...
// Putting it in output file
outputDataLine = "----------------------------" + "\nItems
list:";
outputFile.println(outputDataLine);
outputFile.println(listOfItems);
outputFile.printf("Subtotal $%.2f\n", subtotal);
....
....
} while
(choice.equals("y") || choice.equals("Y"));
outputFile.close();
My Questions is, how do you remove the duplicates in the listOfItems and combine the number of quantity and the price of a particular items in the txt output file
Here is the sample output that stored in txt file.

For instance, Chocolate were listed twice, just need to listed once all the items that is duplicates.
Like this
3 Chocolate 5.37
.....so on
Here's one of the ways how you can achieve that.
Create 2 hashtables for storing quantity and the total price of the product.
Replace the line which updates listOfItems with lines which update the hashtables.
Later on, in the section where the print functions are being called to print the data, update the listOfItems by going through every entry through the hashtables and the print the list. You can see in the following snippet how you can go about doing it. Look at the screenshot in case the text looks confusing to you. Take help of the comments I wrote about which lines serve what purpose. Feel free to ask any doubts by commenting on the answer.
Hashtable<String, Integer> ht = new Hashtable<String,
Integer>(); // ht store quantity of the item
Hashtable<String, double> hp = new Hashtable<String,
double>(); // hp stores the total price of the item
PrintWriter outputFile = new PrintWriter(DATA);
do {
...
...
...
String str =productspec.getDescription(); // str = name of
product
// If the product is already in table ht, increase the quantity and
total price
if (ht.containsKey(str))
{
ht.put(str, ht.get(str) + quantity);
hp.put(str, hp.get(str) + quantity*productspec.getPrice());
}
// Else insert str with quantity in table ht, and str with price in
table hp
else
{
ht.put(str, quantity);
hp.put(str, quantity*productspec.getPrice());
}
...
...
// Putting it in output file
outputDataLine = "----------------------------" + "\nItems
list:";
outputFile.println(outputDataLine);
listOfItems = "";
Enumeration names = ht.keys(); // Extract all the keys from the
table ht
while(names.hasMoreElements()) // Go over every key
{
String key = (String) names.nextElement(); // Convert the next key
to String form
listOfItems += String.format("%10d %-15s $%.2f\n", ht.get(key),
key, hp.get(key)); // Add all the values to listOfItems
}
ht.clear(); // Clears out the hashtable for next iteration
hp.clear(); // Clears out the hashtable for next iteration
outputFile.println(listOfItems);
outputFile.printf("Subtotal $%.2f\n", subtotal);
....
....
} while (choice.equals("y") || choice.equals("Y"));
outputFile.close();

Here a snip of a java code: PrintWriter outputFile = new PrintWriter(DATA); do { ...