Advertisement
JackOUT

Untitled

Jan 11th, 2024
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | None | 0 0
  1. package com.bcs2024.knapsack.model;
  2.  
  3. /**
  4.  * Represents a parcel with specific dimensions and value.
  5.  * Each parcel has a type, length, width, height, and an associated value.
  6.  */
  7. public class Parcel {
  8.     private int value;
  9.     private final String type;
  10.     private int[][][][] shape; // 4D array to represent 3D shapes with orientations
  11.  
  12.     // Constructor for parcels (A, B, C, L, P, T)
  13.     public Parcel(final String type) {
  14.         this.type = type;
  15.         this.shape = ShapesAndRotations.getRotations(this.type);
  16.         initializeParcel();
  17.     }
  18.  
  19.     private void initializeParcel() {
  20.         switch (type) {
  21.             case "A" -> this.value = 1;
  22.             case "B" -> this.value = 2;
  23.             case "C", "L" -> this.value = 3;
  24.             case "P" -> this.value = 4;
  25.             case "T" -> this.value = 5;
  26.             default -> System.out.println("Invalid type");
  27.         }
  28.     }
  29.  
  30.     /**
  31.      * Retrieves a specific orientation of the parcel's shape.
  32.      *
  33.      * @param orientationIndex The index of the desired orientation.
  34.      * @return The 3D boolean array representing the specified orientation of the shape.
  35.      * @throws IllegalArgumentException if the orientation index is out of bounds.
  36.      */
  37.     public int[][][] getShapeOrientation(int orientationIndex) {
  38.         if (orientationIndex < 0 || orientationIndex >= shape.length) {
  39.             throw new IllegalArgumentException("Invalid orientation index");
  40.         }
  41.         return shape[orientationIndex];
  42.     }
  43.  
  44.     /**
  45.      * Returns the shape of the parcel with its orientation.
  46.      *
  47.      * @return The shape of the parcel.
  48.      */
  49.     public int[][][][] getShape() {
  50.         return shape;
  51.     }
  52.  
  53.     /**
  54.      * Sets the shape of the parcel with its orientation.
  55.      *
  56.      * @param shape The new shape of the parcel.
  57.      */
  58.     public void setShape(int[][][][] shape) {
  59.         this.shape = shape;
  60.     }
  61.  
  62.     /**
  63.      * Returns the value of the parcel.
  64.      *
  65.      * @return The value of the parcel.
  66.      */
  67.     public double getValue() {
  68.         return value;
  69.     }
  70.  
  71.     /**
  72.      * Returns the type of the parcel.
  73.      *
  74.      * @return The type of the parcel.
  75.      */
  76.     public String getType() {
  77.         return type;
  78.     }
  79. }
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement