hello guyz,,i have confusion anyway,,

i have a textfiles (products.txt & cart.txt):

"products.txt"
inside this text file is
Alcohol $12.7 12
Shirt $45.00 34

if i run it to a java file it would be like this
actually i already know how to read the file,,and when i output it:
Item Price Quantity on hand
1 Alcohol $12.7 12
2 Shirt $45.00 34

if i would like to buy
buy 2(prodNum) 10(qty)

then after the conversation,,it would be like this..
add Shirt to cart

then my cart.txt will be like this:
"cart.txt"
Shirt 45 10

then the quantity on hand in the "products.txt" will be deducted and would result into new:
"products.txt"
inside this text file is
Alcohol $12.7 12
Shirt $45.00 24 (34-10,,since i purchased 10 shirts,,)

hope you can help me guyz,,thank you ahead...

Sure we can, as soon as we see what you have, you tell us what compiler/error messages it is giving you, and what it is actually producing and how that differs from what it should produce.

Sure we can, as soon as we see what you have, you tell us what compiler/error messages it is giving you, and what it is actually producing and how that differs from what it should produce.

Shopping Cart Java Fundamentals and OOP Instruction
Mr. I. M. Cheap owns Buy From Us, a small convenience store in a small town in the Philippines. Mr. Cheap always dreamt big, and plans to start a chain or convenience stores to rival that those from 7-Eleven and Ministop. A critical component is to develop a small “shopping cart” application that will aid his customers in purchasing products from his store.
Mr. Cheap wanted to start with the bare essentials, and has selected you to develop his critical application. The specifications for the application are outlined below:
Specifications:
1. Developed using the Java Platform
2. Display a list of products available for purchase.
a. The list of products is stored in a text file which is accessed by the system.
b. System should show the product name, number of products available, and the price of the product
c. The products list should be numbered starting from 1 to allow customer to select the product they want to purchase
d. Should there be no products available for purchase, inform the customer and exit the application.
3. Display a list of products that are currently inside the shopping cart.
a. The shopping cart is stored in a text file which is accessed by the system.
b. The list displayed should be of the same format as that displayed by list of products
c. A grand total should be displayed at the end of the list, showing the amount the customer must pay for all the products bought.
d. Should the shopping cart be empty, inform the customer that the shopping cart is empty.
4. Allow a user to buy a product.
a. Accept a product number and quantity.
b. Validate user input
i. Do not allow customers to buy products that do not exist
ii. Do not allow customers to buy more products than being sold.
iii. Do not allow customers to buy products with negative quantity.


Command-line Interface
Application should allow the following commands to be executed
MENU : [LP] - list-products
[SC] – show cart
[BUY #prodNum #qty] – buy

• list-products : lists products being sold
Product List
-----------------------------------------------------------------
No. Name Price Qty
-----------------------------------------------------------------
1 Foo 10.00 5
• show-cart: lists products currently inside the shopping cart

Shopping Cart
-----------------------------------------------------------------
No. Name Price Qty
-----------------------------------------------------------------
1 Foo 10.00 5
Total: 50.00

• buy #productNumber #quantity: buy product specified by the #productNumber with quantity specified by #quantity

Bought 2 pieces of Foo

File Format
The product name, quantity, and price should be stored in the product list and shopping cart text files, separated by tab spaces.

Foo 9 10.00
Banana 11 9.00


You can choose to use BufferedReader or JOptionPane…


..this is how we gonna make this,,we have two days left..actually,,have no idea how to do it,,"no discussions were discussed",,only the reading file...
guyz,,hope you can help me,,,,

By "Show us what you have" I, obviously, meant your code. We are not simply going to do your homework for you. We will help you correct your code, though.

By "Show us what you have" I, obviously, meant your code. We are not simply going to do your homework for you. We will help you correct your code, though.

import java.io.*;

import javax.swing.*;
public class ShoppingCart{
	 private static final File FILE1 = new File("shopFolder/products.txt"); 
     

  public static void productsList() throws IOException {

    FileReader fr;
    try {
      fr = new FileReader(FILE1);
      BufferedReader br = new BufferedReader (fr);
      String line = br.readLine();
      while (line != null) {
          System.out.println(line);
          line = br.readLine();
      }
      br.close();
      
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      
    }
  }
  public static void cartList() throws IOException {
	  FileReader fr1 = new FileReader(FILE1); 
      Reader reader1 = new BufferedReader(fr1); 
      LineNumberReader lnr1 = new LineNumberReader(reader1);  
      Writer writer = new FileWriter("shopFolder/cart.txt"); 
      String line1; 
   
      for (line1 = lnr1.readLine(); line1 != null ; line1 = lnr1.readLine()) { 
              System.out.println(line1); 
              writer.write(line1+" "); 
      } 
      writer.flush(); 
      writer.close(); 


      reader1.close(); 
   
} 
	    
	  
    public static void main (String args[])throws IOException{
    	BufferedReader dataIn = new BufferedReader 
    	(new InputStreamReader( System.in));
    	
    	String buy;
    	String store;
    	store = ("What do you want to do?" +
    			"\nSP - ShowProduct\nSC - ShowCart");
    	
    	System.out.println(store);
    	store = dataIn.readLine();
    	
    	if("SP".equalsIgnoreCase(store)){
    		productsList();
    		buy = dataIn.readLine();
    		System.out.println("Bought");
    		
    		
    	}else if("SC".equalsIgnoreCase(store)){
    		cartList();
    	}
    	
    



  }
}

..i dont know how to implement other methods then,,sorry,,it's because i am just a beginner in java...i think there are errors there...

And what about the rest of the advice from my first post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.