Tuning an application

From: Kris M (mRaEcMcOxVoApMhE_at_yahoo.com)
Date: 03/26/05


Date: Sat, 26 Mar 2005 17:28:35 -0500

any suggestions on how to improve this exercise in using vector?

//----------------------------------

//3-25-05

//Accessing and processing data from a vector

//

import java.io.*;

import java.util.*;

class P4

{

static Scanner input = new Scanner(System.in);

static PrintWriter screen = new PrintWriter(System.out, true);

static final int VECTORSIZE = 8;

static final int ROUNDS = 3;

static final int GAMES = 7;

public static void main(String [] args)

{

Vector<String> dataStore = new Vector<String>(VECTORSIZE);

dataStore = filledVector();

screen.println("Initial DataStore Contents");

displayVectorContents(dataStore);

screen.println("__________________________");

for(int round = 0; round < ROUNDS; round++)

{

screen.println("Round =" + (round +1));

dataStore = playRound(dataStore, round);

displayVectorContents(dataStore);

}

screen.println("Champion!");

}

private static Vector playRound(Vector v, int round)

{

Vector<String> rVector = new Vector<String>((v.capacity())/2);

for(int game = 0; game < rVector.capacity(); game++)

{

rVector.addElement(playGame((String)v.firstElement(),(String)v.lastElement()));

v.remove(v.firstElement());

v.remove(v.lastElement());

}

return rVector;

}

private static String playGame(String string1, String string2)

{

int compare = string1.compareTo(string2);

if(compare < 0)

return string1;

else

return string2;

}

private static Vector filledVector()

{

String [] names = {"Team 1" , "Team 2" , "Team 3" , "Team 4" , "Team 5" ,
"Team 6" , "Team 7" , "Team 8"};

Vector<String> v = new Vector<String>(VECTORSIZE);

for (int index =0; index < VECTORSIZE; index++)

v.addElement(names [index]);

return v;

}

private static void displayVectorContents(Vector v)

{

if(!v.isEmpty())

{

for (Enumeration e = v.elements() ; e.hasMoreElements() ;)

{

System.out.println(e.nextElement());

}

}

else

{

screen.println("Vector is empty");

}

}

}



Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Gcc compatible header file
    ... A string collection is a table of zero terminated strings that will grow ... typedef struct _StringCollection StringCollection; ... int; ... bool; ...
    (comp.lang.c)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Re: FTP CD command
    ... public const int GENERIC_WRITE = 0x40000000; ... string lpszProxyName, ... public static extern IntPtr InternetConnect ( ... public static extern bool FtpGetCurrentDirectory ( ...
    (microsoft.public.dotnet.languages.vb)