Help with creating a method within a class

I need help creating another method within the same class.
Here is part of my progam, and could anyone help me convert the switch statement into a seperate
method within the same class?
import javax.swing.JOptionPane;
public class Yahtzee
     public static void main (String[] args)
          String numStr, playerStr, str, tobenamed;
          int num, times = 13, roll, x, y, maxRoll = 3, z = 0, t;
          int firstDie, secondDie, thirdDie, fourthDie, fifthDie, maxDie = 5, reroll;
          int rerolling = 0, categoryChoice, score, nextDie1, nextDie2, nextDie3, nextDie4;
          Die die1, die2, die3, die4, die5;
          do
          numStr = JOptionPane.showInputDialog ("Enter the number of player: ");
          num = Integer.parseInt(numStr);
          while (num < 1 || num > 6); //end of do loop
          String [] player = new String[num];
          // boolean //finsih later to make category choice only once.
          for (x = 0; x < num; x++)
               playerStr = JOptionPane.showInputDialog ("Name of Player" + (x + 1) + " :");
               player[x] = playerStr;  
          } //end of for loop
          die1 = new Die();
           die2 = new Die();
           die3 = new Die();
           die4 = new Die();
           die5 = new Die();
          int scoring [][] = new int [num][13];//scoring aray
          int[] numDie = new int[maxDie];
          String[][] usedCategory = new String [num][times];
          for (x=0; x < 13; x++)
               for (y = 0; y < num; y++)
                  usedCategory[y][x] = " ";
          for (int choices = 0; choices < times; choices++)
               //player turns for loop.
               for (x = 0; x < num; x++)
                    //rolls the die;
                      for (y = 0; y < maxDie; y++)
                           numDie[y] =  die1.roll();
                 numStr = JOptionPane.showInputDialog (player[x] + "\n~~~~~~~~~~~~~~~~~~~~~~~"
                                                                        + "\nDie1: " + numDie[0]
                                                                            + "\nDie2: " + numDie[1]
                                                                            + "\nDie3: " + numDie[2]
                                                                            + "\nDie4: " + numDie[3]
                                                                            + "\nDie5: " + numDie[4]
                                                                            + "\nWhich dice do you want to reroll");
                reroll = numStr.length();
                if (reroll == 0)
                    t = maxRoll;
               else{                                                      
                //reroll
                     for(t = 0; t < maxRoll; t++ )
                         for (y = 0; y < reroll; y++)
                                rerolling = numStr.charAt(y);
                             //create another mwthod later.
                                switch (rerolling)
                                     case '1':
                                          numDie[0] =  die1.roll();
                                          break;
                                     case '2':
                                          numDie[1] =  die1.roll();
                                          break;
                                     case '3':
                                          numDie[2] =  die1.roll();
                                          break;
                                     case '4':
                                          numDie[3] =  die1.roll();
                                          break;
                                     case '5':
                                          numDie[4] =  die1.roll();
                                          break;
                                     default:
                                     t = maxRoll;//to be changed
                                } //end of switch class
                          }//end of reroll for loop
                               JOptionPane.showMessegeDialog (player[x] + "\n~~~~~~~~~~~~~~~~~~~~~~~"
                                                                                  + "\nDie1: " + numDie[0]
                                                                                      + "\nDie2: " + numDie[1]
                                                                                      + "\nDie3: " + numDie[2]
                                                                                      + "\nDie4: " + numDie[3]
                                                                                      + "\nDie5: " + numDie[4]
                                                                                      + "\nWhich dice do you want to reroll"
                                           switch (rerolling)
                                     case '1':
                                          numDie[0] =  die1.roll();
                                          break;
                                     case '2':
                                          numDie[1] =  die1.roll();
                                          break;
                                     case '3':
                                          numDie[2] =  die1.roll();
                                          break;
                                     case '4':
                                          numDie[3] =  die1.roll();
                                          break;
                                     case '5':
                                          numDie[4] =  die1.roll();
                                          break;
                                     default:
                                     t = maxRoll; //not really anything yet, or is it?
                                } //end of rerolling switch class
                                   //categorychoice = Integer.parseInt(category);
                          }//end of t for loop            
               }//end of player for loop.

samuraiexe wrote:
well, i should have said it is a yahtzee program, and i ask the user what they want to reroll and whatever number they press, the switch will activate the case and the array that it will reroll.
HOw would i pass it as an argument?You put it in the argument list. Modifying your original code a bit:
public static void switchReroll (int[] dice, int position) {
     switch (position) {
     case '1':
             dice[0] =  die1.roll()
             break;
     case '2':
             dice[1] =  die1.roll();
             break;
     case '3':
             dice[2] =  die1.roll();
                 break;
     case '4':
             dice[3] =  die1.roll();
             break;
     case '5':
              dice[4] =  die1.roll();
             break;
     default:
             t = maxRoll;//to be changed
    } //end of switch
}which you could then call as this:
switchReroll(numDie, reroll);Note that your code still isn't done; the above won't compile. This is just an example of how you could pass the stuff as an argument (and note how the values have different names in the main method than in the switchReroll method -- this works, but also note that it's the same array of ints in both).
By the way -- you really don't need a switch statement for this. You can do the same thing with a couple lines of code, which would lessen the advantage for a separate method. But I'd suggest continuing down this path, and then you could change the implementation of the method later.

Similar Messages

  • Help with Creating a method that takes a string of arrays?

    i just begin my intro to programming and im a little stuck we had to write a program yesterday and i managed fine then today we had to work with arrays and i dont know much about arrays so im hoping someone here can point me in the right direction. This is what he wants *"Create a method called "printReceipts" that takes a String array of names (first names only) and prints out a message to customers using their name and telling them what customer number they are. The method should work with an array of any size."*
    Im not asking you to do it for me just i gues point out what methods i need to change thanks
    package edu.nmhu.cs245;
    public class Assignment1 {
         private String messagePrefix1 = "Hello ";
         private String messagePrefix2 = ", \n";
         public String[] getName() {
              String[] names = new String[] {"Lonny", "Gil", "Hosein"};
              return names;
         public String getCompleteMessage(String name, String message) {
              String completeMessage = messagePrefix1 + name + messagePrefix2 + message ;
              return completeMessage;
          * @param args
         public static void main(String[] args) {
              Assignment1 a = new Assignment1();
              String[] names = a.getName();
              for (int i = 0; i < names.length; i++) {
                   String printReciepts = a.getCompleteMessage(names,"You are customer number#" +(i+1));
                   System.out.println(printReciepts);
                   System.out.println();

    Focus! You should know what every single line of code is supposed to do! And they should all add up to a larger goal.
    Don't just put in stuff that seems like it's part of a relevant example.
         public String[] getName() {
              String[] names = new String[] {"Lonny", "Gil", "Hosein","Sam"};
              return names;
         }Are you supposed to do it that way? Or did it come with the assignment? It's (probably) fine for a homework assignment, but it's hardcoded data, which in practice one normally doesn't do.
              String completeMessage = messagePrefix1 + names + messagePrefix2 + messageSuffix ;Why do this? You're supposed to produce a receipt per use, not for all users at one.
              for (int i = 0; i < names.length; i++) OK, good. You could have used a foreach loop but this is fine.
                   String printReciepts = a.getCompleteMessage(names,"You are customer number#" +(i+1));What is "getCompleteMessage"?  You didn't define it.  Do you think that it is created implicitly because of the local String variable you created called "completeMessage"?  It doesn't.           String2 a = new String2();Don't call your class "String2".  It doesn't mean anything.  Name it after the assignment or something.           a.printReceipts(names);"names" isn't defined.  There's a local variable called "names" in the getNames method, but it doesn't exist when you call this and it's unavailable anyway.  You probably meant to do           a.printReceipts(a.getName());                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • I need help with creating a rollover within an accordian

    I made a feature for my portfolio page..  when you click on an image inside an accourdian my portfolio will drop down.. the only thing im having trouble with is giving the illusion that the string is being pulled down i adjusted the states but when i preview it... theres no response to the rollover nothing is working...Please let me know Thanks so much,
    Joe

    Hello,
    Check this video : http://tv.adobe.com/watch/muse-feature-tour/muse-create-tabbed-and-accordion-panels/
    You can see the rollover state under states option here :
    You can double check your states and it will work as I have created a short video with image on all 3 stages : http://unidel.worldsecuresystems.com/surjeet/2013-10-28_1503.swf  Hope this helps!
    Cheers,
    Surjeet

  • Can someone help with this getPos method of aList class ?

    public class AList<T> implements ListInterface<T>
    private T[] entries; // array of list entries
    private int length; // current number of entries in list
    private static final int MAX_SIZE = 50; // max length of list
    public AList()
    this(MAX_SIZE); // call next constructor
    } // end default constructor
    public AList(int maxSize)
    length = 0;
    entries = (T[]) new Object[maxSize]; // necessary cast to generic type
    } // end constructor
         public boolean add(T newEntry)
              boolean isSuccessful = true;
              if (!isFull())
         // Assertion: Length of list < length of array
         assert length < entries.length;
         // position of new entry will be after last entry in list,
         // that is, at position length+1; corresponding array index is
         // 1 less than this position, so index is length
         entries[length] = newEntry;
                   length++;
              else
                   isSuccessful = false;
              return isSuccessful;
         } // end add
         public boolean add(int newPosition, T newEntry)
         boolean isSuccessful = true;
         if (!isFull() && (newPosition >= 1) && (newPosition <= length + 1))
         makeRoom(newPosition);
         entries[newPosition - 1] = newEntry;
         length++;
         else
         isSuccessful = false;
         return isSuccessful;
         } // end add
         public T remove(int givenPosition)
         T result = null; // return value
         if ((givenPosition >= 1) && (givenPosition <= length))
         assert !isEmpty();     
    result = entries[givenPosition - 1]; // get entry to be removed
         // move subsequent entries toward entry to be removed,
         // unless it is last in list
         if (givenPosition < length)
         removeGap(givenPosition);
         length--;
         } // end if
         return result; // return reference to removed entry, or
    // null if either list is empty or givenPosition
    // is invalid
    } // end remove
         public T getEntry(int givenPosition)
         T result = null; // result to return
         if ((givenPosition >= 1) && (givenPosition <= length))
         assert !isEmpty();
              result = entries[givenPosition - 1];
         } // end if
         return result;
         } // end getEntry
    public int getPos(T anItem)
    }

    I would recommend using a for loop to compare anItem to each member of the array. If you get a match, return the index.

  • Help with creating a Quiz

    Hey i need help with creating a quiz with scoring and all.
    I need a helping hand so if you can get me started that
    would help a lot.
    Use the Question class to define a Quiz class. A
    quiz can be composed of up to 25 questions. Define the add method
    of the Quiz class to add a question to a quiz. Define the giveQuiz
    method of the Quiz class to present each question in turn to the user,
    accept an answer for each one, and keep track of the results. Define
    a class called QuizTime with a main method that populates a quiz,
    presents it, and prints the final results.
    // Question.java Author: Lewis/Loftus/Cocking
    // Represents a question (and its answer).
    public class Question implements Complexity
    private String question, answer;
    private int complexityLevel;
    // Sets up the question with a default complexity.
    public Question (String query, String result)
    question = query;
    answer = result;
    complexityLevel = 1;
    // Sets the complexity level for this question.
    public void setComplexity (int level)
    complexityLevel = level;
    // Returns the complexity level for this question.
    public int getComplexity()
    return complexityLevel;
    // Returns the question.
    public String getQuestion()
    return question;
    // Returns the answer to this question.
    public String getAnswer()
    return answer;
    // Returns true if the candidate answer matches the answer.
    public boolean answerCorrect (String candidateAnswer)
    return answer.equals(candidateAnswer);
    // Returns this question (and its answer) as a string.
    public String toString()
    return question + "\n" + answer;
    }

    Do you know why this lazy f&#97;rt-&#97;ss is back? Because when he posted his homework last week, some sorry-assed idiot went and did it for him.
    http://forum.java.sun.com/thread.jspa?threadID=5244564&messageID=10008358#10008358
    He didn't even thank the poster.
    It's the same problem over and over again. You feed the bears and it only teaches them to come back for handouts.
    My polite suggestion to the original poster: please do your own f&#117;cking homework.

  • I need help with Creating Key Pairs

    Hello,
    I need help with Creating Key Pairs, I generate key pais with aba provider, but the keys generated are not base 64.
    the class is :
    import java.io.*;
    import java.math.BigInteger;
    import java.security.*;
    import java.security.spec.*;
    import java.security.interfaces.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import au.net.aba.crypto.provider.ABAProvider;
    class CreateKeyPairs {
    private static KeyPair keyPair;
    private static KeyPairGenerator pairGenerator;
    private static PrivateKey privateKey;
    private static PublicKey publicKey;
    public static void main(String[] args) throws Exception {
    if (args.length != 2) {
    System.out.println("Usage: java CreateKeyParis public_key_file_name privete_key_file_name");
    return;
    createKeys();
    saveKey(args[0],publicKey);
    saveKey(args[1],privateKey);
    private static void createKeys() throws Exception {
    Security.addProvider(new ABAProvider());
    pairGenerator = KeyPairGenerator.getInstance("RSA","ABA");
    pairGenerator.initialize(1024, new SecureRandom());
    keyPair = pairGenerator.generateKeyPair();
    privateKey = keyPair.getPrivate();
    publicKey = keyPair.getPublic();
    private synchronized static void saveKey(String filename,PrivateKey key) throws Exception {
    ObjectOutputStream out= new ObjectOutputStream(new FileOutputStream(filename));
    out.writeObject(key);
    out.close();
    private synchronized static void saveKey(String filename,PublicKey key) throws Exception {
    ObjectOutputStream out= new ObjectOutputStream( new FileOutputStream(filename));
    out.writeObject(key);
    out.close();
    the public key is:
    �� sr com.sun.rsajca.JSA_RSAPublicKeyrC��� xr com.sun.rsajca.JS_PublicKey~5< ~��% L thePublicKeyt Lcom/sun/rsasign/p;xpsr com.sun.rsasign.anm����9�[ [ at [B[ bq ~ xr com.sun.rsasign.p��(!g�� L at Ljava/lang/String;[ bt [Ljava/lang/String;xr com.sun.rsasign.c�"dyU�|  xpt Javaur [Ljava.lang.String;��V��{G  xp   q ~ ur [B���T�  xp   ��ccR}o���[!#I����lo������
    ����^"`8�|���Z>������&
    d ����"B��
    ^5���a����jw9�����D���D�)�*3/h��7�|��I�d�$�4f�8_�|���yuq ~
    How i can generated the key pairs in base 64 or binary????
    Thanxs for help me
    Luis Navarro Nu�ez
    Santiago.
    Chile.
    South America.

    I don't use ABA but BouncyCastle
    this could help you :
    try
    java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    java.security.KeyPairGenerator kg = java.security.KeyPairGenerator.getInstance("RSA","BC");
    java.security.KeyPair kp = kg.generateKeyPair();
    java.security.Key pub = kp.getPublic();
    java.security.Key pri = kp.getPrivate();
    System.out.println("pub: " + pub);
    System.out.println("pri: " + pri);
    byte[] pub_e = pub.getEncoded();
    byte[] pri_e = pri.getEncoded();
    java.io.PrintWriter o;
    java.io.DataInputStream i;
    java.io.File f;
    o = new java.io.PrintWriter(new java.io.FileOutputStream("d:/pub64"));
    o.println(new sun.misc.BASE64Encoder().encode(pub_e));
    o.close();
    o = new java.io.PrintWriter(new java.io.FileOutputStream("d:/pri64"));
    o.println(new sun.misc.BASE64Encoder().encode(pri_e));
    o.close();
    java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader("d:/pub64"));
    StringBuffer keyBase64 = new StringBuffer();
    String line = br.readLine ();
    while(line != null)
    keyBase64.append (line);
    line = br.readLine ();
    byte [] pubBytes = new sun.misc.BASE64Decoder().decodeBuffer(keyBase64.toString ());
    br = new java.io.BufferedReader(new java.io.FileReader("d:/pri64"));
    keyBase64 = new StringBuffer();
    line = br.readLine ();
    while(line != null)
    keyBase64.append (line);
    line = br.readLine ();
    byte [] priBytes = new sun.misc.BASE64Decoder().decodeBuffer(keyBase64.toString ());
    java.security.KeyFactory kf = java.security.KeyFactory.getInstance("RSA","BC");
    java.security.Key pubKey = kf.generatePublic(new java.security.spec.X509EncodedKeySpec(pubBytes));
    System.out.println("pub: " + pubKey);
    java.security.Key priKey = kf.generatePrivate(new java.security.spec.PKCS8EncodedKeySpec(priBytes));
    System.out.println("pri: " + priKey);
    catch(Exception e)
    e.printStackTrace ();
    }

  • Help with creating a form, I want to add a check box to enable me to unlock certain fields and deselect the block again

    Help with creating a form, I want to add a check box to enable me to unlock certain fields and deselect the block again

    Look to the right under "More Like This". Your issue has been discussed many many times. The error you are seeing is because you do not have enough free "contiguous" space on your hard drive. Read the other threads that address this issue to find how to solve the issue.
    Or, put "The disk cannot be partitioned because some files cannot be moved" into the search box at the upper right of this page.

  • Need Help with a getText method

    Gday all,
    I need help with a getText method, i need to extract text from a JTextField. Although this text then needs to converted to a double so that i can multiply a number that i have already specified. As you may of guessed that the text i need to extract already will be in a double format.e.g 0.1 or 0.0000004 etc
    Thanks for your help
    ps heres what i have already done its not very good though
    ToBeConverted.getText();
    ( need help here)
    double amount = (and here)
    total = (amount*.621371192);
    Converted.setText("= " + total);

    Double.parseDouble( textField.getText() );

  • Need help with creating a brush

    Hi guys,
    I wanted to ask for help with creating a brush (even a link to a tutorial will be goon enough ).
    I got this sample:
    I've created a brush from it, and i'm trying to get this kind of result:
    but it's only duplicates it and gives me this result:
    Can someone help me please understand what i need to define in order to make the brush behave like a continues brush instead of duplicate it?
    Thank you very much
    shlomit

    what you need to do is make a brush that looks like the tip of a brush. photoshop has several already but you can make your own that will be better.
    get a paintbrush and paint a spot kind of like what you did but dont paint a stroke. make it look kindof grungy. then make your brush from that, making sure to desaturate it and everything.
    EDIT:
    oh, and if you bring the fill down to like 10-20% your stroke will look better

  • I need help with creating PDF with Preview...

    Hello
    I need help with creating PDF documetns with Preview. Just a few days ago, I was able to create PDF files composed of scanned images (notes) and everything worked perfectly fine. However, today I was having trouble with it. I scanned my notebook and saved 8 images/pages in jpeg format. I did the usual routine with Preview (select all files>print>PDF>save as PDF>then save). Well this worked a few days ago, but when I tried it today, I was able to save it, but the after opening the PDF file that I have saved, only the first page was there. The other pages weren't included. I really don't see anything wrong with what I'm doing. I really need help. Any help would be greatly appreciated.

    I can't find it.  I went into advanced and then document processing but no batch sequence is there and everything is grayed out.
    EDIT: I realized that you cant do batch sequences in standard.  Any other ideas?

  • I need help with creating some formulas

    I'm not sure if anyone around here can help me, but I'm trying to create a Numbers document and need some help with creating a formula/function.
    I have a column of amounts and I would like to create a formula which deducts a percentage (11.9%) and puts the result in another column.
    If anyone can help me, it would be greatly appreciated.

    Here is an example that shows one way to do this:
    The original data is in column A.  In column B we will store formulas to adjust the amounts:
    1) select the cell where you want to formula (in this case cell B2)
    2) Type the "=" (equal sign):
    3) click cell A2:
    4) now type the rest of the formula which is: "*(100-11.9)/100"  that is asterisk, then open parenthesis, 100 minus eleven point nine close parenthesis forward slash  one hundred
    The Asterisk is the multiply operator  (times) and the forward slash is the division operator (divide)
    now hit return.  select cell B2 and hover the cursor over the bottom edge of the cell:
    drag the little yellow dot down to "fill" the formula down as needed.

  • Trying to understand methods - calling methods within own class - help

    I'm trying to write a simple program to search for letters in a string. I'm having a ton op problems; java seems so complicated with a lot of rules.
    The main problem I'm having (for now) is calling a method within the same class as main.
    import java.io.*;
    class LookForLetters{
        public static void main(String[] args)
         int i = 0;     
         int j = 0;
         int l = 0;
         int m = 0;
         String question1 = "Enter the line to be searched"; 
         String question2 = "Enter the line to be searched";       
         returnResponse stringtosearch = new returnResponse(question1); // here's where my problem is
            char[] chartosearch = stringtosearch.toCharArray();
         returnResponse letterstofind = new returnResponse(question2);
            char[] chartofind = letterstofind.toCharArray();     
         int findlength = chartosearch.length();
         int searchlength = chartofind.length();
         int[] k = new int[searchlength];
         for(i = 0; i < findlength; i++)
             for(j = 0; j < searchlength; j++)   
              if(chartosearch[i] == chartofind[j])
                  k[l] = i;
                  l++;
                  System.out.print("T");
             System.out.print(i + " " + l);
                if(l == 0)
                    System.out.print(chartofind[i] + " is the not in the sentence.");
                    System.out.println();       
                else
                    System.out.print(chartofind[i] + " is the ");
                 for(m = 0; m < l; m++)
                     System.out.print(k[l] + " ");
                    System.out.print("letter of your sentence");
                    System.out.println();
                    l = 0;
        public String returnResponse(String question){
         String response = " ";
         System.out.print(question);
         try
             InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReaderbr = new BufferedReader(isr);
             response = br.readLine();            
         catch(IOException e)
             System.out.print("error");
         return response;
    }The compiler says that it can't find the returnResponse method. when I try to instantiate the whole class, it says the package is not included. Please help.

    JoachimSauer wrote:
    DaneWKim wrote:
    thank you very much for your response. I'm sure it's obvious that I'm really confused. I'm used to C and assembly programming, so the OO concepts are really foggy.That particular line doesn't even deal with any OO concept. But the fact that you already know C helps me give a (hopefully) more useful answer:
    What is the return type of the method you're trying to call?
    What is the type of the variable you want to assign the return value to?
    Are those compatible? Or even more general: do they both exist?I changed it to:
            String stringtosearch = returnResponse(question1);
            char[] chartosearch = stringtosearch.toCharArray();
         String letterstofind = returnResponse(question2);
            char[] chartofind = letterstofind.toCharArray();I guess I'm getting confused with medthods, class and types. There's a whole host of new vocabulary and rules with OO and java that have me a bit confused. I appreciate your help.

  • Help with creating a sort method

    I'm trying to create a method that sorts three numbers entered by the user in increasing order IE 1,2,3. I'm having trouble creating the method though, heres what I have
    import java.util.Scanner;
    public class LabFivePartOne {
         public static void main(String[] args){
              Scanner input = new Scanner(System.in);
              System.out.println("Enter a number");
              double num1 = input.nextDouble();
              System.out.println("Enter a number");
              double num2 = input.nextDouble();
              System.out.println("Enter a number");
              double num3 = input.nextDouble();
              int k = sort(num1, num2, num3);
              System.out.println(k);
              public static int sort(double num1, double num2, double num3){
                   int result;
                   if (num1 < num2 && num2 < num3)
                        result = ?;
                   else
                        result = ?;
                   return result;
    }I put ? marks after the result = because i'm not sure what to put there, thats what I'm having trouble with.

    try this:
    double [] dblArr = new double [3];
    for (int i = 0; i < 3; i++)
          System.out.println ("Please enter number " + i);
          dblArr = input.nextDouble ();
    for (int x = 0; x < 2; x++)
    for (int y = x+1; y < 3; y++)
    if (dblArr [x] > dblArr [y])
    String temp = dblArr [x];
    dblArr [x] = dblArr [y];
    dblArr [y] = temp;
    Edited by: tam826 on Oct 7, 2008 6:54 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • I need help to create this method/class

    the code is:
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
    import java.util.Scanner;
    public class words { 
           public static ArrayList<String> readFileIntoString() {
              ArrayList<String> wordList = new ArrayList<String>();
             Scanner scanner = null;
             try {
               scanner = new Scanner(new File("BoggleWords"));
             } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
             // Read all lines in newFile(filename) and append
             // then to the one big StringBuffer object.
             while (scanner.hasNextLine()) {
               wordList.add(scanner.nextLine().toUpperCase());
             return wordList;
    }these assertions should all pass:
    assertEquals(81055, words.size());
    assertTrue(words.contains("PARENT"));
    assertTrue(words.contains("TREE"));
    assertFalse(words.contains("tree"));
    the instruction of this task is:
    Complete a Dictionary with one static method (no object required) that returns acollection of strings where all words must be in uppercase. We will use the file BoggleWords, a file of 81,055 words many people believe are spelled correctly.
    where did I fail this??

    assertEquals(81055, words.size()); size()
    assertTrue(words.contains("PARENT")); contains()
    assertTrue(words.contains("TREE"));
    assertFalse(words.contains("tree"));You must write these methods.

  • Calling a method within a class form another class(ViewController)

    I am creating an SQL project in XCODE. I have one view. My main view controller is loading the database to a table/array. I want to add another class (with no NIB) just to handle the display of the table in a UITableView. So, I added a skeleton cocoa touch class file to my classes folder to handle this function when parameters change.
    So, in my app delegate, the "applicationdidFinishLaunchingWithOptions" method loads my mainViewController and NIB.  On the "viewDidLoad" method in my mainViewController, I read a URL into an SQLite database and close the database.  Herein lies the problem: I want to call my new class (TableViewHandler) and pass it the array created in the mainViewController and use the array to populate the UITable.
    How do I call a class from within another class (which has no NIB) to populate the table?  Especially if my TableViewHandler has no "viewDidLoad", "viewDidAppear", etc.
    Regads,
    -Kevin

    This is what my exact problem.
    i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
    both ShopBook.java and DataBean.java lies in the package shoppack.
    in ShopBook i tried to instantiate the object to DataBean as
    DataBean db = new DataBean();
    it shows the compiler error, unable to resolve symbol DataBean.
    note:
    first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
    when i'm trying to compile the ShopBook its telling this error.
    hope i'm clear in explaining my problem. can u please help me?
    thank u in advance.
    regards,
    Fazli

Maybe you are looking for

  • Help needed with building Flex App without FlexBuilder

    Hi Guys, I was building my application on Struts framework with JSPs as the front end. I just got a new requirement to try and build my application's GUI with Flex (completely replacing JSPs). I cannot use FlexBuilder as my company won't buy it. I've

  • App-V 5.0 - Preserving configuration.xml custom changes during package update

    Hello, is the default configuration file preserved during: 1) Package open, edit, save 2) Package open, add new application, save as Reason is - it is very typical those files will be customized and having to manually transfer those changes to new ve

  • Iphone3g connection to HDTV--what cable, what dock?

    I want to connect my, soon to be ordered, Iphone 3g to my kitchen's HDTV. I am still a little confused about a dock for the iphone that will normally be in my kitchen. My kitchen tv supports Component HD connections. (This tv is currently connected,

  • Last Purchase Price Report

    Hello All, I need to get a Report on the Last Purchase Price for some materials. Where can I find this report? Is there any report that shows the materials related to the suppliers. Best Regards, Miguel Edited by: Miguel Barbosa on May 25, 2009 5:59

  • Reg Organisational Structure Creation

    Hi, When Iam trying to  create root Org Unit  in Org Mgmnt Module it is giving the error as "No valid interval found (internal number assignment)". I also tried to maintain the number ranges entries( internal) in spro . I guess I might not be maintai