Printing a listing from an array of objects

I know I'm missing something simple here but for the life of me I can't spot it. The code below should print a list of student names to the screen. At the moment it only prints the last name entered into the array. I will kick myself when I see the answer but can anyone suss this out ? Many thanks for any help.
// A Program called StudentDetails3.java which inserts student names into an array according to
// a calculated hash Index and then prints out the name list in this order
import javax.swing.JOptionPane;
public class StudentDetails3
// Member Section
// Private members
private static String studentName;
// Public members
public static String input = JOptionPane.showInputDialog(" Please enter the number of students in the class : - ");
public static int maxNum = Integer.parseInt(input);
public static int hashIndex = 0;
// Constructor Section
StudentDetails3 ( String newStudentName )
studentName = newStudentName.toUpperCase();
// Method Section
public int hashCalc()
int total = 0;
for( int charNo = 0; charNo < studentName.length(); charNo ++ )
char letter = studentName.charAt(charNo);
int asciiVal = letter;
     if( studentName.charAt(charNo) ==' ')
     asciiVal = 0;
     total = total + asciiVal;
hashIndex = total % maxNum;
return hashIndex;
public void output()
System.out.println(" The student's name and hash index is " + studentName + " " + hashIndex );
static class DetailsStorage
// Member Section containing the array into which the student objects will be inserted
private Object [] array;
private int current;
// Constructor
DetailsStorage ( int noOfStudents )
array = new Object[ noOfStudents ];
current = 0;
// Method for adding name to array
public void add ( Object StudentDetails3 )
{  if ( array [ hashIndex] == null )
array [ hashIndex ] = StudentDetails3;
else if ( (hashIndex + 1) <= (array.length-1) )
do
{ hashIndex = ( hashIndex + 1 );
     if ( array [ hashIndex ] == null )
     {   array [ hashIndex ] = StudentDetails3;
     break;
} while ( (hashIndex + 1) <= (array.length-1) );
     else
          for ( int firstLp = 0; firstLp < array.length; firstLp ++ )
     if ( array [ firstLp ] == null )
     {   array [ firstLp ] = StudentDetails3;
               break;
public void printOut ( )
{   int loop = 0;
System.out.println ( " Name\t\tCourse " );
System.out.println ( "____\t\t_________ " );
     for ( loop = 0; loop < array.length; loop ++ )
     System.out.println ( ( ( StudentDetails3 ) array [ loop ] ).studentName );
// Main Program for testing
public static void main( String[] args )
{   String  name;                                              
// Obtain list of names from the user
DetailsStorage nameList = new DetailsStorage( maxNum );
for( int lp = 0; lp < maxNum; lp++ )
{   name =  JOptionPane.showInputDialog(" Please enter the name of student in full ( e.g. Gareth Edwards )");
StudentDetails3 newDetails = new StudentDetails3( name );
newDetails.hashCalc();
     nameList.add ( newDetails );
newDetails.output();
nameList.printOut();
System.exit(0);
}

You've made the student name a static field, which means that there's only one for the whole class.
So the last one you input is the one you use for everybody.

Similar Messages

  • Constructing a linked list from an array of integers

    How do I create a linked list from an array of 28 integers in a constructor? The array of integers can be of any value that we desire. However we must use that array to test and debug methods such as getFirst(), getLast(), etc...
    I also have a method int getPosition(int position) where its suppose to return an element at the specified position. However, I get an error that says cannot find symbol: variable data or method next()
    public int getPosition(int position){
         LinkedListIterator iter=new LinkedListIterator();
         Node previous=null;
         Node current=first;
         if(position==0)
         return current.data;
         while(iter.hasMore()){
         iter.next();
         if(position==1)
         return iter.data;
         iter.next();
         if(position==2)
         return iter.data;
         iter.next();
         if(position==3)
         return iter.data;
         iter.next();
         if(position==4)
         return iter.data;
         iter.next();
         if(position==5)
         return iter.data;
         iter.next();
         if(position==6)
         return iter.data;
         iter.next();
         if(position==7)
         return iter.data;
         iter.next();
         if(position==8)
         return iter.data;
         iter.next();
         if(position==9)
         return iter.data;
         iter.next();
         if(position==10)
         return iter.data;
         iter.next();
         if(position==11)
         return iter.data;
         iter.next();
         if(position==12)
         return iter.data;
         iter.next();
         if(position==13)
         return iter.data;
         iter.next();
         if(position==14)
         return iter.data;
         iter.next();
         if(position==15)
         return iter.data;
         iter.next();
         if(position==16)
         return iter.data;
         iter.next();
         if(position==17)
         return iter.data;
         iter.next();
         if(position==18)
         return iter.data;
         iter.next();
         if(position==19)
         return iter.data;
         iter.next();
         if(position==20)
         return iter.data;
         iter.next();
         if(position==21)
         return iter.data;
         iter.next();
         if(position==22)
         return iter.data;
         iter.next();
         if(position==23)
         return iter.data;
         iter.next();
         if(position==24)
         return iter.data;
         iter.next();
         if(position==25)
         return iter.data;
         iter.next();
         if(position==26)
         return iter.data;
         iter.next();
         if(position==27)
         return iter.data;
         iter.next();
         if(position==28)
         return iter.data;
         if(position>28 || position<0)
         throw new NoSuchElementException();
         }

    How do I create a linked list from an array of 28 integers
    in a constructor? In a LinkedList constructor? If you check the LinkedList class (google 'java LinkedList'), there is no constructor that accepts an integer array.
    In a constructor of your own class? Use a for loop to step through your array and use the LinkedList add() method to add the elements of your array to your LinkedList.
    I get an error that
    says cannot find symbol: variable data or method
    next()If you look at the LinkedListIterator class (google, wait for it...."java LinkedListIterator"), you will see there is no next() method. Instead, you typically do the following to get an iterator:
    LinkedList myLL = new LinkedList();
    Iterator iter = myLL.iterator();
    The Iterator class has a next() method.

  • Determining which method to call from an array of Objects

    Hi All,
    Lets suppose I have an interface, a string method name, and an array of Objects indicating the parameters which should be passed to the method.
    What Im trying to work out is a way to quickly determine which method should be invoked.
    I can see that Class has getDeclaredMethod(String, Class[]), but that wont help me as I dont know the formal class types (the method may take X, but I might get passed Y which extends X in the array of objects).
    Does anyone know of a quick way I can determine this?
    All I can think of at the moment is going thru each method of the class one by one, and seeing if the arg is assignable, then, after getting all my matched methods, determining if there are any more 'specific' matches.
    Any ideas?
    Much appreciated,
    Dave

    you might want to take a look at the dynamic proxy apiCheers for the suggestion, but Im actually already using the dynamic proxy API.
    What I have is a MockObjectValidator which allows mock objects to be configuered with expected calls, exceptions to throw etc etc.
    I thought developers on my project would get tired using an interface like this:
    myValidator.setExpectedCall("someMethod", new Class[] { typeA, typeB }, new Object[] { valueA, valueB} );
    I.e, I wanted to cut out having to pass the class array, so they could just use:
    myValidator.setExpectedCall("someMethod", new Object[] { valueA, valueB} );
    The problem there is that I then need to pick the best Method from the class given the object arguments.
    When the mock object is in use, its no problem as the InvocationHandler interface provides the Method. The problem I have is selecting what method a user is talking about from an array of Objects.
    Ive written a simple one now, it just does primitive type class -> wrapper substitution, and then finds ** A ** match. If there is more than one match (ie, all params are assignable to a class' method params), I dont let that method be used.
    Shortly I'll update it to actually make the correct selection in those cases.
    cheers
    Dave

  • Error printing pick list from IW32

    Hi all,
    When trying to print pick list from transaction IW32, I get this error message:
    Express document "Update was terminated" received from author ...
    When I checked out this error message in SM13, I found this:
    Transaction code: IW32
    Module name (function): PM_ORDER_PRINT_CONTROL
    Status: Update was terminated
    Raise exception: KEY_NOT_FULLY_SPECIFIED (Complete key not entered)
    The shop paper (pick list) is customer defined (Z*) under application area O (Maintenance orders). This shop paper is set up to print to a certain printer, P1, and printing other PLM documents on this output device works fine.
    Does anyone have an idea what can be causing this error?
    All helpful answers will be rewarded.
    Best regards,
    MV

    Hi,
    I have tried to print the pick list several times, in development, test, and production systems. It fails with the same error each time.
    Do you have any ideas why this error occurs, is there any special IMG activity or PLM configuration that I could check to see if some printer settings are wrong?
    Regards,
    MV

  • Print event list from iCal

    I manage different calendars, private, work, hobby etc.
    Now, I would like to print a list of upcoming events from one of those calendars.
    My iPhone has a "list" option that does exactly what I want, but I can't print that.
    I have tried File/Print selecting only the wanted calendar and a date span, but I don't get the expected result.
    iCal will print ALL the days within the time span, including dates with no entry. I would like to see only a list with events...
    Is this possible in iCal?

    The only way I have found takes a few steps, but it is not too complex.
    - It requires the desired events to have a common set of characters in each event so the Search function will pull them out together (e.g., xxx, day, class, etc.).
    - These common characters can be in the main event text box at the top of the event, or they can be anywhere in the event (in the location field, in the note section of the event at the bottom, etc.)
    - Next, be sure the Calendar is selected on which these events are listed (top left corner click on Calendars and put check in the appropriate box(es).
    - Next, click in the Search box in the top right of the main Calendar window and type the common characters set you entered in all the events (e.g., day).
    - This opens a window pane at the bottom of the Calendar window.  To make the window pane larger click on the top of the window pane and drag it towards the top of the screen.
    - In the window pane is a list of all the events that meet your search criteria.
    - Click on all the events you want to print (<shift>mouse click on a range and <command>mouse click work here)
    - Select print Calendar (File/Print, <cmd>P, ...)
    - In the print window, first select or unselect the Calendars to print (so only the desired Calendar keys print)
    - Next, in print window, at top in View, select "Selected Events"
    - Select the print options you want
    - Click on Continue, with takes you to the Printer window, and select the print and click Print (or PDF)
    Done!
    I believe this is much harder than it should be. I haven't yet found a 3rd party app that makes this any easier.

  • Printing a list from Contacts via Pages

    I'm not sure if this is an Address Book question or a Pages question, but I am posting it here.
    I want to print a list of my contacts from the Address Book via Pages so I can format it appropriately. I have looked at mail merge, but that seems to insist on a page break between each record. what's the best way to do what I am trying to achieve ?

    Thanks, but having read it that looks a rather long winded and clumsy approach to the problem.
    Actually, I've just done a bit more Googling on the problem and I realize there is a print option I was overlooking (when I expand the print options) that will create a list of all contacts.
    Hmm, looked at that a bit more and there is not much control over which fields are included, won't really do the job.
    Is there really no off the shelf Apple solution to what seems to me to be a pretty basic and frequently wanted requirement ?
    Message was edited by: tonydenson

  • Printing Picking list from LT31

    Hi all,
    I have to print a picking list from the TO & WH as input...
    i have created the smartform and a driver program with two input fields TO & WH.....
    and it worked perfectly....
    now user wants to use the tcode LT31 for printing ...now i want to know how to pass the values of TO & WH from screen of LT31 to my driver program...
    thnx
    RK

    Hi,
    There is a transaction called 'OMLV' . Here you have to configure your smartform as well as the print program. There is a program called RLVSDR40. You can use it of your own zprogram. This is a program for print control for warehouses with Storage Unit Management.
    In the print code , Warehouse Number segment  of OMLV you have give the 'Print program name' and Warehouse movement segment you have to pass your form name.
    You can ask your functional owner to do the configuration.
    Hope this will help u.
    Thanks,
    Abhijit
    Edited by: Abhijit Mandal on Jan 22, 2010 8:04 PM

  • Printing Contacts List from Backup Assistant Webpage.

    What is the trick to printing your contact list from the Backup Assistant webpage?
    I selected all contacts, then selected "Select All Contact" then clicked Go.
    I used no filters, and it shows I have selected all 156 contacts, but when I click on Go (to print), nothing happens. If I click Command P on my Mac, it just prints the 8 contacts on that page. There is no way to view all of my contacts at once, otherwise it would be easy to print them, but as it stands now, I would have to click on each Next Page to print them all, 8 contacts per page, meaning 19 pages...a colossal waste of paper.
    Anybody have an idea on this?

        drsdc
    I'm sorry to hear about the trouble you're having with printing your contacts! I definitely want to make sure you can get the details you need from your online contact info. Are you able to export the contacts instead? This may allow you to format them in a way you'd prefer to print them. http://vz.to/19joHKi
    RuthW_VZW
    Follow us on twitter @VZWSupport

  • Print Packing List from Delivery at Goods Issue

    We are facing an issue with our packing list for a division we are going live with in three weeks.  Our current business process for our plants already on SAP is to create the Packing List when the Delivery is created, with timing code "3" in the Packing List output condition, but to not print it until the "Check-in" button is clicked with the Shipment in VT02N based on an activity profile.
    However, for the service shipments in this division going live August 1, we do not need to create a Shipment nor generate a Bill of Lading from VT02N.  We will post goods issue from the Delivery itself, and we want the Packing List to print at the time of Post Goods Issue from the Delivery.  We have an access sequence for these service Deliveries with Shipping Point/Distribution Channel/Delivery Type, so only Distribution Channel 02 Deliveries will have Goods Issue from the Delivery, but we are not sure how to get the Packing List to not print until Goods Issue.  Any advice would be appreciated.
    Regards,
    Jeff Stewart

    Go to IMG>Logistics Execution>Shipping> Basic Shipping Functions>Output Determination> Maintain Output Determination for Outbound Deliveries.
         Select the Procedure you are using and check the control data to find the Cond. Type you are executing at the moment of the Outbound Delivery.
         Check the fifth column and see you have plenty of options, check them out helped by an ABAP team member; if there is nothing already there, just ask him/her to create a new routine with the validation you need and set it there.
    This is the same that Joao is suggesting I just went a little bit more in details.
    Good luck Jeff!

  • Print contact list from my blackberry??

    I'm trying to print all my address book from my black berry  8820.  i assume i connect it to  my computer but then what?
    thanks,
    Jim

    So what you need to do, is connect it to your computer, then Run the BackUp Program, so it saves a backup to your computer. Then you need to install ABC Amber BlackBerry Converter which is $19.95 from http://www.processtext.com/abcblackberry.html Or the demo verison only does 10 at a time. It can do eveything, make list, turn it into PDF HTML everything. There really is no free way to do this. But it shows everything! Like what buttons your pressed during calls, deleted text messages, just everything.

  • Printing Specific Lists from iPod

    I do DJ work and at times need to have (handout) lists by author, song title or album - even genre at times. I'm looking for a time efficient way to do this. I try grabbing all albums or artists in the Browser of iTunes but it gives me everything instead of a single list of all artists or albums. Any ideas would be appreciated

    actually that didn't work. for what I needed. I need a list of:
    A. Artists
    B. Albums
    C. Songs
    what I got going that route was a xml file that was huge and would take me months to deal with.
    My feeling is iTunes libraries look like excel files but I can't grab the needeed columns and manipulate them the way I want to. Quickly is the key here. Prior to a gig I would like to go for a genre and print what I need. and not get every song listed in the library.

  • Printing Contact list from BB Q10

    I have a BBQ10, how do I transfer the my contacts list to a printable file...?

    mslynn85 wrote:
    Third-party app, such as . . . . . . .
    Your profile states you have a 8220 Flip phone... check App World for a something In Touch Contacts app, if I recall it will backup and export to a CSV file.
    If you have a Q10 as this thread is about, App World has several, some for free, some paid. BackupPro is one.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Get a list of objects from an array

    I'm having trouble getting a list from an array.  I have an array (cardArray) that I load up with movieclips.
    I create the instances via: var card_01:RallyChaseCard = new RallyChaseCard();, card_02 etc.
    I want to be able to run a trace on the array and get a current listing and order of the cards inside.
    When I run trace(cardArray) all I get is a list like this:
    [object RallyChaseCard],[object RallyChaseCard],[object RallyChaseCard]
    How do I get it to list the contents buy their card names?
    This is one of those things that seems like it ought to be so obvious, yet is eluding me and my trial and error attempts to solve it.

    create a name property in your class and assign a name property to your instances (either in the contructor) and/or using getters/setters.  (you'll need a getter anyway.)

  • Help with printing from an array

    hello there, looking for help. Basically i have read a text file into an array. I can print a sentence from the array using startsWith()...if i take that code out, and just put in the last part:
    while(!(words.trim()).startsWith("slightly")) {
         System.out.println(i + ":" + words[i] + ":");
         i++;
    this basically prints out the whole text file until it reaches the word slightly. I want to print out text that is in between two words. Now i can stop printing with this , any suggestions on how i can tell it to start printing when it finds a word....
    public static void main( String[] args )
         int i = 0;
    // will store the words read from the file
    List<String> wordList = new ArrayList<String>();
    BufferedReader br = null;
    try
    // attempt to open the words file
    br = new BufferedReader( new FileReader( "ireland.txt" ) );
    String word;
    while( ( word = br.readLine() ) != null )
    // add the read word to the wordList
    wordList.add( word );
    } catch( IOException e ) {
    e.printStackTrace();
    } finally {
    try {
    // attempt the close the file
    br.close();
    catch( IOException ex ) {
    ex.printStackTrace();
    String[] words = new String[ wordList.size() ];
    // wordList to our string array words
    wordList.toArray( words );
    System.out.println(" Returning line ");
    // loop and display each word from the words array
    /*while(i < words.length )
         String tempWord = words[i].trim();
         //area
         if (tempWord.startsWith("'''Loc"))
              System.out.println(i+":"+ words[i]+":" );     
         i++;
    /*while(!(words[i].trim()).startsWith("slightly")) {
         System.out.println(i + ":" + words[i] + ":");
         i++;

    This may help, it looks like the same assignment:
    http://forum.java.sun.com/thread.jspa?threadID=5144211
    Yeah, and it's from the same guy.
    Thanks (NOT) for posting yet another thread about the
    same problem, tras.D'OH! I didn't even notice that. In what ways were the answers you got in the other thread insufficient?

  • Is there any way to print a list of what is in your Library?

    Is there any way to print a list from ipod 60gb video (either from the itunes screen or from my documents)? I'd really like to be able to see what I already have without having my ipod plugged in. Thanks!

    Boy I feel stupid! I really thought I'd checked the drop down menus. Oh well. Thanks!

Maybe you are looking for

  • HT2506 PDF edits made in Preview Invisible to PCs, Google Docs?

    Hi, Does anyone know why my edits in Preview using Lion are not visible to some PC users, and when uploaded to Google Docs? Thanks!         

  • Basic NOT EXISTS query not returning any results

    DB Version: 10gR2 One of our tables in the test schema is having less number of columns than the PROD shema. To determine which are missing columns in this table in Test schema i did the following. -----In Test Schema CREATE TABLE XYZ2 (COL1 NUMBER);

  • USB in cadillac escalade

    Has anyone got a Ipod Shuffle (Gen 4) to work in their 2010 Escalade?

  • Where is import button?

    I am just starting the trial. I have downloaded the sample pictures. Imagine my joy when the first thing to do... I can not do! There is no import button on the bottom left... just Copy or Paste.

  • Having Trouble Installing new adobe flash player

    I have tried to download the newest version a dozen times. I have uninstalled everything relating to flash player, and then I close ALL MY PROGRAMS, but for some reason, when I go to install it, I get an error message telling me that it couldn't inst