Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-24-2007, 03:20 PM
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??
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-24-2007, 06:52 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Here is a tip to show you how to obtain item code from standard input:

Java Tips - Reading Text from Standard Input
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-25-2007, 10:20 AM
Member
 
Join Date: Jul 2007
Posts: 7
e_as're is on a distinguished road
that helps .. thanx
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-25-2007, 11:14 AM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
You are welcome. Let us know if you have further problems..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +3. The time now is 09:37 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org