wxns

code_v2

Sep 6th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.21 KB | None | 0 0
  1. package program_classes;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class topClothing {
  6.  
  7.  
  8.     //private String name = "top1";
  9.  
  10. //    public topClothing(String a) {
  11.     //    this.setName(a);
  12.   //  }
  13.  
  14.     //public String getName() {
  15.     //    return name;
  16.     //}
  17.  
  18.     //private void setName(String d) {
  19.     //    this.name = d;
  20.    // }
  21.     // private variables allow them to be inaccessible outside public class-specific functions and methods
  22.     private String[] sleeveLength = {"None", "Cap sleeves", "Short sleeves", "3/4 length sleeves", "Long sleeves", "Long sleeves with holes", "shirt sleeve length", "q"};
  23.     private String sleeveLengthFinal = "None";
  24.     private String primaryColor;
  25.     private String secondaryColor;
  26.  
  27.     private String[] mannerWorn = {"Tucked over bottom", "Tucked under bottom", "Worn around waist"}; // 3rd option only for long sleeves
  28.  
  29.     private int maxquantityPockets = 7;
  30.  
  31.     private String[][] pockets = new String[maxquantityPockets][2]; // second array value for properties
  32.  
  33.     public int getMaxquantityPockets() { // should be int
  34.         return maxquantityPockets;
  35.     }
  36.  
  37.     public String[][] getPockets() {
  38.         return pockets;
  39.     }
  40.  
  41.     public String[][] setPockets(String[][] a) {
  42.         this.pockets = a;
  43.         return a;
  44.     }
  45.     public String[] getSleeveLength() {
  46.         return sleeveLength;
  47.     }
  48.  
  49.     public String getSleeveLengthFinal(){
  50.         return sleeveLengthFinal;
  51.     }
  52.  
  53.     private void setSleeveLengthFinal(String x){
  54.         this.sleeveLengthFinal = x;
  55.     }
  56.  
  57.     public void setMaxquantityPockets(int z) { // should be void
  58.         this.maxquantityPockets = z;
  59.         //    return z;
  60.     }
  61.  
  62.     public int pocketNumber(int q) {
  63.  
  64.         boolean repeat = false;
  65.  
  66.  
  67.         do {
  68.             System.out.print("Please select the number of pockets you want to work with: ");
  69.             Scanner qu = new Scanner(System.in);
  70.             int userQu = qu.nextInt();
  71.  
  72.             if (userQu > 7 || userQu < 1) {
  73.                 System.out.println("Sorry, that is not a valid number of pockets. ");
  74.                 repeat = true;
  75.             } else {
  76.                 System.out.println("You have chosen " + userQu + " pockets to work with. ");
  77.                 q = userQu; // LEFT declares value, RIGHT assigns value
  78.                 repeat = false;
  79.                 int x;
  80.                 for (x = 0; x < getMaxquantityPockets(); x++) { // invoke class attributes
  81.                     pockets[x][0] = ("Pocket " + (x + 1));
  82.                     pockets[x][1] = ("None");
  83.                 }
  84.                 break;
  85.             } // once this complete, values erased.
  86.         } while (repeat);
  87.  
  88.         return q;
  89.     }
  90.  
  91.  
  92.  
  93.  
  94.     // get user input and validate it
  95.     // if outside of maximum pocket range, reject input
  96.     // user access to individual pockets and their individual properties
  97.  
  98.  
  99. //        public int managePocketsQuantity.getQuantf
  100.  
  101.     public void managePockets() { // get value from outside method and set within method?
  102.         boolean repeat = false;
  103.         int x;
  104.         int y;
  105.  
  106.         System.out.println(getMaxquantityPockets());
  107.         for (x = 0; x < getMaxquantityPockets(); x++) { // invoke class attributes
  108.             this.pockets[x][0] = ("Pocket " + (x+1));
  109.             this.pockets[x][1] = ("None");
  110.             System.out.println(this.pockets[x][0]);
  111.         }
  112.         do {
  113.             System.out.println("Please enter the pocket you want to work with (press q to return to previous menu): ");
  114.             Scanner pocket = new Scanner(System.in);
  115.             String userPocket = pocket.nextLine();
  116.  
  117.             for (x = 0; x < getMaxquantityPockets(); x++) {
  118.                 if (userPocket.equals(this.pockets[x][0])) {
  119.                     break;
  120.                 }
  121.             }
  122.             if (x == getMaxquantityPockets() && !(userPocket.equals("q"))) {
  123.                 System.out.println("Sorry, we cannot work with that pocket.");
  124.                 x = 0;
  125.                 repeat = true;
  126.             } else if (x == getMaxquantityPockets() && userPocket.equals("q")){
  127.                 break;
  128.             } else {
  129.                 System.out.println("You have chosen to work with " + this.pockets[x][0]);
  130.                 System.out.println("What properties would you like to have for this pocket?");
  131.                 Scanner property = new Scanner(System.in);
  132.                 String userProperty = property.nextLine();
  133.                 this.pockets[x][1] = userProperty;
  134.  
  135.                 System.out.println(this.pockets[x][0] + " has the following properties: " + this.pockets[x][1]);
  136.                 repeat = false;
  137.             }
  138.  
  139.         } while (repeat);
  140.     //    return a;
  141.     }
  142.  
  143.  
  144.     //    int repeat2 = 0;
  145.     //    int y;
  146.  
  147.     public boolean hood;
  148.     public boolean isHoodUp;
  149.     public boolean topOpen;
  150.     public boolean wearTopOpen;
  151.     public String topOpenFasten;
  152.     public void userHood() {
  153.         boolean repeat = false;
  154.         do {
  155.             System.out.print("Would you like a hood with your top? (y/n) ");
  156.             Scanner option = new Scanner(System.in);
  157.             String userOption = option.nextLine();
  158.             switch (userOption) {
  159.                 case "y":
  160.                     boolean repeat2 = false;
  161.                     do {
  162.                         this.hood = true;
  163.                         System.out.print("You have chosen to include a hood to your top. Would you like to wear it up? (y/n) ");
  164.                         Scanner option2 = new Scanner(System.in);
  165.                         String userOption2 = option2.nextLine();
  166.                         switch (userOption2) {
  167.                             case "y":
  168.                                 System.out.println("You have chosen to wear it up.");
  169.                                 isHoodUp = true;
  170.                                 break;
  171.                             case "n":
  172.                                 System.out.println("You have chosen to wear it down.");
  173.                                 isHoodUp = false;
  174.                                 break;
  175.                             default:
  176.                                 System.out.println("Sorry, invalid input!");
  177.                                 repeat2 = true;
  178.                                 break;
  179.                         }
  180.                     } while (repeat2);
  181.                     break;
  182.                 case "n":
  183.                     System.out.println("You have chosen not to include a hood with your top.");
  184.                     this.hood = false;
  185.                     this.isHoodUp = false;
  186.                     break;
  187.                 default:
  188.                     System.out.println("Sorry, invalid input!");
  189.                     repeat = true;
  190.                     break;
  191.             }
  192.  
  193.  
  194.         } while (repeat);
  195.     }
  196.     public void userOpen(){
  197.         boolean repeat = false;
  198.         do {
  199.  
  200.             System.out.print("Would you like your clothing to be open or closed? (open/closed) ");
  201.             Scanner closeopen = new Scanner(System.in);
  202.             String userCloseOpen = closeopen.nextLine();
  203.             switch (userCloseOpen) {
  204.  
  205.                 case "open":
  206.                     topOpen = true;
  207.                     System.out.print("You have chosen to have an open top. Select the fastener: ");
  208.                     Scanner fastener = new Scanner(System.in);
  209.                     String userFastener = fastener.nextLine();
  210.                     this.topOpenFasten = userFastener;
  211.  
  212.                     Scanner fasten = new Scanner(System.in);
  213.                     String userFasten = fasten.nextLine();
  214.                     System.out.print("Would you like to wear it open or closed? (open/closed) ");
  215.  
  216.                         boolean repeat2 = false;
  217.                         do {
  218.                             switch (userFasten) {
  219.                                 case "open":
  220.                                     wearTopOpen = true;
  221.                                     System.out.println("You have chosen to wear your top open.");
  222.                                     break;
  223.                                 case "closed":
  224.                                     wearTopOpen = false;
  225.                                     System.out.println("You have chosen to wear your top closed.");
  226.                                     break;
  227.                                 default:
  228.  
  229.                                     System.out.println("Sorry, invalid input!");
  230.                                     repeat2 = true;
  231.                                     break;
  232.                             }
  233.  
  234.                         } while (repeat2);
  235.  
  236.                     break;
  237.                 case "closed":
  238.                     topOpen = false;
  239.                     wearTopOpen = false;
  240.                     this.topOpenFasten = "None";
  241.                     System.out.println("You have chosen to have a closed top.");
  242.                     break;
  243.                 default:
  244.                     System.out.println("Sorry, invalid input!");
  245.                     repeat = true;
  246.                     break;
  247.             }
  248.  
  249.         } while (repeat); // simplified from repeat == true;
  250.     }
  251.     private String userprintdesc = "None";
  252.     public void topPrint(){
  253.         String[] printLocations = {"Chest", "Back", "Sleeves", "q"}; // 3rd option can't be applied with sleeveless
  254.         boolean repeat = false;
  255.         int x;
  256.         do {
  257.             System.out.println("Please select a print location, or press q to go back: ");
  258.             for (x = 0; x < 3; x++) {
  259.                 System.out.println(printLocations[x]);
  260.             }
  261.             Scanner printloc = new Scanner(System.in);
  262.             String userprintloc = printloc.nextLine();
  263.             for (x = 0; x < printLocations.length; x++) {
  264.                 if (userprintloc.equals(printLocations[x])) {
  265.                     break;
  266.                 }
  267.             }
  268.             if (x == printLocations.length|| (userprintloc.equals(printLocations[2]) && (this.sleeveLengthFinal.equals("None") || this.sleeveLengthFinal.equals("")))) {
  269.                 System.out.println("Sorry, invalid input!");
  270.                 x = 0;
  271.                 repeat = true;
  272.             } else if (userprintloc.equals("q")){
  273.                 break;
  274.             } else {
  275.                 System.out.println("You have chosen to make a print on " + printLocations[x] + ". Please type a description of the print, or type None to clear the print:");
  276.                 Scanner theprint = new Scanner(System.in);
  277.                 String myprint = theprint.nextLine();
  278.                 myprint = this.userprintdesc;
  279.                 break;
  280.             }
  281.  
  282.         } while (repeat);
  283.  
  284.     }
  285.  
  286.     public void showPrint(){
  287.         System.out.println("This is what is printed on your shirt: "+ this.userprintdesc);
  288.     }
  289.  
  290.     int quantity;
  291.     public void userSleeveLength() {
  292.         boolean repeat = false;
  293.         int x;
  294.         do {
  295.             System.out.println("Please select the " + this.sleeveLength[this.sleeveLength.length - 2] + " of your garment: ");
  296.             System.out.println("Press " + this.sleeveLength[this.sleeveLength.length - 1] + "to return to the previous menu.");
  297.  
  298.             for (x = 0; x < this.sleeveLength.length - 2; x++) { // using this. to take a class attribute
  299.                 System.out.println("Sleeve: " + this.sleeveLength[x]);
  300.             }
  301.             Scanner sleeveselection = new Scanner(System.in);
  302.             String userSleeveSelection = sleeveselection.nextLine();
  303.  
  304.             for (x = 0; x < this.sleeveLength.length; x++) {
  305.                 if (userSleeveSelection.equals(this.sleeveLength[x])){
  306.                     break;
  307.                 }
  308.             }
  309.  
  310.             if (x == (this.sleeveLength.length)) {
  311.                 System.out.println("Sorry, that was not a valid menu option");
  312.                 x = 0;
  313.                 repeat = true;
  314.             } else if (userSleeveSelection.equals("q")) {
  315.                 break;
  316.             } else {
  317.                 System.out.println("You have chosen " + this.sleeveLength[x]);
  318.                 this.setSleeveLengthFinal(userSleeveSelection);
  319.                 break;
  320.             }
  321.         } while (repeat);
  322.  
  323.     }
  324.     public void viewPockets(int b) {
  325.         int x;
  326.         for (x = 0; x < b; x++) { // maybe assign as function?
  327.             System.out.println(this.pockets[x][0] + "\t" + this.pockets[x][1]);
  328.         }
  329.     }
  330.  
  331. }
  332. import java.util.Scanner;
  333. import program_classes.topClothing;
  334. // use getters and setters in place of returns - Java does not automatically use values within methods.
  335. public class program {
  336.  
  337.  
  338.  
  339.     static int[] intInputVal(int[] userIntArray) {
  340.  
  341.         int repeat = 0;
  342.         int x;
  343.         do {
  344.  
  345.            System.out.println("Here is a list of the elements contained within your array: ");
  346.  
  347.            for (x = 0; x < userIntArray.length; x++) {
  348.                System.out.println(x + ". " + userIntArray[x]);
  349.            }
  350.  
  351.            Scanner intInput = new Scanner(System.in);
  352.            int userIntInput = intInput.nextInt();
  353.  
  354.            for (x = 0; x < userIntArray.length; x++) {
  355.                if (userIntInput == userIntArray[x] || userIntInput == x){
  356.                    break;
  357.                }
  358.            }
  359.  
  360.            if (x == userIntArray.length) {
  361.                System.out.println("Sorry, that was not a valid menu option");
  362.                x = 0;
  363.                repeat = 1;
  364.            } else {
  365.                System.out.println("You have chosen " + x + ". " + userIntArray[x]);
  366.                break;
  367.            }
  368.  
  369. //           for (int t: userArray) {
  370. //               System.out.println(x + ". " + t);
  371. //           }
  372.  
  373.         } while (repeat == 1);
  374.         return userIntArray;
  375.     }
  376.  
  377. //    public static void viewPockets(String [][] a, int b) {
  378. //        int x;
  379. //        for (x = 0; x < b; x++) { // maybe assign as function?
  380. //            System.out.println(a[x][0] + "\t" + a[x][1]);
  381. //        }
  382. //    }
  383.  
  384.     public static void main(String[] args){
  385.  
  386. //        System.out.println("Hello World!");
  387. //        int[] array = {33,34,35,36};
  388. //        intInputVal(array);
  389.         topClothing shirt = new topClothing(); // ask user to determine class instance? class instance name?
  390.  
  391.  
  392.  
  393.         boolean quit = false;
  394.         do {
  395.             System.out.println("You are here: Main menu");
  396.             System.out.println("Select: \na) Top clothing sleeve length\nb) Top clothing pockets\nc) Top clothing hood\nd) Top clothing fastening type\ne) Top prints \nx) \"View\" top \nq) Quit");
  397.  
  398.             Scanner select = new Scanner(System.in);
  399.             String userSelection = select.nextLine();
  400.  
  401.             switch (userSelection) {
  402.  
  403.                 case "a":
  404.  
  405.  
  406.                     boolean quit2 = false;
  407.                     do {
  408.                         System.out.println("You are here: Main menu > Top clothing sleeve length");
  409.                         System.out.println("Select: \na) Choose sleeve length\nb) View chosen sleeve length\nq) Return to previous menu");
  410.  
  411.                         Scanner select2 = new Scanner(System.in);
  412.                         String userSelection2 = select2.nextLine();
  413.                         switch (userSelection2) {
  414.                             case "a":
  415.                                 System.out.println("You are here: Main menu > Top clothing sleeve length > Choose sleeve length");
  416.                             //    shirt.getSleeveLengthFinal();
  417.                             //    strInputVal(shirt.sleeveLength);
  418.                             //    shirt.strInputVal();
  419.                                 //    shirt.pocketNumber(shirt.maxquantityPockets);
  420.                                 //    shirt = new topClothing("a2");
  421.                                 //    shirt.setName("b");
  422.                                 shirt.userSleeveLength();
  423.                                 break;
  424.                             case "b":
  425.                                 System.out.println("You are here: Main menu > Top clothing sleeve length > View chosen sleeve length");
  426.                                 shirt.getSleeveLengthFinal();
  427.                                 if (shirt.getSleeveLengthFinal().equals("")){
  428.                                     System.out.println("Sorry, you haven't chosen a sleeve length");
  429.                                 } else {
  430.                                     System.out.println("Here is the shirt sleeve length you have selected: " + shirt.getSleeveLengthFinal());
  431.                                 }
  432.                                 break;
  433.                             case "q":
  434.                                 quit2 = true;
  435.                                 break;
  436.                             default:
  437.  
  438.                                 break;
  439.                         }
  440.                     } while (quit2 != true);
  441.  
  442.                     break;
  443.                 case "b":
  444.                     boolean quit3 = false;
  445.                     do {
  446.                         System.out.println("You are here: Main menu > Top clothing pockets");
  447.                         System.out.println("Select: \na) Choose number of pockets\nb) Manage pocket properties\nc) View pockets\nq) Return to previous menu");
  448.                         Scanner select3 = new Scanner(System.in);
  449.                         String userSelection3 = select3.nextLine();
  450.  
  451.                         switch (userSelection3) {
  452.                             case "a":
  453.                                 shirt.setMaxquantityPockets(shirt.pocketNumber(shirt.getMaxquantityPockets()));
  454.                                 System.out.println(shirt.getMaxquantityPockets());
  455.                                 // shirt.managePockets(shirt.setPockets(shirt.getPockets()));
  456.                             //    shirt.setPockets(shirt.managePockets(shirt.getPockets()));
  457.  
  458.                             //    System.out.println(shirt.getMaxquantityPockets());
  459.  
  460.                                 break;
  461.                             case "b":
  462.                                 shirt.managePockets();
  463.                                 System.out.println(shirt.getMaxquantityPockets());
  464.                                 break;
  465.                             case "c":
  466.                                 System.out.println("Here are the pockets you have used and their properties: ");
  467.  
  468.                                 shirt.viewPockets(shirt.getMaxquantityPockets());
  469.                                 /*
  470.                                 int x;
  471.                                 for (x = 0; x < shirt.getMaxquantityPockets(); x++) { // maybe assign as function?
  472.                                     System.out.println(shirt.pockets[x][0] + "\t" + shirt.pockets[x][1]);
  473.                                 }
  474.                                 break;
  475.                                 */
  476.                                 break;
  477.                             case "q":
  478.                                 quit3 = true;
  479.                                 break;
  480.                             default:
  481.                                     System.out.println("Sorry, invalid input!");
  482.                                 break;
  483.  
  484.                         }
  485.                     } while (quit3 != true);
  486.                     break;
  487.                 case "c":
  488.                     shirt.userHood();
  489.                     break;
  490.                 case "d":
  491.                     shirt.userOpen();
  492.                     break;
  493.                 case "e":
  494.                     shirt.topPrint();
  495.                     break;
  496.                 case "x":
  497.                     System.out.println("Here are the final properties for your top: \nSleeves: " + shirt.getSleeveLengthFinal() + "\nPockets:");
  498.                     shirt.viewPockets(shirt.getMaxquantityPockets());
  499.                     System.out.println("");
  500.                     System.out.println("Hood? " + shirt.hood + "\nIs hood up? " + shirt.isHoodUp + "\nRequires fastening? " + shirt.topOpen + "\nFastener? " + shirt.topOpenFasten + "\nFastened? " + shirt.wearTopOpen);
  501.                     shirt.showPrint();
  502.                     break;
  503.                 case "q":
  504.                     quit = true;
  505.                     break;
  506.                 default:
  507.                     System.out.println("Sorry, that is not valid input, please try again.");
  508.                     break;
  509.             }
  510.         } while (quit != true);
  511.     }
  512.  
  513.  
  514.  
  515. }
Advertisement
Add Comment
Please, Sign In to add comment