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.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?Code: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 ); } }


Reply With Quote


Bookmarks