Results 1 to 4 of 4
  1. #1
    e_as're is offline Member
    Join Date
    Jul 2007
    Posts
    7
    Rep Power
    0

    Default 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??

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    Here is a tip to show you how to obtain item code from standard input:

    Java Tips - Reading Text from Standard Input

  3. #3
    e_as're is offline Member
    Join Date
    Jul 2007
    Posts
    7
    Rep Power
    0

    Default

    that helps .. thanx

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    You are welcome. Let us know if you have further problems..

Similar Threads

  1. exercise of recursive method
    By amexudo in forum New To Java
    Replies: 2
    Last Post: 03-09-2008, 05:55 PM
  2. Prob with an exercise
    By jhetfield18 in forum New To Java
    Replies: 4
    Last Post: 02-15-2008, 06:11 PM
  3. Problems with Calendar exercise
    By Jude in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 07:30 PM
  4. I/O exercise
    By Feldom in forum New To Java
    Replies: 1
    Last Post: 10-28-2007, 04:48 PM
  5. help with an exercise calcuting tax
    By e_as're in forum New To Java
    Replies: 7
    Last Post: 08-01-2007, 03:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •