Advertisement
scaawt

Homework06(Back End)

Dec 4th, 2018
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. /**
  2.  * written by tariq scott
  3.  */
  4. public class Dresser {
  5.  
  6.   //array for the max clothes and dresser
  7.   private Dresser [][] dresser;
  8.   public static final int MAX_CLOTHES = 10;
  9.   public static final int MAX_DRAWER = 5;
  10.  
  11.   public Dresser ()
  12.   {
  13.     dresser = new Dresser [MAX_DRAWER][MAX_CLOTHES];
  14.   }
  15.  
  16.   public Dresser [][] getDresser()
  17.   {
  18.     return this.dresser;
  19.   }
  20.  
  21.   //adds clothing to empty spot of the drawer
  22.   public void addClothing (Dresser addClothing)
  23.   {
  24.     for (int i =0; i < dresser.length; i++)
  25.     {
  26.       for (int j = 0; j <dresser.length; j++)
  27.     {
  28.       if (dresser [i][j] == null)
  29.             {
  30.         dresser [i][j] = addClothing;
  31.         return;
  32.       }
  33.     }
  34.   }
  35.   }
  36.  
  37. //System.out.println("The dresser is full!");
  38.  
  39. //removing clothes where from where they are
  40. public void removeClothing (Dresser addClothing)
  41.   {
  42.     for (int i =0; i < dresser.length; i++)
  43.     {
  44.       for (int j = 0; j <dresser.length; j++)
  45.     {
  46.       if (dresser [i][j] != null && dresser [i][j].equals(addClothing))
  47.       {
  48.         dresser[i][j] = null;
  49.         return;
  50.       }
  51.     }
  52.     }
  53. }
  54.  
  55.     public void printDresser()
  56.     {
  57.       for (int i=0; i < dresser.length; i++)
  58.       {
  59.        for (int j=0; j < dresser.length; j++)
  60.         {
  61.           if (dresser[i][j] == null)
  62.           {
  63.             break;
  64.           }
  65.           System.out.println(dresser[i][j]);
  66.     }
  67.       }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement