DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Assignment help

  1. #1
    Join Date
    Sep 2007

    Assignment help

    Here is my assignment.

    Ask the user for the number of rows (or aisles of coffee bins). Then prompt the user for the number of bins in each aisle. Create a two dimensional array to correspond to the numbers that the user entered. The array will hold numbers representing pounds. Now prompt the user for the pounds in each bin. Once all the bins are filled, display the each element in the array (in a good format) and display the total number of pounds in the coffee shop.
    import java.util.Scanner;
    public class CoffeeArray
    	public static void main( String args[] )
    	   Scanner input = new Scanner( System.in );
    	   int coffee[][];
    		int weight;
    		int aisles;
    		int total[];
    		int counter;
    		int number;
    		int bins = 0;
    		int totalWeight = 0;
    		System.out.print( "Please input the number of aisles\n" );
    		aisles = input.nextInt();
    		coffee = new int [aisles][1];
    		if ( counter = 0; coffee.length > counter; counter++)
    		number = counter + 1;
    		System.out.printf( "\nHow many bins are in each aisle %d?\n" , number  );
    		bins = input.nextInt();
    	   coffee[aisles][1] =  bins;
    		System.out.print( "How much does each coffee bin weigh?\n" );
    		weight = input.nextInt();
          total = new int [aisles];
    		total[aisles] = bins * weight;
    		System.out.printf( "%s%10s%10s\n", "Aisles" , "Bins" , "Weight" );
    	   System.out.printf( "%d%10d%10d\n" , coffee[aisles][0], coffee[aisles][1], total[aisles]);
    		totalWeight += total[30];
    		System.out.printf( "The total amount of pounds is: %d" , totalWeight );
    The program compiles but it isn't working because the array is out of bounds. Am I totally off base, or do I just need to rework what I have?

  2. #2
    Join Date
    Jul 2005
    You can rework what you have, with a little more new code added in.

    you need to ask for the number of aisles, ask for the number bins, _then_ construct your 2D array.

    I think that the question is assuming that each aisle has the same number of bins.

    You need to add in a nested for loop to go through and ask the user to input the ammount of coffee in each bin.

    While they're doing that, you could also add up the totals too.

  3. #3
    Join Date
    Sep 2007
    I wish I understood what you're saying. I think my brain is fried for tonight.

  4. #4
    Join Date
    Jul 2005
    Ask how many aisles
    Ask how many bins per aisle

    make 2D array from those numbers

    For each aisle, ask how much coffee is in each bin
    Keep a running total of the amount of coffee

    Print (nicely) to screen the amount of coffee in each bin
    Print the total amount of coffee to screen.

  5. #5
    Join Date
    Sep 2007
    It was because I'd been working on this and other things all day yesterday. I'm awake from the new morning and understand your logic now. Thank you. I'll see if I can code this.

Similar Threads

  1. Help with Array Assignment
    By youngone in forum C++
    Replies: 4
    Last Post: 03-01-2007, 06:23 PM
  2. Replies: 3
    Last Post: 10-31-2006, 04:51 PM
  3. Assignment Help
    By egobolo in forum Java
    Replies: 4
    Last Post: 05-24-2006, 03:27 AM
  4. Replies: 3
    Last Post: 10-21-2005, 10:06 AM
  5. Replies: 2
    Last Post: 07-02-2005, 12:35 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center