copy multi dim array to Vector and print, goofy output
I thought it would print the contents of the array, such as Paper, Large or Plastic, Small. Instead I got this. Can anyone lead me in the right direction?
Also, why is it that when I put the print statement for the vector in the printVectorList method it does not recognize cupVector?
output: Vector contents
[[[I@10b62c9]
BUILD SUCCESSFUL (total time: 0 seconds)
/*
* Main.java
*
* Created on May 21, 2007, 12:41 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author P
*/
import java.util.Vector;
publicclass Main{
/* The main method in the Main class will instantiate an array of 10 Cup
objects. Five cups will be
small and plastic. The other five will be large and paper.
From the array, you will use a for loop to copy the Array of Cups into a
Vector, an ArrayList,
and a LinkedList. Note: The Vector, ArrayList, and LinkedList should all be
static instance variables so that they
can be used by other static methods than just the main method.
For example,
int cups[] = new Cup[10]//added by DS in lab
//the initialization
for(int i=0; i<cups.length; i++){
*///copy a cup into the Vector
//copy a cup into the ArrayList
//copy a cup into the LinkedList
//After the population of these data structures, print the cup information in
//each by calling
//appropriate print methods from main, for example:
//printCupVector(), printCupArrayList(), and printCupLinkedList().*/
privatestaticvoid printCupVector()
{
System.out.println("Vector contents");
}
privatestaticvoid printCupArrayList()
{
}
privatestaticvoid printCupLinkedList()
{
}
//This means that you have to create these three private methods in Main.java.
//Declare them as
//static so that the main method can call them without having to instantiate a
//class.
//Post your code and output from running it to the Discussion Board and comment
//on other
//postings. Be sure that you get your code to run on your own before looking at
//another student's
//posting. You will be graded on the quality of your postings: good clean
//indentation, good naming
//of variables, methods, classes, and so forth.
publicstaticvoid main(String[] args)
//1. create an array of ten cups as specified above. 5 small and 5 large
//
//2. Define the private static variables for Vector ArrayList and LinkList
//3. Copy the contents of the array of cups into the Vector ArrayList and LinkList
{
int cups[][] ={{0,0},{0, 0},{0,0},
{0,0},{0,0},{1,1},{1,1},
{1,1},{1,1},{1,1}};
//int cups[] = new Cup[10];
Vector cupVector =new Vector();
for(int i=0; i><cups.length; i++);
cupVector.add(cups);
printCupVector();
System.out.println(cupVector.toString() );
//copy a cup into the Vector
//copy a cup into the ArrayList
//copy a cup into the LinkedList
}
/* Main.java will contain a class Main.
/** Creates a new instance of Main */
}
/*
* Cup.java
*
* Created on May 21, 2007, 12:41 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author P
*/
publicclass Cup{
//Define the class Cup with the instance variables:
private String cupSize;//cupSize will be set to "small" or "large" for
//ounces in the constructor
private String cupMaterial;// will be set to "plastic" or "paper" in the
//constructor
privateint sizeCode;
privateint materialCode;
publicstaticfinalint LARGE = 1;
publicstaticfinalint SMALL = 0;
publicstaticfinalint PAPER = 1;
publicstaticfinalint PLASTIC = 0;
//The Cup constructor will be coded in the following way. Copy and paste this
//code into your Cup class.
//public Cup(String cupSize, String cupMaterial){
// this. cupSize = cupSize;
// this.cupMaterial = cupMaterial;
// if(cupSize.equals("large"))
//sizeCode = LARGE;
// else
//sizeCode = SMALL;
/** Creates a new instance of Cup */
public Cup(String cupSize, String cupMaterial){
this. cupSize = cupSize;
this.cupMaterial = cupMaterial;
if(cupSize.equals("large"))
sizeCode = LARGE;
else
sizeCode = SMALL;
if(cupMaterial.equals("paper"))
materialCode = PAPER;
else materialCode = PLASTIC;
}
//
}
>

