I'm trying to write a program for my self that will allow me to sort ArrayLists information of companies.
I don't want the program to always show me all the information, only about 8 different aspects of information at a time, such as market value, stock price, ceo, ect.. I have created a few common ones, but i wanted to create a way for the program to allow the user to create their own set of data for the program to display by inserting info. get(whatever command you want) system.
In other words, i want the program to allow me to input a method into the console and have it spit that method out. Is there anyway to do this that is simple?
Edit: Im still having trouble with this and the previous solution didnt actually work. So im going to show you exactly what im working with here:
public ArrayList<Object> newtag = new ArrayList<Object>();
ArrayList tagname = new ArrayList();
double tagnum;
int e = 0;
public void printCreate() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner scan = new Scanner(System.in);
System.out.println("Insert the number of tags you wish to view up to 5.");
tagnum = scan.nextDouble();
if (tagnum > 5){
System.out.println("Please enter a value less than or equal to 5.");
tagnum = scan.nextDouble();
} else {
for (int a = 0; a < tagnum; ++a){
++e;
System.out.println(e+". Insert the tag which you would like to look up:");
String taglookup = br.readLine();
newtag.add(taglookup);
System.out.println("Type the name of this tag that you would like to be displayed:");
tagname.add(br.readLine());
}
int c = 0;
for(Company info: companies){
if (tagnum == 1){
++c;
System.out.println("-------------------------------------------------------------");
System.out.println();
System.out.format("#%s. %5s Last trade: %s Days Low-High: %s - %s volume:%s \n", c, info.getCompanyName(), info.getRTLastTrade(), info.getDaysLow(), info.getDaysHigh(), info.getVol());
System.out.println();
System.out.println(tagname.get(0) + " : " + newtag.get(0));
System.out.println();
} else if (tagnum == 2){
++c;
System.out.println("-------------------------------------------------------------");
System.out.println();
System.out.format("#%s. %5s Last trade: %s Days Low-High: %s - %s volume:%s \n", c, info.getCompanyName(), info.getRTLastTrade(), info.getDaysLow(), info.getDaysHigh(), info.getVol());
System.out.println();
System.out.println(tagname.get(0) + " : " + newtag.get(0) + " " + tagname.get(1) + " : " + newtag.get(1));
System.out.println();
I need to essentially have it so that the newtag.get(0) becomes whatever the user wants from a list of information that all have getters. I tried using christans method but there is an issue with calling the different companies from the Company class.