Results 1 to 9 of 9

Thread: arraylist

  1. #1
    nanees is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default arraylist

    hi all ,,
    please i want your help in my assignment
    im trying to make an arraylist in my main .. but it refused to be implemented because its static (note: i refrenced it in the main) ..
    when i make it without a reference and declare it all in the static void main ... it doesn't implement at all .. and the program cant understand it is an array list.
    what can i do ???
    ps: i dont want to make it in separated class i want it in main .

  2. #2
    nanees is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default

    please i want your help

  3. #3
    only_java is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    Kindly post your code.

  4. #4
    nanees is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default

    thats my main


    package finaltags;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.io.*;
    import java.util.ArrayList;
    public class Main {
    //tags Mytag;
    //ArrayList<String> blurbs;
    public static void main(String[] args) throws IOException {
    ArrayList<String> blurbs = new ArrayList<String>();
    tags Mytag= new tags();
    InputStreamReader ipu = new InputStreamReader(System.in);
    BufferedReader object = new BufferedReader(ipu);
    int count=0;
    while(count<5)
    {
    System.out.println("1- Add a blurb.");
    System.out.println("2- Tag a blurb.");
    System.out.println("3- Remove a tag from a blurb. ");
    System.out.println("4- Search blurbs by tags. ");
    System.out.println("5- Exit.");
    System.out.println("Please choose one of the following operations: ");
    int choice= Integer.parseInt(object.readLine());
    switch(choice)
    {
    case 1:
    System.out.println("Please enter your Blurb.");
    InputStreamReader inp = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(inp);
    String str = null;
    try {
    str = br.readLine();
    } catch (IOException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }
    blurbs.add(str);
    System.out.println("You entered :"+str);
    break;


    case 2:
    System.out.println("Choose a blurb");
    System.out.println(blurbs);
    InputStreamReader j = new InputStreamReader(System.in);
    BufferedReader tagb = new BufferedReader(j);
    String n=null;
    try {
    n = tagb.readLine();
    } catch (IOException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }
    if(blurbs.contains(n));
    {
    System.out.println("Enter your tag : ");
    InputStreamReader k = new InputStreamReader(System.in);
    BufferedReader tagbl = new BufferedReader(k);
    String test=null;
    try {
    test = tagbl.readLine();
    } catch (IOException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }
    Mytag.tagnames.add(test);
    Mytag.Tagblurb(test);
    }
    break;


    case 3:

    System.out.println("Choose a blurb");
    System.out.println(blurbs);
    InputStreamReader p = new InputStreamReader(System.in);
    BufferedReader tagd = new BufferedReader(p);
    String del=null;
    try {
    del = tagd.readLine();
    } catch (IOException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }
    if(blurbs.contains(del));
    {
    System.out.println("Enter the selected tag for deleting: ");
    InputStreamReader u = new InputStreamReader(System.in);
    BufferedReader tagde = new BufferedReader(u);
    String tagdelete = null;
    try {
    tagdelete = tagde.readLine();
    } catch (IOException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }
    Mytag.tagnames.remove(tagdelete);
    Mytag.removeTagname(tagdelete);
    }
    break;
    case 4:
    System.out.println("Enter the keyword for searching");
    InputStreamReader k = new InputStreamReader(System.in);
    BufferedReader tagse = new BufferedReader(k);
    String tagsearch = null;
    try {
    tagsearch = tagse.readLine();
    } catch (IOException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }
    Mytag.searchTags(tagsearch);
    break;
    case 5:
    System.out.println("End!!");
    System.exit(0);
    break;
    default:
    System.out.println("Please enter between 1-5");

    }
    }

    }

    }

  5. #5
    nanees is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default

    its my first time to study java and use netbeans :S

  6. #6
    nanees is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default

    thats my class tags





    package finaltags;
    import java.io.DataOutputStream;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.*;
    import java.util.ArrayList;

    public class tags {
    int [] tagIDs= new int[5];
    ArrayList<String> tagnames;
    public tags(){
    tagnames = new ArrayList<String>();
    }

    public void Tagblurb (String tagname)
    {
    System.out.println("You entered the tag " + tagname);
    System.out.println(tagnames);
    }
    public void removeTagname (String tagname)
    {
    System.out.println("Tag "+tagname+" deleted!");
    System.out.println(tagnames);
    }
    public void searchTags (String tagname)
    {
    System.out.println("All blurbs having the tag "+ tagname+" are:");
    }

    }

  7. #7
    only_java is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default more clarification

    what this line suggest

    tags Mytag = new tags();

    Is this class I need to have or what ?

  8. #8
    nanees is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default

    no thats the object i took from the class tags
    to use the methods i have in this class ..
    i posted the whole code for you

  9. #9
    nanees is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

Similar Threads

  1. copying contents of an ArrayList to another ArrayList
    By ankit1801 in forum New To Java
    Replies: 8
    Last Post: 03-27-2011, 07:07 AM
  2. sorting arraylist based on another arraylist
    By busdude in forum New To Java
    Replies: 4
    Last Post: 02-07-2011, 12:48 PM
  3. Replies: 7
    Last Post: 11-22-2010, 02:26 PM
  4. Replies: 2
    Last Post: 11-16-2010, 06:51 PM
  5. Replies: 2
    Last Post: 04-21-2008, 12:43 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •