Skip to content

Adding In Constructors to item and item classes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
public class Book extends Item {

private int pageCount;

// Book constructor
public Book(String t, String des, double p, int pageCount) {
super(t, des, p);
this.pageCount = pageCount;
}

public int getPageCount()
{
Expand Down
7 changes: 7 additions & 0 deletions CD.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package Project3_Store;

public class CD extends Item {

private int trackCount;

// CD constructor
public CD(String t, String des, double p, int trackCount) {
super(t, des, p);
this.trackCount = trackCount;
}

public int getTrackCount()
{
Expand Down
28 changes: 28 additions & 0 deletions Fruit.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
5 changes: 3 additions & 2 deletions Item.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,6 +41,7 @@ public void setPrice(double newPrice)
{
this.price = newPrice;
}

public String toString()
{
String s = "\nTitle:" + getTitle() + "\nPrice: $ "+ getPrice() +"\nDescription: "+getDescription();
Expand Down
28 changes: 28 additions & 0 deletions Meat.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
7 changes: 7 additions & 0 deletions Movie.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package Project3_Store;

public class Movie extends Item {

private double movieLength;

// Movie constructor
public Movie(String t, String des, double p, double length) {
super(t, des, p);
this.movieLength = length;
}

public double getMovieLength()
{
Expand Down
52 changes: 51 additions & 1 deletion Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Meat> meatStock = new ArrayList<Meat>(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<Fruit> fruitStock = new ArrayList<Fruit>(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<Vegetable> vegetableStock = new ArrayList<Vegetable>(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<Item> s) {
this.stock = s ;
Expand Down
28 changes: 28 additions & 0 deletions Vegetable.java
Original file line number Diff line number Diff line change
@@ -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";
}
}