-
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 .
-
-
-
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");
}
}
}
}
-
its my first time to study java and use netbeans :S
-
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:");
}
}
-
more clarification
what this line suggest
tags Mytag = new tags();
Is this class I need to have or what ?
-
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
-