Created
March 3, 2016 15:10
-
-
Save SamuelSchwent/eb678248ff8826364837 to your computer and use it in GitHub Desktop.
Java - Aggregation Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package Challenge2; | |
| public class DisplayInventoryItem { | |
| public static void main(String[] args) { | |
| String description = "This is a large Bolt."; | |
| double units = 13; | |
| InventoryItem item1 = new InventoryItem(description, units); | |
| InventoryItem item2 = new InventoryItem(item1); | |
| System.out.println("Item 1 Units: " + item1.units); | |
| System.out.println(item1.description); | |
| System.out.println("Item 2 Units: " + item2.units); | |
| System.out.println(item2.description); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package Challenge2; | |
| public class InventoryItem { | |
| String description; | |
| Double units; | |
| public InventoryItem(String description, double units) | |
| { | |
| this.description = description; | |
| this.units = units; | |
| } | |
| public InventoryItem(InventoryItem item) | |
| { | |
| description = item.description; | |
| units = item.units; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment