diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9793229 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..88d680d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/SE Project.iml b/SE Project.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/SE Project.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Item.java b/src/Item.java new file mode 100644 index 0000000..a81a056 --- /dev/null +++ b/src/Item.java @@ -0,0 +1,55 @@ + +public class Item +{ + String item_description; // Stores the name for the item description + int quantity; // Stores the quantity of the item + double price; // Stores the price of the item + String date_purchased; // Stores the date purchased for the item + String time_stamp; //Stores the time stamp for the item + + + // Constructor method + public Item(String item_description, int quantity, double price, String date_purchased, String time_stamp){ + super(); + this.item_description = item_description; + this.quantity = quantity; + this.price = price; + this.date_purchased = date_purchased; + this.time_stamp = time_stamp; + } + + //get and set methods to access and modify the variables + public String getItem_Description(){ + return item_description; + } + public int getQuantity(){ + return quantity; + } + public double getPrice(){ + return price; + } + public String getDate_purchased(){ + return date_purchased; + } + public String getTime_stamp(){ + return time_stamp; + } + + public void setItem_description(String item_description){ + this.item_description = item_description; + } + public void setQuantity(int quantity){ + this.quantity = quantity; + } + public void setPrice(double price){ + this.price = price; + } + public void setDate_purchased(String date_purchased){ + this.date_purchased = date_purchased; + } + public void setTime_stamp(String time_stamp){ + this.time_stamp = time_stamp; + } + + +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..d9172cc --- /dev/null +++ b/src/Main.java @@ -0,0 +1,22 @@ +import java.util.Hashtable; +import java.util.Set; + +public class Main { + public static void main (String args[]) throws Exception{ + Hashtable hash = new Hashtable (); //Creates a hash table called "hash" that stores an integer as key and "Item" object as value + + hash.put(1, new Item("Orange", 5, 1.25, "01-24-17", "02-31-18")); //Add new items to our hashtable + hash.put(2, new Item("Apple", 10, 2.25, "05-21-17", "05-12-18")); + hash.put(3, new Item("Banana", 23, 0.99, "02-01-17", "02-01-18")); + + Set keys = hash.keySet(); //Get a set view of the keys contained in the table + + System.out.println("Inventory ID | Item Description | Quantity | Price | Date Purchased | Time Stamp"); //Prints out the headers of each field + + // Iterate through the items in the hashtable and retrieve the variables in the object Item, and print them out corresponding to its headers + for (Integer key : keys){ + Item item = hash.get(key); + System.out.println(key + " | " + item.getItem_Description() + " | " + item.getQuantity() + " | " + item.getPrice() + " | " + item.getDate_purchased() + " | " + item.getTime_stamp()); + } + } +}