Results 1 to 4 of 4
  1. #1
    Exceedinglife is offline Member
    Join Date
    Apr 2012
    Posts
    17
    Rep Power
    0

    Default copying information

    hello i have data i need to get from a .txt doc and i need to put that data into an array the data is doubles and i am using the scanner class to read the data but now i am having troubles getting it to copy into the array i am trying to use a nested for loop

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: copying information

    Please post the code that you have written so far. So we can have a check on what you are doing there.

  3. #3
    Exceedinglife is offline Member
    Join Date
    Apr 2012
    Posts
    17
    Rep Power
    0

    Default Re: copying information

    ok here you go i forgot my actually code on the pc at school so i need to start over

    Java Code:
    import java.io.*;
    import java.util.Scanner;
    import java.text.DecimalFormat;
    
    public class SalesStats
    {
    	public static void main(String[] args) throws IOException
    	{
    	    // Create a Divisions object.
    	    Divisions d = new Divisions();
    
       	    // Read the values from the file into d.
    	    readValues(d);
    		
    	    // Display the values in d.
    	    displaySales(d);
    	
    	    // Display the quarterly increase or decrease.
    	    displayQtrDifference(d);
    		
    	    // Display the total sales by quarter.
    	    displaySalesByQtr(d);
    		
    	    // Display the quarterly increase or decrease
    	    // by quarter.
    	    displayCompanyQtrDifference(d);
    		
    	    // Display the average sales per quarter.
    	    displayAverageSalesPerQtr(d);
    		
    	    // Display the division with the highest sales
    	    // by quarter.
    	    displayHighestDivisionPerQtr(d);
    	}
    	
    	/**
    	 * readValues method.
    	 * Reads the values from Sales.txt into the object.
    	 */
    	
    	public static void readValues(Divisions d) throws IOException
    	{
                 /* Missing code starts here */
    			Scanner keyboard = new Scanner(System.in);
    			File file = new File("Sales.txt");
    			Scanner inputFile = new Scanner(file);
    			while(inputFile.hasNext())
    				{
    				String Sales = inputFile.nextLine();
    				inputFile.close();
    				}
                 /* Missing code ends here */
    	}
    
    	/**
    	 * displayValues method.
    	 * Displays a list of sales figures by division.
    	 */
    	
    	public static void displaySales(Divisions d)
    	{
    	    System.out.println("SALES AMOUNTS BY DIVISION");
    	    System.out.println("=========================");
                /* Missing code starts here */
     
                /* Missing code ends here */
    	}
    	
    	/**
    	 * displayQtrDifference method.
    	 * Displays the quareterly increase or decrease for each
    	 * division, starting at quarter 2.
    	 */
    	
    	public static void displayQtrDifference(Divisions d)
    	{
    	    System.out.println("QUARTERLY INCREASE/DECREASE BY DIVISION");
    	    System.out.println("=======================================");
                /* Missing code starts here */
     
                /* Missing code ends here */
    	}
    	
    	/**
    	 * displaySalesByQtr method.
    	 * Displays total sales by quarter.
    	 */
    	
    	public static void displaySalesByQtr(Divisions d)
    	{
    		DecimalFormat dollar = new DecimalFormat("#,##0.00");
    		
    		System.out.println("SALES AMOUNTS BY QUARTER");
    		System.out.println("========================");
    		for (int qtr = 1; qtr <= 4; qtr++)
    		{
    			System.out.println("Quarter " + qtr + ": $" +
    			                   dollar.format(d.totalQuarterSales(qtr)));
    		}
    		System.out.println();
    	}
    
    	/**
    	 * displayCompanyQtrDifference method.
    	 * Displays the quareterly increase or decrease for the
    	 * company, starting at quarter 2.
    	 */
    	
    	public static void displayCompanyQtrDifference(Divisions d)
    	{
    	    double increase;
    		
    	    DecimalFormat dollar = new DecimalFormat("#,##0.00");
    		
    	    System.out.println("QUARTERLY INCREASE/DECREASE FOR THE COMPANY");
    	    System.out.println("===========================================");
                /* Missing code starts here */
     
                /* Missing code ends here */
    	}
    	
    	/**
    	 * displayAverageSalesPerQuarter method.
    	 * Displays the average sales for all divisions per quarter.
    	 */
    	
    	public static void displayAverageSalesPerQtr(Divisions d)
    	{
                /* Missing code starts here */
     
                /* Missing code ends here */
    	}
    
    	/**
    	 * displayHighestDivisionPerQtr method.
    	 * Displays the division with the highest sales per quarter.
    	 */
    	
    	public static void displayHighestDivisionPerQtr(Divisions d)
    	{
    	    System.out.println("DIVISION WITH THE HIGHEST SALES PER QUARTER");
    	    System.out.println("===========================================");
    		
                /* Missing code starts here */
     
                /* Missing code ends here */
    	}
    }
    this is the part im asking about


    Java Code:
    	public static void readValues(Divisions d) throws IOException
    	{
                 /* Missing code starts here */
    			Scanner keyboard = new Scanner(System.in);
    			File file = new File("Sales.txt");
    			Scanner inputFile = new Scanner(file);
    			while(inputFile.hasNext())
    				{
    				String Sales = inputFile.nextLine();
    				inputFile.close();
    				}
                 /* Missing code ends here */
    	}

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: copying information

    The following code will store data read from the Sales.txt document into an ArrayList. Use ArrayList if we are not sure the size of our data are. We can just add data into an ArrayList.

    Java Code:
    public static void readValues(Divisions d) throws IOException
    {
            ArrayList list = new ArrayList();
    
            File file = new File("Sales.txt");
            Scanner inputFile = new Scanner(file);
    
            while(inputFile.hasNext()) {
                String sales = inputFile.nextLine();
                list.add(sales);
            }
    }

Similar Threads

  1. Replies: 5
    Last Post: 04-27-2011, 09:14 PM
  2. add to a zip file without copying it.
    By yurabita in forum New To Java
    Replies: 5
    Last Post: 08-21-2010, 03:16 AM
  3. Not Copying Libraries!?!
    By Atriamax in forum NetBeans
    Replies: 0
    Last Post: 10-13-2009, 07:56 AM
  4. Copying a derectory
    By linux1man in forum New To Java
    Replies: 10
    Last Post: 01-15-2009, 07:16 PM

Posting Permissions

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