Answer to Question #236859 in Java | JSP | JSF for Flying Bird

Question #236859
in java language Design a wardrobe management system. The system should have the following classes:  Dress: having information about dress code, color, material and brand of dress Dress collection: having two different collections (arrays) each for formal and casual dresses Wardrobe class having main() The system must support the addition and removal of different types (formal and casual) of dresses.  Write code in java and submit working code files. Follow principles of abstraction and encapsulation.
1
Expert's answer
2021-09-14T00:41:47-0400
public class Dress {
    private int code;
    private String color;
    private String material;
    private String brand;

    public Dress(int code, String color, String material, String brand) {
        this.code = code;
        this.color = color;
        this.material = material;
        this.brand = brand;
    }

    public int getCode() {
        return code;
    }
}


public class DressCollection {
    private Dress[] formal;
    private Dress[] casual;
    private int formalTail;
    private int casualTail;

    public DressCollection(int size) {
        formal = new Dress[size];
        casual = new Dress[size];
        formalTail = 0;
        casualTail = 0;
    }

    public boolean addCasual(Dress dress) {
        if (casualTail == casual.length) {
            return false;
        }
        casual[casualTail++] = dress;
        return true;
    }

    public boolean addFormal(Dress dress) {
        if (formalTail == formal.length) {
            return false;
        }
        formal[formalTail++] = dress;
        return true;
    }

    public boolean removeCasual(int code) {
        for (int i = 0; i < casualTail; i++) {
            if (casual[i].getCode() == code) {
                for (int j = i + 1; j < casualTail; j++) {
                    casual[j - 1] = casual[j];
                }
                casual[--casualTail] = null;
                return true;
            }
        }
        return false;
    }

    public boolean removeFormal(int code) {
        for (int i = 0; i < formalTail; i++) {
            if (formal[i].getCode() == code) {
                for (int j = i + 1; j < formalTail; j++) {
                    formal[j - 1] = formal[j];
                }
                formal[--formalTail] = null;
                return true;
            }
        }
        return false;
    }
}


import java.util.Scanner;

public class Wardrobe {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        DressCollection dressCollection = new DressCollection(3);
        String choice;
        int code;
        String color;
        String material;
        String brand;
        while (true) {
            System.out.println("1. Add casual\n2. Remove casual\n" +
                    "3. Add formal\n4. Remove formal\n0. Exit");
            choice = in.nextLine();
            switch (choice) {
                case "1":
                case "3":
                    System.out.println("Code:");
                    code = Integer.parseInt(in.nextLine());
                    System.out.println("Color:");
                    color = in.nextLine();
                    System.out.println("Material:");
                    material = in.nextLine();
                    System.out.println("Brand:");
                    brand = in.nextLine();
                    if (choice.equals("1")) {
                        System.out.println(dressCollection.addCasual(new Dress(code, color, material, brand)));
                    } else {
                        System.out.println(dressCollection.addFormal(new Dress(code, color, material, brand)));
                    }
                    break;
                case "2":
                case "4":
                    System.out.println("Code:");
                    code = Integer.parseInt(in.nextLine());
                    if (choice.equals("2")) {
                        System.out.println(dressCollection.removeCasual(code));
                    } else {
                        System.out.println(dressCollection.removeFormal(code));
                    }
                    break;
                case "0":
                    System.exit(0);
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS