Results 1 to 4 of 4
Thread: help with exercise
- 09-24-2007, 02:20 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 7
- Rep Power
- 0
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??
- 09-24-2007, 05:52 PM #2
Here is a tip to show you how to obtain item code from standard input:
Java Tips - Reading Text from Standard Input
- 09-25-2007, 09:20 AM #3
Member
- Join Date
- Jul 2007
- Posts
- 7
- Rep Power
- 0
that helps .. thanx
- 09-25-2007, 10:14 AM #4
Similar Threads
-
exercise of recursive method
By amexudo in forum New To JavaReplies: 2Last Post: 03-09-2008, 05:55 PM -
Prob with an exercise
By jhetfield18 in forum New To JavaReplies: 4Last Post: 02-15-2008, 06:11 PM -
Problems with Calendar exercise
By Jude in forum New To JavaReplies: 1Last Post: 11-20-2007, 07:30 PM -
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10-28-2007, 04:48 PM -
help with an exercise calcuting tax
By e_as're in forum New To JavaReplies: 7Last Post: 08-01-2007, 03:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks