Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lakes_;
- import javax.swing.JOptionPane;
- public class Lakes_
- {
- //lake's attributes (array format)
- static String [] name = new String[100];
- static double [] temp = new double[100];
- static int [] pH = new int[100];
- static int [] acidity = new int[100];
- //working variables
- static int lakeCount = 0; //keep count of lakes and the next lake to be inputed
- static int option = 0;
- public static void main(String[] args)
- {
- int answer = JOptionPane.showConfirmDialog(null, "Start?" , "Confirm Dialog", JOptionPane.YES_NO_OPTION);//do you want to start this program or no?
- if(answer == JOptionPane.YES_OPTION)//if answer is yes then start program
- {
- while(option != 4) //as long as 4 isn't clicked, then the user continues to use program
- {
- menu();
- switch(option) //instead of an if statement to go with the menu input
- {
- case 1: getLake();
- lakeCount++; //add 1 to count statement for another lake
- break; //then leave case 1
- case 2: dispReport();
- break;
- case 3: search(name);
- dispReport();
- break;
- }//end switch
- }//end while
- }//end if
- else
- JOptionPane.showMessageDialog(null, "Thank you for stopping by!"); //the person clicked no
- JOptionPane.showMessageDialog(null, "Good bye!");
- }//end main
- //================================================
- public static void menu() //method to allow the user to select a menu option
- {
- String input = "";
- input = JOptionPane.showInputDialog("-1-Create a laken" +
- "-2-Display all lakesn" +
- "-3-Search for a laken" +
- "-4-Quit Program");
- option = Integer.parseInt(input);
- }//end menu
- //=================================================
- public static void getLake() //method to create a new lake
- {
- String input = ""; //for the purpose of input
- input = JOptionPane.showInputDialog("Enter the lake's name: ");
- name[lakeCount] = input;//then store it in the corresponding variable
- input = JOptionPane.showInputDialog("Enter the lake's temperature in Fahrenheit: ");
- temp[lakeCount] = Double.parseDouble(input); //have to parse it to convert it
- input = JOptionPane.showInputDialog("Enter the lake's pH level: ");
- pH[lakeCount] = Integer.parseInt(input); //then store the input
- }//end getLake
- //=================================================
- public static String search(String name) //method to search for inputed lake's info
- {
- input = JOptionPane.showInputDialog("Enter the lake's name you wish to search for: ");
- {
- for (String name : input)
- {
- if (name.equals(input))
- return name;
- }//end if
- else
- return null;
- }//end for
- }//end search
- //=================================================
- public static void dispReport() //method to display lake's report
- {
- for(int i = 0; i < lakeCount; i++) //displaying batch
- {
- JOptionPane.showMessageDialog(null, "Lake's name: " + name[i] + "n" +
- "Temperature: " +temp[i] + "n" +
- "pH levels: " +pH[i]);
- }//end for
- }//end dispReport
- }//end class Lakes_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement