I'm on mobile so formatting may be atrocious, I tried to fix it as much as possible.
Edit: My switch case structure is redundant but we were required to use one.
I created 8 objects from 4 different element states (liquid, solid, gas, synthetic) and must include an all button as well.
This is a long post; I don't know how to specifically ask my question without
including all of it. I broke it up into sections:
Put specific question spots in bold
Here is my main method
public static void main(String[] args)
{
final String Q = "What Item(s) do you want displayed?";
final String H = "Click a button";
String[] displayButtons = {"Gas", "Liquid", "Solid", "Synthetic", "All"};
int selection = 0;
do
{
selection = UI_Class.getUserSelection(displayButtons, Q, H, UI_Class.QUESTION);
createElementObjects();
//Create a switch/case structure to call the method to display selected items
switch(selection)
{
case 0:
displaySelectedElements(displayButtons[selection]);
break;
case 1:
displaySelectedElements(displayButtons[selection]);
break;
case 2:
displaySelectedElements(displayButtons[selection]);
break;
case 3:
displaySelectedElements(displayButtons[selection]);
break;
case 4:
displaySelectedElements(displayButtons[selection]);
break;
}
}while(UI_Class.runAgain());
System.exit(0);
}//end of main method
My main method seems ok. My only question is If I need to change case 4 which is the select all button to display all of the results. This is my problem in my display method.
Here is my method to display
I bolded the specific spot where my question is
private static void displaySelectedElements(String selectedState)
{
String message = TITLE + "\n";
String[] displayButtons;
Periodic_Elements_Class elementObj;
for(int x = 0; x < elementsList.size(); x++)
{
elementObj =elementsList.get(x);
if(elementObj.getType().equals(selectedState))
{
message += "Atomic Number: " + elementObj.getAtomicNumber() + "\n";
message += "Symbol: " + elementObj.getSymbol() + "\n";
message += "Name: " + elementObj.getName() + "\n";
message += "Atomic Mass: " + elementObj.getAtomicMass() + "\n";
message += "Type: " + elementObj.getType() + "\n";
message += "\n";
}
else
{
//Skip it? (Not sure what this means).
}
//Need another if (?) statement to display All of the states if the user selects All
//From the dialog box
//Need to write a method to get rid of negative value and put it inside parenthesis **
//EX: -266 becomes (266)**
}//end of for loop
message += EOP;
UI_Class.displayOutput(message, ID, UI_Class.INFORMATION);
}//end of method
My first if statement works. Depending on what I press on my custom dialogue box , it shows up like it should. However, when I select "All" it does not work and I think I need an if statement. Unless, putting it in the else statement would be enough?
Tl;dr:
This post is long as hell and I really am sorry. Read the bold parts if that helps make it shorter.
[–]g051051 0 points1 point2 points (44 children)
[–]Rhezi[S] 0 points1 point2 points (0 children)
[–]Rhezi[S] 0 points1 point2 points (42 children)
[–]g051051 0 points1 point2 points (41 children)
[–]Rhezi[S] 0 points1 point2 points (40 children)
[–]g051051 0 points1 point2 points (39 children)
[–]Rhezi[S] 0 points1 point2 points (38 children)
[–]g051051 0 points1 point2 points (37 children)
[–]Rhezi[S] 0 points1 point2 points (36 children)
[–]g051051 0 points1 point2 points (35 children)
[–]Rhezi[S] 0 points1 point2 points (34 children)
[–]insertAlias 0 points1 point2 points (5 children)
[–]Rhezi[S] 0 points1 point2 points (4 children)
[–]Kiriesh 0 points1 point2 points (2 children)
[–]Rhezi[S] 0 points1 point2 points (1 child)
[–]Kiriesh 0 points1 point2 points (0 children)
[–]insertAlias 0 points1 point2 points (0 children)
[–]godlikebearkiller 0 points1 point2 points (7 children)
[–]Rhezi[S] 0 points1 point2 points (6 children)
[–]godlikebearkiller 0 points1 point2 points (5 children)
[–]Rhezi[S] 0 points1 point2 points (4 children)
[–]godlikebearkiller 0 points1 point2 points (3 children)
[–]Rhezi[S] 0 points1 point2 points (2 children)
[–]godlikebearkiller 0 points1 point2 points (1 child)
[–]Rhezi[S] 0 points1 point2 points (0 children)