KimJack -2 Junior Poster

For some reason this method prints out an extra integer at the bottom. For example: It is supposed to only print out 4 x4.

20 20 20 20
20 20 20 20
20 20 20 20
20 20 20 20
20

Any idea how to remove the extra character?

public void gridOfChars(int gridSize) {
        for (int i = 0; i < 2; i++) {
         for (char n = 'A'; n <= 'Z'; n++)
         {
            gameList.add(n);
         }      
      }
      shuffle(gameList);     
      copyGameList = gameList.subList(0, (gridSize * 2));     
      temp = new ArrayList<Character>(copyGameList);     
      temp2 = new ArrayList<Character>(temp);      
      temp.addAll(temp2);       
      shuffle(temp);      
      gameList = temp;        
   	
   
      //displays grid of chars for text display
      int newLine = 0;
      for (int a = 0; a <= (gridSize * gridSize); a++) {
         newLine++;
         System.out.print(" " + gameList.get(a));
         
         if (newLine == gridSize) 
         {
            System.out.println();
            newLine = 0;
         }
      }
    }

Any assistance will be great thanks, Kimjack.

KimJack -2 Junior Poster

Thanks everyone. Just needed a little psuedocode to gain some understanding.

KimJack -2 Junior Poster

I have read it many times, if I understand all I would not be asking for assistance. If you cannot provide assitance without being rude, I would rather you not respond at all.

masijade commented: Very pampered student with an over blown sense of entitlement -2
KimJack -2 Junior Poster

I understand how to get elements from an array. I am working on the display. How to display elements of an array at certain positions. If charA and charB are matches then display the positions of the array along with the correctly matched elements as such:

1, 2, 3, 4, T, 6, 7, T, 9

if charA and charB do not match display:
1, 2, 3, 4, 5, 6, 7, 8, 9

Thanks in advance for any suggestions from all.

Kimjack

KimJack -2 Junior Poster

Hi all,

I wondering how to get started with this. I am working on a method that will take two ints. These ints represent positions in an arraylist of characters. I am trying to determine if the elements of the two positions are equal. If, so display the elements, if not display the int position. For example f the arraylist is as follows:

ArrayList<Character> list = new ArrayList<Character>();
list.add('a');
list.add('f');
list.add('c');
list.add('a');
list.add('s');

and the method is:

public void matchElements(int charA, int char)
{
//(psuedocode)
if(list.get(charA).compareTo(list.get(charB) == 0)
display charA and charB
else
display position of charA and charB
}

Any suggestions will be greately appreciated.

Thanks,
Kimjack

KimJack -2 Junior Poster

hmm, I have never heard of an array of Character. Would you provide an example?

KimJack -2 Junior Poster

Here is a snippet of code:

Array<Character> letters = new ArrayList<Character>();
char[] characters =  new char[row * col];
...

public void createShuffleLetters()
	{
		//create letters
		for(char ch = 'a'; ch <='z'; ch++)
		{
			letters.add(ch);
		}
		//shuffle
		Collections.shuffle(letters);
		
		//convert arrayList to array
		letters.toArray(characters);		
	}

The line in red seems as if it should work, but I get the following error:
The method toArray(T[]) in the type ArrayList<Character> is not applicable for the arguments (char[])

I am trying to take an arraylist of characters and shuffle them then convert that arraylist to an array of chars. Any suggestions will be great.

Thanks,
Kimjack

KimJack -2 Junior Poster

Hi All,


Is it possible to convert an arraylist of chars to an array? For example:

ArrayList<Character> array = new ArrayList<Character>();

Can this be converted to an array of chars. I have tried using the toArray method but it is not working. Does anyone have any suggestions?

Thanks,
Kimjack

KimJack -2 Junior Poster

This is great, but how would I go about preventing duplicates when the array is randomized?

KimJack -2 Junior Poster

This was was not working for me.

Here is what I have so far. In stead of printing it out in one row how can i get it to print in both rows and colomns. For example:

A B C D
E F G H
I J K L
...

Thanks

public void randomChars()
	{
		 ArrayList<Integer> list = new ArrayList<Integer>();
         int i = new Random().nextInt(letters.length);
         for(; list.size() != letters.length; i = new Random().nextInt(letters.length)) {
            if(!list.contains(i)) {
               System.out.print(letters[i]+" ");
               list.add(i);
            }
         }
KimJack -2 Junior Poster

Hi,

This is a very simple question. Is it possible to print a one dimensional array into the shape of a grid?

For example if I have the follow array:

chars arrayofChars[] = {'A', 'B', 'C', 'D', 'E'...};

how can it be printed out as

A B C D
E F G H
I J K L
...


I can print it out as a 2d array but prefer to use a 1D array if possible.

Any suggestions will be great.

Thanks,

Kimjack

KimJack -2 Junior Poster

Yes, I think I got it. Thanks

KimJack -2 Junior Poster

Hello,

I am working on a plain old simple text version of a memory game.
The player will be able to match letters of the alphabet by clicking on various numbers. For example

This is what the player will see:

123
456
789

but underneath that will be something like:

ABF
DFA
BDA

If user enters 1 and 6 they get a matching set and the letters underneath will display, if the user enters 3 and 4 the letters underneath will not display.

I am wondering what is the best way to go about programming a game like this. Should I use an array, 2d array, or arraylist. Any suggestions or examples will be wonderful

Thank you,
Kimjack

KimJack -2 Junior Poster

Hi all,

I have a quick question. Is this a proper way of using blackbox testing to test the stringTokenizer class? If not, would you provide a proper example that displays the pass or fail.

string = "cat, dog";
    StringTokenizer token = new StringTokenizer(string, ",");	     
         if (token.countTokens() == 2)
	System.out.println("Passed");
	     else {
	     System.out.println("Fail");	     
	     }

Thanks, KimJack

KimJack -2 Junior Poster

Hi,

I really hope that someone can give me a little advice. I am working on a program that reads a text file formatted as follows:

Bike, Schwinn, 45.00
Car, Mercedes, 98,000
...

I am writing a program that will read this text file and write each item in a seperate JMenu for user selection. For example each JMenu will house one column of information.

So far I have created the JMenus, added them to a frame and am reading the file to the console. My question is that instead of reading to the console how would I get this informaton into the JMenus. I am using the BufferedReader and the FileReader to read the file and using a StringTokenizer to parse the lines.

Any suggestions will be great.

KimJack

KimJack -2 Junior Poster

I really hope that someone can provide some suggestions or help to guide me in the right direction.
I am trying to use a scanner to parse a string and use its elements with methods. It is formatted as so:

String line = "Mercedes, 124 124.11, 45";

When I parse the string, I get a java.util.InputMismatchException

here is a snippet:

Scanner line = new Scanner(line);
                line.useDelimiter(",");
                
                while(line.hasNext())
                {
                	String car = line.next();                	
                	int id = line.nextInt();
                	double serial = line.nextDouble();
                	int code = line.nextInt();         	
                }

Any suggestions will be a hugely appreciated.

KimJack -2 Junior Poster

Hello,

I have a text file that is formatted as such:
Volkswagen, 547, 9.78, 2
Mercedes, 985, 45.77, 35
...

I am trying to figure out how use the Scanner to read from the text file and store the information into an ArrayList of objects.

ArrayList<Car> cars = new ArrayList<Car>();

I would then like to be able to use each element of the arraylist individually. For example:


cars.getName();
cars.getSerial();
...

Here is what I have so far:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class ScannerTest 
{
    public static void main(String[] args) {

       ArrayList<Car> cars = new ArrayList<Car>();
       
        File file = new File("car.csv");       
        
        try {
           
            Scanner scanner = new Scanner(file).useDelimiter(",");
            
            while (scanner.hasNextLine()) 
            {
                String line = scanner.nextLine();
                String name = scanner.next();
                int serial = scanner.nextInt();
                double itemCost = scanner.nextDouble();
                int itemCode = scanner.nextInt();                
                               
                System.out.println(name);           
               
                
            }//while
        } //try
        catch (FileNotFoundException e) 
        {
            e.printStackTrace();
        }
        
    }
}

For some reason, I am getting a Mismatch input error and the items are not being added to an arraylist for proper usage. Is there a better method to using the file elements individually?

Any assitance will appreciated.
Thank you

KimJack -2 Junior Poster

Thanks all, it works fine, but I am curious as to why eclipse gives the error but not JGrasp.

KimJack -2 Junior Poster

There must be some sort of error in Eclipse, because it is the only one that gives this error. However, I moved over to JGrasp and it works fine with your solution.

Is there any way to add a 0 for the minutes to keep the time formatted properly?

For example: if minutes are less than 10 it should display 12:08 instead of 12:8

Thanks

KimJack -2 Junior Poster

Thanks, I tried that but still get the same error. Any other suggestions?

KimJack -2 Junior Poster

Hello all,

I am trying to display time in the following format that represents hours and minutes:
hh:mm

public String getTime()
      {
        String time = String.format("%tI:%tM", hours, minutes);     
      
       return time;
      }

For some reason I keep getting the following error:
"The method format(String, Object[]) in the type String is not applicable for the arguments (String,
int, int)". Both time and minutes are integers. I am not sure what the problem could be. Any assistance will be appreciated.

Thanks Kim

KimJack -2 Junior Poster

Hello All,

I really hope that you can help me. I am working on a program that will read a randomaccess file's contents and store the contents into an array. It will then update the array and write it back into the randomaccess file. I have the following two methods and am not sure how to get them to read from a Randomaccessfile into an array and from an array back to a randomaccessfile.

/**
      Writes a savings account record to the data file
      @param n the index of the account in the data file
      @param account the account to write
   */
   public void write(int n, BankAccount account)
         throws IOException
   {  
      file.seek(n * RECORD_SIZE);
      file.writeInt(account.getAccountNumber());
      file.writeDouble(account.getBalance());
      byte[] buf = new byte[BankAccount.SIZE];
      file.write(buff);
   }
	
	
	
 /**
      Reads a savings account record.
      @param n the index of the item in the data file
      @return a savings account object initialized with the file data
   */
   public BankAccount read(int n)
         throws IOException
   {  
      file.seek(n * RECORD_SIZE);      
      int accountNumber = file.readInt();
      double balance = file.readDouble();
      byte[] buf = new byte[BankAccount.SIZE];
      file.readFully(buf);
      return new BankAccount(accountNumber, balance);
   }

Any help will be appreciated.
Thanks, Kim

KimJack -2 Junior Poster

Thank you for all of the help.

KimJack -2 Junior Poster

Hello All,

I am working on a simple program that will counts the number of matches found. I then need to display the text of the last successful pattern and the text the preceeds the last successful pattern match. This is where my problem is. How can I get these matches to display?

Here is my code so far:

#!/usr/local/bin/perl
use English;

$string = "This is my string this is it.  I want to tie my string";

$count = 0;

while ($string =~ m/[string]/gi)
{
  $count=$count+1;
}

print "$count strings\n";
print "\n Match: $MATCH";
print "\n PreMatch: $PREMATCH";

Any assistance will be greatly appreciated.

Thanks,

KimJack -2 Junior Poster

Here is the code which is in a table. Any help will be appreciated.

<table width="92%" border="0">
                     <tr>
                        <td width="61%" bgcolor="#FFFFFF"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','600','height','400','src','SimonGirtyTab/GirtyFlipper','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','Simon/Simon' ); //end AC code
                        </script>
                           <noscript>
                           <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="600" height="400">
                              <param name="movie" value="Simon/Simon.swf" />
                              <param name="quality" value="high" />
                              <embed src="SimonGirtyTab/GirtyFlipper.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="600" height="400"></embed>
                           </object>
                           </noscript></td>
                        <td width="7%" bordercolor="#000000">&nbsp;</td>
                        <td width="32%" align="left" valign="top" bordercolor="#000000"><p align="center" class="style12">&nbsp;</p></td>
                     </tr>
                  </table>
KimJack -2 Junior Poster

Hello all,

I have a problem that I hope some one can assist me with. I have a site done in html and css that also has swf files embedded. It works great on Internet Explorer, but Firefox is another story. The swf file is a page flipper and in firefox the pages takes turns working. A page that works on one visit will not work on another visit, but all work fine in Internet Explorer.

I have all of the necessary plugins for firefox and have used both embed and object tags for the swf files. I am not sure what else the problem could be.

Any solutions would be great.

Thanks,

KimJack

KimJack -2 Junior Poster

Hello All,

I am fairly new at this but I am trying to add drop caps to each paragraph of text that will be included in a text scrollbar.
I have tried eveything that I can think of.

I created the text document in Adobe inDesign; however the file that inDesign creates cannot be imported into Adobe Flash for use in a text scroll bar.

I also tried creating the text in Adobe Flash and using another text box to add what looks like drop caps and change this into a movie clip. I then added the movie clip to the scrollbar and well, the font is not formatted properly. It changes and does weird things.

Can anyone help me. Here is an example of what I would like to put into a scroll bar that will be added my webpage. The bold red letter would be of larger text, which is the drop cap.

Hello, This is a test. Test

Is this the test?

Any suggestions would be appreciated.
Thanks

KimJack -2 Junior Poster

Hi,

I am working on a sort of stack calculator. If anyone can suggest a better method please advice:

Basically, using the stringtokenizer to break the string into tokens. If the token does not equal "add" or "sub" or if the token is a digit push it onto the stack... proceed to methods...

I believe that the problem is with the bolded section. I think it has something to do with the fact that I switched to using chars instead of the entire token. If the omit the bolded section and replace it with

stack.push(token);


and simply push it onto the stack it works fine; however, it does not meet my requirements. Can anyone advise on how to determine if a token is "add", "sub" or is a digit?

if(!token.equalsIgnoreCase("add")) 
        if(!token.equalsIgnoreCase("sub")) 
               {
                 [B] for(int i = 0; i < token.length(); i ++)
                  if(Character.isDigit(token.charAt(i)))
                  stack.push(token);    [/B]    
                }
                
                  if(token.equalsIgnoreCase("add"))
                  add();
               
                if(token.equalsIgnoreCase("sub"))
                  subtract();

Any assistance will be appreciated.

Thanks

KimJack -2 Junior Poster

So the basic question that I would like to ask is: In the job sector, who would have the bigger salary and who whould move up in a company faster, CS or CIS degrees?

I am currently a senior in CIS (which is offered as a BS in my school's Computer Science department)and am contemplating switching to CS , at this point in my education, do you all think that it is wise to change majors?

KimJack -2 Junior Poster

This is the line the received the exception:

hash2.put(info,((Item)hash.get(info)).getDescrip());

Well, "info" is infact a substring from a string entered by the user and getDescrip() returns a string from the Item class.

The Item class is alot of code but simply a class full of methods that sets up everything. get this, get that, set this, set that, basic stuff. Here is the getDescrip() method from the Item class:

public String getDescrip()
      {
         return description;
      }

But it also extends a Dictionary class that contains the hashtable that I HAD to create myself. Here is my "homemade" put and get method from the Dictionary class that is extended from the Item class.

Item extends Dictionary
.....

public void put(Object key, Object value)
       {
          int bucket = hash(key); 
          ListNode list = hashTable[bucket];    
          while (list != null)
          {
                
             if (list.key.equals(key))
                break;
             list = list.next;
          }
          if (list != null)
          {
             list.value = value;
          }
          else
          {
             
             if (count >= .50 *hashTable.length)
             {
                doubleHash();
             }
             ListNode newNode = new ListNode();
             newNode.key = key;
             newNode.value = value;
             newNode.next = hashTable[bucket];
             hashTable[bucket] = newNode;
             count++;          }
       }
    
   
   
   
   
       public Object get(Object key)
      {
         int bucket = hash(key); 
         ListNode list = hashTable[bucket]; 
         while (list != null) {
            if (list.key.equals(key))
               return list.value;
            list = list.next; 
         	
         }
         return null;  
      }

That's it. Thanks for all your help.

Glad to hear that you got everything up and running.

KimJack -2 Junior Poster

Thanks Ezzaral,
It worked exactly as you described however I am now receiving the following error that I am trying to figure out:

Exception in thread "main" java.lang.ClassCastException: java.lang.String

This how I set up the previous code:

if(hash.containsKey(info))
    {
      hash2.put(info,((Item)hash.get(info)).getDescrip());
    }

Thanks to all for your assistance.

KimJack -2 Junior Poster

I have tried the following:

if(test.containsKey("mouse"))
      {
          test2.put("mouse", (test.getDescrip()));
                          
      }

This this code only "mouse" gets put into the hashtable as the key and value is simply null.

I tried the suggestion from Ezzaral, however, that set up will not allow me access to the getDescrip().

Are there any other suggestions or additional information that I can provide?

Any assistance will be greatly appreciated.

Thank you,

KimJack -2 Junior Poster

No prob JavaAddict,

I started a new thread because the old one started to get a bit confusing and unorganized. I was starting to confuse myself with all of the changes that I was making (thinking that I had figured it out, when actually it just "seemed" that I had).

Thanks for your comments and help.

KimJack -2 Junior Poster

Thanks for your help Ezzaral.

KimJack -2 Junior Poster

Hello All,

How can I get the information that corresponds with the containsKey to be put into the hashtable.

I am checking to see if a hashtable contains a key. If it does how can I put that key along with its value into a second hashtable.


Snippet of code:

for(int i = 0; i < 7; i ++)
     {
         if(hash.containsKey("elephant"))
         {
            hash2.put(hash.t.animals[i].getName(), hash.t.animals.item[i]getDescrip());
         }
     }

For example if "hash" containsKey "elephant". Search the array for elephant and "put" "elephant" and its description into hash2. The "elephant" is in .....getName() and description of the elephant is in .....getDescrip().

elephant would be the key and its description would be the value.

Any suggestions would be appreciated.

Thanks,

KimJack -2 Junior Poster

Just at a glance there are numerous issues. You need to fix the obvious things then resubmit your code within code tags to allow for ease of reading.

KimJack -2 Junior Poster

All are type Objects with the exception of "info", which is a String read from user input. Of course hash and hash2 represents the hash tables.

KimJack -2 Junior Poster

Well, I have made some progress. But it still will not "remove" the item from the hashtable.

this is how I used the put method:

hash2.put(hash.get(info), hash.getDescrip());

However when I use the remove method it will not remove the info from the hashtable.

Any suggestions?

Thank you,

KimJack -2 Junior Poster

The problem has to be with how I am using the put method. When I test the put method with simple strings it works fine.

KimJack -2 Junior Poster

How is this? I still have the same problem. It will not go into the hashtable.

for(int i = 0; i < 7; i++)
                        {
                          if(hash.containsKey(info))
                           {
                           hash2.put(hash.t.car[i].getName(), 
                           hash.t.car[i].getDescrip());
                                        
                           }
                        }
KimJack -2 Junior Poster

Hello All,

I really hope that someone can provide some assistance.

I have read a XML file into my hashtable. Next I created a second hashtable. If a key is located in my first hashtable, I want that key along with its value to be inserted into the second hashtable.

For example the code below: if hash contains the key "info" put the key "info" along with its value into hash2. However when it it displayed I want to display the value, which is the description.

for(int i = 0; i < 7; i++)
       {
           if(hash.containsKey(hash.get(info)))
                 {
                    hash2.put(hash.t.car[i].getName(), 
                    hash.t.car[i].getDescrip());
                              
                   }   
       }

This is done so when I try to remove a key I can just test for the key "info" and remove the value, which is description.

if(hash2.containsKey(info) )
         {
            hash2.remove(info);
         }

The problem is that when I try to "put" items into the hashtable they simply will not go into the hashtable. What am I doing wrong?

Any assistance will be greatly appreciated.

Thanks

KimJack -2 Junior Poster

Does any one know of any good websites that explain hash tables in great detail?

Thanks

KimJack -2 Junior Poster

Hello All,

I am using a stringtokenizer to divide a string while comparing each word in the string to a specific word and pushing it onto a stack. I can push it onto the stack with no problems; however, I cannot get it to find the specific word.

for Example:

String a = "I am here and there I go."

I need to find the word "there" in order to proceed with the rest of my program.


Here is a snippet of my code:

StringTokenizer temp = new StringTokenizer(a);
         while(temp.hasMoreTokens())
         {
         if(!temp.nextElement().equals("there"))
            stack.push(temp.nextElement());
         }

Any assistance will be appreciated.

KimJack -2 Junior Poster

H..

KimJack -2 Junior Poster

Thanks

KimJack -2 Junior Poster

Thanks for the reply. Are there any real differences between Eclipse and NetBeans?

KimJack -2 Junior Poster

I have been using Eclipse for quite some time to program. I have been told that NetBeans is a little better. The problem that I am having is that I can't figure out how to get a program into NetBeans for further programming.

Can anyone explain these steps?

Thanks,

KimJack -2 Junior Poster

Hello All,

I am using a stack to create a sort of calculator.

My input string will be "5 6 add"

I have to push 5, push 6, and when I get read "add" pop 5 and 6 and and push the answer.

The question is after the string is broken up by the whitespaces, how do I compare each individual part to the string "add" so when it is equal to "add" it will pop the 5 and 6 and I can continue on with my next step?

For example:

is "5" equal to "add" - no, push onto stack
is "6" equal to "add" - no, push onto stack
is "add" equal to "add" - yes, pop 6, pop 5 and (continue)

Any assistance will be appreciated.

Thanks,

The question I have is when I push 5 and push 6, when I get to "add" how to I use it ias a comparison

KimJack -2 Junior Poster

There is another version of putty. Thanks for the comment but I figured it out.

Thanks

KimJack -2 Junior Poster

Hello All,

I am trying to use an image as a background. I am working with perl through putty .58 and am wondering how to get an image into a specific location in putty that can be used in a perl webpage?

Thanks,