Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package program_classes;
- import java.util.Scanner;
- public class topClothing {
- //private String name = "top1";
- // public topClothing(String a) {
- // this.setName(a);
- // }
- //public String getName() {
- // return name;
- //}
- //private void setName(String d) {
- // this.name = d;
- // }
- // private variables allow them to be inaccessible outside public class-specific functions and methods
- private String[] sleeveLength = {"None", "Cap sleeves", "Short sleeves", "3/4 length sleeves", "Long sleeves", "Long sleeves with holes", "shirt sleeve length", "q"};
- private String sleeveLengthFinal = "None";
- private String primaryColor;
- private String secondaryColor;
- private String[] mannerWorn = {"Tucked over bottom", "Tucked under bottom", "Worn around waist"}; // 3rd option only for long sleeves
- private int maxquantityPockets = 7;
- private String[][] pockets = new String[maxquantityPockets][2]; // second array value for properties
- public int getMaxquantityPockets() { // should be int
- return maxquantityPockets;
- }
- public String[][] getPockets() {
- return pockets;
- }
- public String[][] setPockets(String[][] a) {
- this.pockets = a;
- return a;
- }
- public String[] getSleeveLength() {
- return sleeveLength;
- }
- public String getSleeveLengthFinal(){
- return sleeveLengthFinal;
- }
- private void setSleeveLengthFinal(String x){
- this.sleeveLengthFinal = x;
- }
- public void setMaxquantityPockets(int z) { // should be void
- this.maxquantityPockets = z;
- // return z;
- }
- public int pocketNumber(int q) {
- boolean repeat = false;
- do {
- System.out.print("Please select the number of pockets you want to work with: ");
- Scanner qu = new Scanner(System.in);
- int userQu = qu.nextInt();
- if (userQu > 7 || userQu < 1) {
- System.out.println("Sorry, that is not a valid number of pockets. ");
- repeat = true;
- } else {
- System.out.println("You have chosen " + userQu + " pockets to work with. ");
- q = userQu; // LEFT declares value, RIGHT assigns value
- repeat = false;
- int x;
- for (x = 0; x < getMaxquantityPockets(); x++) { // invoke class attributes
- pockets[x][0] = ("Pocket " + (x + 1));
- pockets[x][1] = ("None");
- }
- break;
- } // once this complete, values erased.
- } while (repeat);
- return q;
- }
- // get user input and validate it
- // if outside of maximum pocket range, reject input
- // user access to individual pockets and their individual properties
- // public int managePocketsQuantity.getQuantf
- public void managePockets() { // get value from outside method and set within method?
- boolean repeat = false;
- int x;
- int y;
- System.out.println(getMaxquantityPockets());
- for (x = 0; x < getMaxquantityPockets(); x++) { // invoke class attributes
- this.pockets[x][0] = ("Pocket " + (x+1));
- this.pockets[x][1] = ("None");
- System.out.println(this.pockets[x][0]);
- }
- do {
- System.out.println("Please enter the pocket you want to work with (press q to return to previous menu): ");
- Scanner pocket = new Scanner(System.in);
- String userPocket = pocket.nextLine();
- for (x = 0; x < getMaxquantityPockets(); x++) {
- if (userPocket.equals(this.pockets[x][0])) {
- break;
- }
- }
- if (x == getMaxquantityPockets() && !(userPocket.equals("q"))) {
- System.out.println("Sorry, we cannot work with that pocket.");
- x = 0;
- repeat = true;
- } else if (x == getMaxquantityPockets() && userPocket.equals("q")){
- break;
- } else {
- System.out.println("You have chosen to work with " + this.pockets[x][0]);
- System.out.println("What properties would you like to have for this pocket?");
- Scanner property = new Scanner(System.in);
- String userProperty = property.nextLine();
- this.pockets[x][1] = userProperty;
- System.out.println(this.pockets[x][0] + " has the following properties: " + this.pockets[x][1]);
- repeat = false;
- }
- } while (repeat);
- // return a;
- }
- // int repeat2 = 0;
- // int y;
- public boolean hood;
- public boolean isHoodUp;
- public boolean topOpen;
- public boolean wearTopOpen;
- public String topOpenFasten;
- public void userHood() {
- boolean repeat = false;
- do {
- System.out.print("Would you like a hood with your top? (y/n) ");
- Scanner option = new Scanner(System.in);
- String userOption = option.nextLine();
- switch (userOption) {
- case "y":
- boolean repeat2 = false;
- do {
- this.hood = true;
- System.out.print("You have chosen to include a hood to your top. Would you like to wear it up? (y/n) ");
- Scanner option2 = new Scanner(System.in);
- String userOption2 = option2.nextLine();
- switch (userOption2) {
- case "y":
- System.out.println("You have chosen to wear it up.");
- isHoodUp = true;
- break;
- case "n":
- System.out.println("You have chosen to wear it down.");
- isHoodUp = false;
- break;
- default:
- System.out.println("Sorry, invalid input!");
- repeat2 = true;
- break;
- }
- } while (repeat2);
- break;
- case "n":
- System.out.println("You have chosen not to include a hood with your top.");
- this.hood = false;
- this.isHoodUp = false;
- break;
- default:
- System.out.println("Sorry, invalid input!");
- repeat = true;
- break;
- }
- } while (repeat);
- }
- public void userOpen(){
- boolean repeat = false;
- do {
- System.out.print("Would you like your clothing to be open or closed? (open/closed) ");
- Scanner closeopen = new Scanner(System.in);
- String userCloseOpen = closeopen.nextLine();
- switch (userCloseOpen) {
- case "open":
- topOpen = true;
- System.out.print("You have chosen to have an open top. Select the fastener: ");
- Scanner fastener = new Scanner(System.in);
- String userFastener = fastener.nextLine();
- this.topOpenFasten = userFastener;
- Scanner fasten = new Scanner(System.in);
- String userFasten = fasten.nextLine();
- System.out.print("Would you like to wear it open or closed? (open/closed) ");
- boolean repeat2 = false;
- do {
- switch (userFasten) {
- case "open":
- wearTopOpen = true;
- System.out.println("You have chosen to wear your top open.");
- break;
- case "closed":
- wearTopOpen = false;
- System.out.println("You have chosen to wear your top closed.");
- break;
- default:
- System.out.println("Sorry, invalid input!");
- repeat2 = true;
- break;
- }
- } while (repeat2);
- break;
- case "closed":
- topOpen = false;
- wearTopOpen = false;
- this.topOpenFasten = "None";
- System.out.println("You have chosen to have a closed top.");
- break;
- default:
- System.out.println("Sorry, invalid input!");
- repeat = true;
- break;
- }
- } while (repeat); // simplified from repeat == true;
- }
- private String userprintdesc = "None";
- public void topPrint(){
- String[] printLocations = {"Chest", "Back", "Sleeves", "q"}; // 3rd option can't be applied with sleeveless
- boolean repeat = false;
- int x;
- do {
- System.out.println("Please select a print location, or press q to go back: ");
- for (x = 0; x < 3; x++) {
- System.out.println(printLocations[x]);
- }
- Scanner printloc = new Scanner(System.in);
- String userprintloc = printloc.nextLine();
- for (x = 0; x < printLocations.length; x++) {
- if (userprintloc.equals(printLocations[x])) {
- break;
- }
- }
- if (x == printLocations.length|| (userprintloc.equals(printLocations[2]) && (this.sleeveLengthFinal.equals("None") || this.sleeveLengthFinal.equals("")))) {
- System.out.println("Sorry, invalid input!");
- x = 0;
- repeat = true;
- } else if (userprintloc.equals("q")){
- break;
- } else {
- 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:");
- Scanner theprint = new Scanner(System.in);
- String myprint = theprint.nextLine();
- myprint = this.userprintdesc;
- break;
- }
- } while (repeat);
- }
- public void showPrint(){
- System.out.println("This is what is printed on your shirt: "+ this.userprintdesc);
- }
- int quantity;
- public void userSleeveLength() {
- boolean repeat = false;
- int x;
- do {
- System.out.println("Please select the " + this.sleeveLength[this.sleeveLength.length - 2] + " of your garment: ");
- System.out.println("Press " + this.sleeveLength[this.sleeveLength.length - 1] + "to return to the previous menu.");
- for (x = 0; x < this.sleeveLength.length - 2; x++) { // using this. to take a class attribute
- System.out.println("Sleeve: " + this.sleeveLength[x]);
- }
- Scanner sleeveselection = new Scanner(System.in);
- String userSleeveSelection = sleeveselection.nextLine();
- for (x = 0; x < this.sleeveLength.length; x++) {
- if (userSleeveSelection.equals(this.sleeveLength[x])){
- break;
- }
- }
- if (x == (this.sleeveLength.length)) {
- System.out.println("Sorry, that was not a valid menu option");
- x = 0;
- repeat = true;
- } else if (userSleeveSelection.equals("q")) {
- break;
- } else {
- System.out.println("You have chosen " + this.sleeveLength[x]);
- this.setSleeveLengthFinal(userSleeveSelection);
- break;
- }
- } while (repeat);
- }
- public void viewPockets(int b) {
- int x;
- for (x = 0; x < b; x++) { // maybe assign as function?
- System.out.println(this.pockets[x][0] + "\t" + this.pockets[x][1]);
- }
- }
- }
- import java.util.Scanner;
- import program_classes.topClothing;
- // use getters and setters in place of returns - Java does not automatically use values within methods.
- public class program {
- static int[] intInputVal(int[] userIntArray) {
- int repeat = 0;
- int x;
- do {
- System.out.println("Here is a list of the elements contained within your array: ");
- for (x = 0; x < userIntArray.length; x++) {
- System.out.println(x + ". " + userIntArray[x]);
- }
- Scanner intInput = new Scanner(System.in);
- int userIntInput = intInput.nextInt();
- for (x = 0; x < userIntArray.length; x++) {
- if (userIntInput == userIntArray[x] || userIntInput == x){
- break;
- }
- }
- if (x == userIntArray.length) {
- System.out.println("Sorry, that was not a valid menu option");
- x = 0;
- repeat = 1;
- } else {
- System.out.println("You have chosen " + x + ". " + userIntArray[x]);
- break;
- }
- // for (int t: userArray) {
- // System.out.println(x + ". " + t);
- // }
- } while (repeat == 1);
- return userIntArray;
- }
- // public static void viewPockets(String [][] a, int b) {
- // int x;
- // for (x = 0; x < b; x++) { // maybe assign as function?
- // System.out.println(a[x][0] + "\t" + a[x][1]);
- // }
- // }
- public static void main(String[] args){
- // System.out.println("Hello World!");
- // int[] array = {33,34,35,36};
- // intInputVal(array);
- topClothing shirt = new topClothing(); // ask user to determine class instance? class instance name?
- boolean quit = false;
- do {
- System.out.println("You are here: Main menu");
- 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");
- Scanner select = new Scanner(System.in);
- String userSelection = select.nextLine();
- switch (userSelection) {
- case "a":
- boolean quit2 = false;
- do {
- System.out.println("You are here: Main menu > Top clothing sleeve length");
- System.out.println("Select: \na) Choose sleeve length\nb) View chosen sleeve length\nq) Return to previous menu");
- Scanner select2 = new Scanner(System.in);
- String userSelection2 = select2.nextLine();
- switch (userSelection2) {
- case "a":
- System.out.println("You are here: Main menu > Top clothing sleeve length > Choose sleeve length");
- // shirt.getSleeveLengthFinal();
- // strInputVal(shirt.sleeveLength);
- // shirt.strInputVal();
- // shirt.pocketNumber(shirt.maxquantityPockets);
- // shirt = new topClothing("a2");
- // shirt.setName("b");
- shirt.userSleeveLength();
- break;
- case "b":
- System.out.println("You are here: Main menu > Top clothing sleeve length > View chosen sleeve length");
- shirt.getSleeveLengthFinal();
- if (shirt.getSleeveLengthFinal().equals("")){
- System.out.println("Sorry, you haven't chosen a sleeve length");
- } else {
- System.out.println("Here is the shirt sleeve length you have selected: " + shirt.getSleeveLengthFinal());
- }
- break;
- case "q":
- quit2 = true;
- break;
- default:
- break;
- }
- } while (quit2 != true);
- break;
- case "b":
- boolean quit3 = false;
- do {
- System.out.println("You are here: Main menu > Top clothing pockets");
- System.out.println("Select: \na) Choose number of pockets\nb) Manage pocket properties\nc) View pockets\nq) Return to previous menu");
- Scanner select3 = new Scanner(System.in);
- String userSelection3 = select3.nextLine();
- switch (userSelection3) {
- case "a":
- shirt.setMaxquantityPockets(shirt.pocketNumber(shirt.getMaxquantityPockets()));
- System.out.println(shirt.getMaxquantityPockets());
- // shirt.managePockets(shirt.setPockets(shirt.getPockets()));
- // shirt.setPockets(shirt.managePockets(shirt.getPockets()));
- // System.out.println(shirt.getMaxquantityPockets());
- break;
- case "b":
- shirt.managePockets();
- System.out.println(shirt.getMaxquantityPockets());
- break;
- case "c":
- System.out.println("Here are the pockets you have used and their properties: ");
- shirt.viewPockets(shirt.getMaxquantityPockets());
- /*
- int x;
- for (x = 0; x < shirt.getMaxquantityPockets(); x++) { // maybe assign as function?
- System.out.println(shirt.pockets[x][0] + "\t" + shirt.pockets[x][1]);
- }
- break;
- */
- break;
- case "q":
- quit3 = true;
- break;
- default:
- System.out.println("Sorry, invalid input!");
- break;
- }
- } while (quit3 != true);
- break;
- case "c":
- shirt.userHood();
- break;
- case "d":
- shirt.userOpen();
- break;
- case "e":
- shirt.topPrint();
- break;
- case "x":
- System.out.println("Here are the final properties for your top: \nSleeves: " + shirt.getSleeveLengthFinal() + "\nPockets:");
- shirt.viewPockets(shirt.getMaxquantityPockets());
- System.out.println("");
- System.out.println("Hood? " + shirt.hood + "\nIs hood up? " + shirt.isHoodUp + "\nRequires fastening? " + shirt.topOpen + "\nFastener? " + shirt.topOpenFasten + "\nFastened? " + shirt.wearTopOpen);
- shirt.showPrint();
- break;
- case "q":
- quit = true;
- break;
- default:
- System.out.println("Sorry, that is not valid input, please try again.");
- break;
- }
- } while (quit != true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment