View Single Post
  #1 (permalink)  
Old 09-24-2007, 04:20 PM
e_as're e_as're is offline
Member
 
Join Date: Jul 2007
Posts: 7
e_as're is on a distinguished road
help with exercise
hi, we've been given an exercise to complete which im having difficulties with. we have to write a small checkout program which an item code is entered asking for a product code. when entered it it matches it displays the relevant product (reads input from a an existing file). ive written out the following;

public class CheckoutProgram {

public void start() {
SalesItem[] items = getStock();

}

// method to read in "stock.txt" and store the items for sale in an array of type SalesItem

private SalesItem[] getStock(){
SalesItem[] items = new SalesItem[1000];
try {
BufferedReader br = new BufferedReader(new FileReader("stock.txt"));
String theLine;
int count = 0;
while ((theLine = br.readLine()) != null) {
String[] parts = theLine.split(",");
items[count] = new SalesItem(parts[0],parts[1],Double.parseDouble(parts[2]));
if (parts.length==4){
String discount = parts[3];
String numPurchases = discount.substring(0, discount.indexOf("@"));
String price = discount.substring(discount.indexOf("@")+1);
items[count].setNumPurchases(Integer.parseInt(numPurchases));
items[count].setDiscountedPrice(Double.parseDouble(price));
}
count++;
}
}
catch (IOException e) {
System.err.println("Error: " + e);
}
return items;
}

private void getDescription(){
System.out.println();
System.out.println("Type item code (press enter to finish): ");
System.out.println("Type item code (press enter to finish): ");
System.out.println("Type item code (press enter to finish): ");
}

am stuck from here??
Reply With Quote
Sponsored Links