Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. package Lakes_;
  2. import javax.swing.JOptionPane;
  3.  
  4. public class Lakes_
  5. {
  6. //lake's attributes (array format)
  7. static String [] name = new String[100];
  8. static double [] temp = new double[100];
  9. static int [] pH = new int[100];
  10. static int [] acidity = new int[100];
  11. //working variables
  12. static int lakeCount = 0; //keep count of lakes and the next lake to be inputed
  13. static int option = 0;
  14.  
  15. public static void main(String[] args)
  16. {
  17. int answer = JOptionPane.showConfirmDialog(null, "Start?" , "Confirm Dialog", JOptionPane.YES_NO_OPTION);//do you want to start this program or no?
  18. if(answer == JOptionPane.YES_OPTION)//if answer is yes then start program
  19. {
  20. while(option != 4) //as long as 4 isn't clicked, then the user continues to use program
  21. {
  22. menu();
  23. switch(option) //instead of an if statement to go with the menu input
  24. {
  25. case 1: getLake();
  26. lakeCount++; //add 1 to count statement for another lake
  27. break; //then leave case 1
  28. case 2: dispReport();
  29. break;
  30. case 3: search(name);
  31. dispReport();
  32. break;
  33. }//end switch
  34. }//end while
  35. }//end if
  36. else
  37. JOptionPane.showMessageDialog(null, "Thank you for stopping by!"); //the person clicked no
  38. JOptionPane.showMessageDialog(null, "Good bye!");
  39. }//end main
  40. //================================================
  41. public static void menu() //method to allow the user to select a menu option
  42. {
  43. String input = "";
  44. input = JOptionPane.showInputDialog("-1-Create a laken" +
  45. "-2-Display all lakesn" +
  46. "-3-Search for a laken" +
  47. "-4-Quit Program");
  48. option = Integer.parseInt(input);
  49. }//end menu
  50. //=================================================
  51. public static void getLake() //method to create a new lake
  52. {
  53. String input = ""; //for the purpose of input
  54. input = JOptionPane.showInputDialog("Enter the lake's name: ");
  55. name[lakeCount] = input;//then store it in the corresponding variable
  56. input = JOptionPane.showInputDialog("Enter the lake's temperature in Fahrenheit: ");
  57. temp[lakeCount] = Double.parseDouble(input); //have to parse it to convert it
  58. input = JOptionPane.showInputDialog("Enter the lake's pH level: ");
  59. pH[lakeCount] = Integer.parseInt(input); //then store the input
  60. }//end getLake
  61. //=================================================
  62. public static String search(String name) //method to search for inputed lake's info
  63. {
  64. input = JOptionPane.showInputDialog("Enter the lake's name you wish to search for: ");
  65. {
  66. for (String name : input)
  67. {
  68. if (name.equals(input))
  69. return name;
  70. }//end if
  71. else
  72. return null;
  73. }//end for
  74. }//end search
  75. //=================================================
  76. public static void dispReport() //method to display lake's report
  77. {
  78. for(int i = 0; i < lakeCount; i++) //displaying batch
  79. {
  80. JOptionPane.showMessageDialog(null, "Lake's name: " + name[i] + "n" +
  81. "Temperature: " +temp[i] + "n" +
  82. "pH levels: " +pH[i]);
  83. }//end for
  84. }//end dispReport
  85. }//end class Lakes_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement