Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. import java.util.*;
  2. public class Interface
  3. {
  4.  
  5. private Depot depot1, depot2;
  6.  
  7. int choice;
  8. Scanner console = new Scanner(System.in);
  9.  
  10. public Interface()
  11. {
  12.  
  13. depot1 = new Depot();
  14. depot2 = new Depot();
  15.  
  16. }
  17.  
  18. public void run(){
  19.  
  20.  
  21.  
  22. //System.out.println("Enter Depot name: ");
  23. //String dName = console.nextLine();
  24. //Depot d = new Depot();
  25. //d.setName(dName);
  26. //System.out.println("Name: " + d.getName());
  27.  
  28.  
  29. //this method should control the flow of the program
  30.  
  31.  
  32.  
  33. do {
  34. System.out.println("Add Depot(1), Remove Depot(2), List Depots(3), Exit (9): ");
  35. choice = console.nextInt();
  36. if(choice<1){
  37. System.out.println("Negative numbers not allowed");
  38. }
  39. else
  40. switch(choice)
  41. {
  42. case 1:
  43. createDepot();
  44. break;
  45.  
  46. case 2: removeDepot();
  47. break;
  48.  
  49. case 3: listDepot();
  50. break;
  51.  
  52. case 4: System.out.println("cool");
  53. break;
  54.  
  55. case 5: addProduct();
  56. break;
  57.  
  58. default: System.out.println("invalid option");
  59. }
  60. }
  61. while(choice!=9);
  62. }
  63.  
  64. private void createDepot()
  65. {
  66. System.out.println("Please enter a Depot name");
  67. String n = console.nextLine();
  68. if(n.equals(depot1.getName()) || n.equals(depot2.getName()))
  69. {
  70. System.out.println("You have entered an already existing depot");
  71. System.out.println("Please enter a new Depot name");
  72. }
  73.  
  74. else if (depot1.getName().equals("null")) {
  75.  
  76. depot1.setName(n);
  77. System.out.println("else if reached");
  78. System.out.println(depot1.getName());
  79. }
  80. else {
  81. depot2.setName(n);
  82. System.out.println(" Final else reached");
  83. System.out.println(depot2.getName());
  84. }
  85.  
  86.  
  87. }
  88.  
  89.  
  90.  
  91.  
  92. private void removeDepot()
  93. {
  94. System.out.println("Please enter the name of the depot you wish to remove");
  95. String r = console.nextLine();
  96. if (r!= depot1.getName() || r!= depot2.getName()) {
  97. System.out.println("You have entered a non-existing Depot");
  98. System.out.println("Please enter the name of the depot you wish to remove");
  99. r = console.nextLine();
  100. }
  101. else if (r==depot1.getName()) {
  102. depot1 = null;
  103. System.out.print("You have removed depot1");
  104. }
  105. else depot2 = null;
  106. System.out.print("You have removed depot2");
  107. }
  108. private void listDepot()
  109. {
  110. if (depot1 == null && depot2 == null) {
  111. System.out.println("There are no Depots available");
  112. }
  113. else
  114. System.out.println(depot1.getName() + depot2.getName());
  115. }
  116.  
  117. private void addProduct() {
  118. System.out.println("Enter product name");
  119. String nm = console.nextLine();
  120.  
  121. System.out.println("Enter product price");
  122. double pr = console.nextDouble();
  123.  
  124. System.out.println("Enter product weight");
  125. double wt = console.nextDouble();
  126.  
  127. System.out.println("Enter product quantity");
  128. int qt = console.nextInt();
  129. depot1.addInfo(1, nm, pr, wt, qt);
  130. }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. public static void main(String[] args) {
  139. Interface intFace = new Interface();
  140. intFace.run();
  141.  
  142.  
  143.  
  144.  
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement