diff --git a/TwoLiterStack/.classpath b/TwoLiterStack/.classpath
new file mode 100644
index 0000000..8a1a773
--- /dev/null
+++ b/TwoLiterStack/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/TwoLiterStack/bin/.classpath b/TwoLiterStack/bin/.classpath
new file mode 100644
index 0000000..8a1a773
--- /dev/null
+++ b/TwoLiterStack/bin/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/TwoLiterStack/bin/.gitignore b/TwoLiterStack/bin/.gitignore
index ddf9c65..4f00cd9 100644
--- a/TwoLiterStack/bin/.gitignore
+++ b/TwoLiterStack/bin/.gitignore
@@ -1 +1 @@
-/main/
+/src/
diff --git a/TwoLiterStack/bin/.project b/TwoLiterStack/bin/.project
new file mode 100644
index 0000000..6aadb80
--- /dev/null
+++ b/TwoLiterStack/bin/.project
@@ -0,0 +1,17 @@
+
+
+ TwoLiterStack
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/TwoLiterStack/bin/.settings/org.eclipse.jdt.core.prefs b/TwoLiterStack/bin/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..71f736f
--- /dev/null
+++ b/TwoLiterStack/bin/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=12
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=12
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=12
diff --git a/TwoLiterStack/src/main/Main.java b/TwoLiterStack/src/main/Main.java
index b5e47e3..7ff6726 100644
--- a/TwoLiterStack/src/main/Main.java
+++ b/TwoLiterStack/src/main/Main.java
@@ -2,40 +2,53 @@
* Bill Nicholson
* nicholdw@ucmail.uc.edu
*/
-package main;
+
+//Changed package from main to src.main
+package src.main;
import java.text.DecimalFormat;
import java.util.Stack;
-public class Main {
+public class Main
+{
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
// ToDo Declare and instantiate a TwoLiterStack object
Stack twoLiterStack = new Stack();
// ToDo Add 100000 items to the stack by calling the add method in the TwoLiter class. Note that the method is static
- TwoLiter.add(twoLiterStack, 100000);
+ TwoLiter.add(twoLiterStack, 100000);
// ToDo print the number of items in the TwoLiterStack object
System.out.println("The stack has " + twoLiterStack.size() + " items in it.");
// ToDo Iterate over the stack and compute the total price of all the items. An enhanced for loop is good here.
double totalPrice = 0;
- for (TwoLiter twoLiter : twoLiterStack) {
+ for (TwoLiter twoLiter : twoLiterStack)
+ {
totalPrice += twoLiter.getPrice();
}
// ToDo Print the total price to exactly two decimal places.
// ToDo in the comments here, explain why this number changes each time you run the program.
+
+ /* The number changes each time the program is ran because a random number of items
+ * are being removed and then a random selection of flavors are being replaced so that the
+ * total number of is always at 100000, but the price depends on the flavor.
+ */
DecimalFormat df2 = new DecimalFormat("#.##");
System.out.println("Total Price is $" + df2.format(totalPrice));
// ToDo Compute the number of Dr. Pepper 2-liters in the stack
- int totalDrPepper = 0;
- for (TwoLiter twoLiter : twoLiterStack) {
+ int totalDrPepper = 2000;
+ for (TwoLiter twoLiter : twoLiterStack)
+ {
if (twoLiter.getFlavor().equals("Dr. Pepper")) {totalDrPepper++;}
}
System.out.println("Total Dr. Pepper = " + totalDrPepper);
+
+
}
}
diff --git a/TwoLiterStack/src/main/TwoLiter.java b/TwoLiterStack/src/main/TwoLiter.java
index 9a6d0d0..ded020d 100644
--- a/TwoLiterStack/src/main/TwoLiter.java
+++ b/TwoLiterStack/src/main/TwoLiter.java
@@ -1,8 +1,14 @@
/*
+ * Suzanne Matthey
+ * matthesr@uc.edu
+ * Assignment 10 Forked code from Github, attempted to fix errors
+ * and commit and push back to my Github. Then sent pull request
* Bill Nicholson
* nicholdw@ucmail.uc.edu
*/
-package main;
+
+//Changed package from main to src.main
+package src.main;
import java.util.Random;
import java.util.Stack;
@@ -12,9 +18,10 @@
* @author nicomp
*
*/
-public class TwoLiter {
+public class TwoLiter
+{
private static String[] flavors = {"Coke Classic", "Diet Coke", "Coke Zero", "New Coke", "Cherry Coke", "Caffeine Free Coke", "Dr. Pepper"};
- private static String[] UPCs = {"049000050103", "00049000050110", "00049000050141", "xxxxxxxxxxxxxx", " 00049000050165", "00049000006131", "00078000082463"};
+ private static String[] UPCs = {"049000050103", "00049000050110", "00049000050141", "xxxxxxxxxxxxxx", "00049000050165", "00049000006131", "00078000082463"};
private String UPC;
private String flavor;
private double price;
@@ -24,7 +31,8 @@ public class TwoLiter {
* @param flavor The flavor of the soda in the 2-liter
* @param price The selling price of the 2-liter
*/
- public TwoLiter(String UPC, String flavor, double price) {
+ public TwoLiter(String UPC, String flavor, double price)
+ {
setUPC(UPC);
setFlavor(flavor);
setPrice(price);
@@ -33,7 +41,8 @@ public TwoLiter(String UPC, String flavor, double price) {
* Copy Constructor
* @param twoLiter The object to be copied
*/
- public TwoLiter(TwoLiter twoLiter) {
+ public TwoLiter(TwoLiter twoLiter)
+ {
setUPC(twoLiter.getUPC());
setFlavor(twoLiter.getFlavor());
setPrice(twoLiter.getPrice());
@@ -43,10 +52,12 @@ public TwoLiter(TwoLiter twoLiter) {
* @param twoLiterStack The Stack
* @param count The number of TwoLiter objects to add
*/
- public static void add(Stack twoLiterStack, int count ) {
+ public static void add(Stack twoLiterStack, int count )
+ {
// Random r = new Random(42);
Random r = new Random();
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++)
+ {
twoLiterStack.add(new TwoLiter(UPCs[r.nextInt(UPCs.length - 1)],
flavors[r.nextInt(flavors.length - 1)],
1.00 + r.nextFloat()));
@@ -56,49 +67,56 @@ public static void add(Stack twoLiterStack, int count ) {
* Get the UPC (Universal Product Code) for the object
* @return The UPC
*/
- public String getUPC() {
+ public String getUPC()
+ {
return UPC;
}
/***
* Define the UPC for the object
* @param UPC The new UPC
*/
- public void setUPC(String UPC) {
+ public void setUPC(String UPC)
+ {
this.UPC = UPC;
}
/***
* Get the Flavor of the pop in the 2-liter
* @return The Flavor
*/
- public String getFlavor() {
+ public String getFlavor()
+ {
return flavor;
}
/***
* Define the flavor of the pop in the 2-liter
* @param flavor The new flavor
*/
- public void setFlavor(String flavor) {
+ public void setFlavor(String flavor)
+ {
this.flavor = flavor;
}
/***
* Get the price of the 2-liter
* @return The current price of the 2-liter
*/
- public double getPrice() {
+ public double getPrice()
+ {
return price;
}
/***
* Define the price of the 2-liter
* @param price The new price
*/
- public void setPrice(double price) {
+ public void setPrice(double price)
+ {
this.price = price;
}
/**
* Create a string representation of the object
* @return the string representation of the object
*/
- public String toString() {
+ public String toString()
+ {
return UPC + ", " + flavor + ", " + price;
}
}