From f9417ec1cab6449275463ec676e7647b946ba4b8 Mon Sep 17 00:00:00 2001 From: ianseki Date: Sat, 16 Nov 2019 15:44:58 -0800 Subject: [PATCH 1/2] Adding In Constructors to item and item classes I also got rid of the item id because I don't think they don't need a unique ID being that the items are kinda unique already --- Book.java | 8 ++++++++ CD.java | 9 +++++++++ Item.java | 5 +++-- Movie.java | 9 +++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Book.java b/Book.java index 35e8c2b..c28a3eb 100644 --- a/Book.java +++ b/Book.java @@ -3,6 +3,14 @@ public class Book extends Item { private int pageCount; + + // Book constructor + public Book(String t, String des, double p, int pageCount) { + this.title = t; + this.description = des; + this.price = p; + this.pageCount = pageCount + } public int getPageCount() { diff --git a/CD.java b/CD.java index a749da9..89e2ee2 100644 --- a/CD.java +++ b/CD.java @@ -1,7 +1,16 @@ package Project3_Store; public class CD extends Item { + private int trackCount; + + // CD constructor + public CD(String t, String des, double p, int trackCount) { + this.title = t; + this.description = des; + this.price = p; + this.trackCount = trackCount; + } public int getTrackCount() { diff --git a/Item.java b/Item.java index cd5f7f4..cb83142 100644 --- a/Item.java +++ b/Item.java @@ -1,17 +1,17 @@ package Project3_Store; public class Item { - int id; String title; String description; double price; + // Generic Item constructor public Item(String t, String des, double p) { - id =+ 1; this.title = t; this.description = des; this.price = p; } + public String getTitle() { return title; @@ -41,6 +41,7 @@ public void setPrice(double newPrice) { this.price = newPrice; } + public String toString() { String s = "\nTitle:" + getTitle() + "\nPrice: $ "+ getPrice() +"\nDescription: "+getDescription(); diff --git a/Movie.java b/Movie.java index 34dd00a..d72b520 100644 --- a/Movie.java +++ b/Movie.java @@ -1,7 +1,16 @@ package Project3_Store; public class Movie extends Item { + private double movieLength; + + // Movie constructor + public Movie(String t, String des, double p, double length) { + this.title = t; + this.description = des; + this.price = p; + this.movieLength = length; + } public double getMovieLength() { From 66bf213df67a6941da5c0acb2a1c40238fa4df09 Mon Sep 17 00:00:00 2001 From: ianseki Date: Sat, 16 Nov 2019 17:34:19 -0800 Subject: [PATCH 2/2] Adding Bowen's Item Classes and Created arrayList Stocks for them Made minor adjustments to Bowen's classes and condensed some of the item classes code --- Book.java | 6 ++---- CD.java | 4 +--- Fruit.java | 28 +++++++++++++++++++++++++++ Meat.java | 28 +++++++++++++++++++++++++++ Movie.java | 4 +--- Store.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- Vegetable.java | 28 +++++++++++++++++++++++++++ 7 files changed, 139 insertions(+), 11 deletions(-) create mode 100644 Fruit.java create mode 100644 Meat.java create mode 100644 Vegetable.java diff --git a/Book.java b/Book.java index c28a3eb..c305288 100644 --- a/Book.java +++ b/Book.java @@ -6,10 +6,8 @@ public class Book extends Item { // Book constructor public Book(String t, String des, double p, int pageCount) { - this.title = t; - this.description = des; - this.price = p; - this.pageCount = pageCount + super(t, des, p); + this.pageCount = pageCount; } public int getPageCount() diff --git a/CD.java b/CD.java index 89e2ee2..35260a1 100644 --- a/CD.java +++ b/CD.java @@ -6,9 +6,7 @@ public class CD extends Item { // CD constructor public CD(String t, String des, double p, int trackCount) { - this.title = t; - this.description = des; - this.price = p; + super(t, des, p); this.trackCount = trackCount; } diff --git a/Fruit.java b/Fruit.java new file mode 100644 index 0000000..e12f9cc --- /dev/null +++ b/Fruit.java @@ -0,0 +1,28 @@ +package Project3_Store; + +public class Fruit extends Item { + + private int weightCount; + + public Fruit(String t, String des, double p, int weight) { + super(t,des,p); + this.weightCount = weight; + } + + public int getweightCount() + { + return weightCount; + } + + public void setweightCount(int newweightCount) + { + this.weightCount = newweightCount; + } + + @Override + public String toString() + { + return "Title: " + title + "\nPrice: $" + price +"\nDescription: " + + description + "\nWeight Count: " + weightCount + "lb\n"; + } +} diff --git a/Meat.java b/Meat.java new file mode 100644 index 0000000..9c3b096 --- /dev/null +++ b/Meat.java @@ -0,0 +1,28 @@ +package Project3_Store; + +public class Meat extends Item { + + private int weightCount; + + public Meat(String t, String des, double p, int weight) { + super(t,des,p); + this.weightCount = weight; + } + + public int getweightCount() + { + return weightCount; + } + + public void setweightCount(int newweightCount) + { + this.weightCount = newweightCount; + } + + @Override + public String toString() + { + return "Title: " + title + "\nPrice: $" + price +"\nDescription: " + + description + "\nWeight Count: " + weightCount + "lb\n"; + } +} diff --git a/Movie.java b/Movie.java index d72b520..3d435ac 100644 --- a/Movie.java +++ b/Movie.java @@ -6,9 +6,7 @@ public class Movie extends Item { // Movie constructor public Movie(String t, String des, double p, double length) { - this.title = t; - this.description = des; - this.price = p; + super(t, des, p); this.movieLength = length; } diff --git a/Store.java b/Store.java index 800fcee..cb9eebe 100644 --- a/Store.java +++ b/Store.java @@ -5,7 +5,7 @@ public class Store { // Max amount of different items in stock - private int maxStock = 6; + private int maxStock = 10; // Arbitrary number for max amount of items in specific inventory private int maxInventory = 10; @@ -64,6 +64,56 @@ public class Store { // Adding cdStock to stock ArrayList stock.add(bookStock); + // Creating an ArrayList meatStock for meat in stock + private ArrayList meatStock = new ArrayList(maxInventory); + + // Creating different meats to stock the meatStock ArrayList + private meat1 = new Meat("Ground Beef", "All Natural* 93% Lean/7% Fat Lean Ground Beef Roll", 4.77, 1); + private meat2 = new Meat("Chicken Breast", "Foster Farms Family Pack of Boneless Skinless " + + "Chicken Breast", 9.69, 3); + private meat3 = new Meat("Ground Beef Patty", "All Natural* 85% Lean/15% Fat " + + "Angus Steak Patties 12 Count", 16.48, 4); + + // Adding meat to meatStock ArrayList + meatStock.add(meat1); + meatStock.add(meat2); + meatStock.add(meat3); + + // Adding meatStock to stock ArrayList + stock.add(meatStock); + + // Creating fruitStock + private ArrayList fruitStock = new ArrayList(maxInventory); + + // Creating different fruits to stock the fruitStock ArrayList + private fruit1 = new Fruit("Strawberries", "Stem Strawberries", 3.34, 2); + private fruit2 = new Fruit("Oranges", "Navel Oranges", 6.48, 5); + private fruit3 = new Fruit("Peaches", "Organic Peaches", 4.29, 2); + + // Adding fruits to fruitStock ArrayList + fruitStock.add(fruit1); + fruitStock.add(fruit2); + fruitStock.add(fruit3); + + // Adding fruitStock to stock ArrayList + stock.add(fruitStock); + + // Creating vegetableStock + private ArrayList vegetableStock = new ArrayList(maxInventory); + + // Creating vegetables to stock the vegetableStock ArrayList + private vegetable1 = new Vegetable("Carrots", "Peeled Baby-Cut Carrots", 1.84, 2); + private vegetable2 = new Vegetable("Sweet Potatoes", "Sweet Potato Bag", 3.19, 3); + private vegetable3 = new Vegetable("Bell Peppers", "Sweet Mini Peppers Bag", 2.98, 1); + + // Adding vegetables to vegetableStock ArrayList + vegetableStock.add(vegetable1); + vegetableStock.add(vegetable2); + vegetableStock.add(vegetable3); + + // Adding vegetableStock to stock ArrayList + stock.add(vegetableStock); + // getters and setters public void setStock(ArrayList s) { this.stock = s ; diff --git a/Vegetable.java b/Vegetable.java new file mode 100644 index 0000000..51c73be --- /dev/null +++ b/Vegetable.java @@ -0,0 +1,28 @@ +package Project3_Store; + +public class Vegetable extends Item { + + private int weightCount; + + public Vegetable(String t, String des, double p, int weight) { + super(t,des,p); + this.weightCount = weight; + } + + public int getweightCount() + { + return weightCount; + } + + public void setweightCount(int newweightCount) + { + this.weightCount = newweightCount; + } + + @Override + public String toString() + { + return "Title: " + title + "\nPrice: $" + price +"\nDescription: " + + description + "\nWeight Count: " + weightCount + "lb\n"; + } +}