Hello everyone. This if my first post on the forum, and hopefully my last asking for help on an assignment. I've picked and picked at this, and now I'm going insane. I've edited this one too many times, so now I figure its one of three things. My entire approach to the problem was wrong, my approach wasn't wrong but I went about it the wrong way, or I got it right but my code is messed up somewhere and the entire thing is being throw off.

Anyways, here's 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.

Here's my attempt at coding this. I hope it doesn't look too pathetic.

import java.util.Scanner;

public class CoffeeArray
{
	public static void main( String args[] )
	{
	
	   Scanner input = new Scanner( System.in );
		
	   int coffee[][];
		int aisles;
		int weight;
		int total[];
		int counter;
		int number;
		int bins;
		int totalweight;
		
		System.out.print( "Please input the number of aisles\n" );
		aisles = input.nextInt();
		
		coffee = new int [aisles][];
		
		for ( 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] = { {aisles + counter } , {bins} };
		
		}
		

		
		System.out.print( "How much does each coffee bin weigh?\n" );
		weight = input.nextInt();
		
      total[] = { {bins * weight} };
		
		
	   System.out.printf( "%s%10s%10s\n", "Aisles" , "Bins" , "Weight" );
	   System.out.printf( "%d%10d%10d\n" "Don't know what to put here");

           totalweight += total[];

		
		System.out.printf( "The total amount of pounds is: %d" );
		
		
	}
}

Worked on it again and fixed the compiling errors, but now it won't run correctly.

import java.util.Scanner;

public class CoffeeArray
{
	public static void main( String args[] )
	{
	
	   Scanner input = new Scanner( System.in );
		
	   int coffee[][];
		int aisles;
		int weight;
		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];
		
		for ( 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[aisles];
		
		System.out.printf( "The total amount of pounds is: %d" , totalWeight );
		
		
	}
}

Why not use a class?

class Blah
{
int aisles;
int bins;
}

Then you can store them and access them as objects?
[edit]foget that i didn't read your conditions[/edit]

As I understand your requirement, you only need an array coffee[numberOfAisles][numberOfBins]. I don't think you need to have a different number of bins per aisle, so you can create the array directly from the two questions without looping.

You will need to loop the array when you total the weight. Which you currently are not doing.

Yeah, I figured it out. Basically I made the assignment out to be more than it is. Classic case of over-thinking something simple.

This article has been dead for over six months. Start a new discussion instead.