Results 1 to 4 of 4
  1. #1
    Vahevahe is offline Member
    Join Date
    Aug 2015
    Posts
    3
    Rep Power
    0

    Default Hi guys! Need help with simple code.

    Hey guys,
    Im taking a java class and am kind of stuck! The teacher requires us to read a CSV file with sales data on it. Calculate how much of each item sold and output 2 collums. One with the item number and one with how much was sold of that item. Im more of a C++ guy so i am just learning java and i am kind of stuck. Instructions for program are first, Code is second and output is third. Any help would be greatly appreciated!!!

    1. Read the Sales data from the provided file. A sample of the file is shown below. (Its a excel file that we change to CSV).

    Customer ID Product ID Units(sample, real list is longer)
    1 10002 4
    1 10004 6
    1 10008 2
    1 10010 3

    2. Calculate the Total Units Sold for Each Product. Output the results in a file formatted as the example below.
    3. Identify and document the requirements
    4. Write pseudo-code for this application
    5. Create Test Cases that will demonstrate the requirements
    6. Implement in Java.
    7. Write a main program that demonstrates that the code meets the requirements.
    8. Document your test results


    Heres what i have so far...
    Java Code:
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    
    public class Experiment3 {
    	
    	public static void main(String[] args) throws IOException {
    		
    		String lines = "";
    		String unparsedFile = ""; 
    		String myArray[]; 
    		
    		FileReader fr= new FileReader("c://SalesData.csv"); 
    		BufferedReader br = new BufferedReader(fr); 
    	
    	
    		while((lines = br.readLine()) != null){
    			
    			unparsedFile += lines; 
    			
    		}
    		br.close();
    		myArray = unparsedFile.split(","); 
    		//The bottom is what puts the items into the array 
    		for(String item : myArray){
    			
    			System.out.println(item);
    					
    		
    		}
     }
    }
    HERE IS MY OUTPUT

    Customer ID
    Product ID
    Units






    1
    10002
    4






    1
    10004
    6






    1
    10008
    2






    1
    10010
    3
    Last edited by Vahevahe; 08-28-2015 at 08:30 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Hi guys! Need help with simple code.

    First, you need to wrap you code in code tags - see BB Code List - Java Programming Forum - Learn Java Programming

    The instructions said "..format below" but I didn't see a format. Nor did you specifically state what help you needed.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Vahevahe is offline Member
    Join Date
    Aug 2015
    Posts
    3
    Rep Power
    0

    Default Re: Hi guys! Need help with simple code.

    Hey Jim thanks for your prompt response!
    The format is basically 2 column output with the item number first and the quantity sold second. Basically I have the output but I don't know how to go through the output and take out what I need from it. I need to get the item numbers (10002, 10004 ect) and the amount of those items sold (1 ,2 , ext). Add the amounts together. So if I have item number 10002 with 2 quality sold and 10002 with 3 quantity sold it will output 10002 with 5 quantity sold. So it is basically a sales list. I don't need the first 3 headers in the output (Customer ID,Product ID, Units) and I don't need the customer it (which is the first number in the outputs triplet.)

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Hi guys! Need help with simple code.

    Are you permitted to use HashMaps? You can use the item number as a key for the map and the value can be the sums of the item bought. Check out the tutorial in my signature. Go to big index and check out maps.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. I need help guys on the java code.
    By Phila in forum New To Java
    Replies: 2
    Last Post: 08-27-2015, 06:27 PM
  2. need a simple code for the following
    By payal in forum New To Java
    Replies: 3
    Last Post: 09-14-2011, 01:24 AM
  3. help me guys i got one simple doubt
    By funkygarzon in forum New To Java
    Replies: 10
    Last Post: 02-06-2011, 05:14 PM
  4. OK Guys! My new and improved code.
    By Meta in forum New To Java
    Replies: 4
    Last Post: 04-07-2010, 01:06 PM
  5. Please help me this is simple bit of code
    By BlitzAcez in forum New To Java
    Replies: 4
    Last Post: 11-27-2008, 05:52 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
  •