Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package com.ssn.ssijs.lgh_test17;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Scanner;
  5. import java.util.Set;
  6.  
  7. public class Application {
  8. Set<String> constraints = new HashSet<>();
  9.  
  10. public static void main(String[] args) {
  11. Depot dep = new Depot(4, 4);
  12. dep.show();
  13. Application app = new Application();
  14.  
  15. app.run();
  16.  
  17. }
  18.  
  19. private void run() {
  20. Scanner scanner = new Scanner(System.in);
  21. String[] inputConstraints = { "F", "L", "I", "P", "FL", "FI", "FP", "LI", "LP", "IP", "FLI", "FLP", "FIP",
  22. "LIP", "FLIP" };
  23. addConstraints(inputConstraints);
  24. while (true) {
  25. System.out.println("Put Article:");
  26. String type = scanner.nextLine();
  27. type = type.toUpperCase();
  28. try {
  29. if (!checkInput(type)) {
  30.  
  31. throw new Exception();
  32. } else {
  33. System.out.println("Articolul " + type + " este valid");
  34. }
  35.  
  36. } catch (Exception e) {
  37. System.out.println("Input incorect");
  38. }
  39. }
  40. }
  41.  
  42. private boolean checkInput(String type) {
  43.  
  44. return constraints.contains(type);
  45. }
  46.  
  47. private void addConstraints(String[] inputConstraints) {
  48. constraints.clear();
  49. for (int i = 0; i < inputConstraints.length; i++) {
  50. constraints.add(inputConstraints[i]);
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement