Skip to content
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
10 changes: 10 additions & 0 deletions TwoLiterStack/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
10 changes: 10 additions & 0 deletions TwoLiterStack/bin/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion TwoLiterStack/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/main/
/src/
17 changes: 17 additions & 0 deletions TwoLiterStack/bin/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TwoLiterStack</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions TwoLiterStack/bin/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
20 changes: 16 additions & 4 deletions TwoLiterStack/src/main/Main.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
/*
* Bill Nicholson
* nicholdw@ucmail.uc.edu
* Professor Bill Nicholsons code, Edited by Joshua Ciulla..
* ciullaja@mail.uc.edu
* Assignment #: 10
* IT 2045C Spring Semester
* This is Professor Bill Nicholsons code, I am just editing the code. I will be fixing the Dr. Pepper problem
*/
package main;

package src.main;

import java.text.DecimalFormat;
import java.util.Stack;

public class Main {

public static void main(String[] args) {


Stack<String> myStack = new Stack<String>(); // Adding a paramater to this class and Joshua added this

// ToDo Declare and instantiate a TwoLiterStack object
Stack<TwoLiter> twoLiterStack = new Stack<TwoLiter>();

Expand All @@ -25,17 +33,21 @@ public static void main(String[] args) {
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.
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;
myStack.add("Dr. Pepper"); // Joshua Added this
String myPop = myStack.pop(); // Joshua added this

for (TwoLiter twoLiter : twoLiterStack) {
if (twoLiter.getFlavor().equals("Dr. Pepper")) {totalDrPepper++;}
}

System.out.println("Total Dr. Pepper = " + totalDrPepper);
}
}
30 changes: 19 additions & 11 deletions TwoLiterStack/src/main/TwoLiter.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
/*
* Bill Nicholson
* nicholdw@ucmail.uc.edu
* Professor Bill Nicholsons code, Edited by Joshua Ciulla.
* ciullaja@mail.uc.edu
* Assignment #: 10
* IT 2045C Spring Semester
* This is Professor Bill Nicholsons code, I am just editing the code. I will be fixing the Dr. Pepper problem.
*/
package main;

package src.main;

import java.util.Random;
import java.util.Stack;

//
/**
* Model a 2-liter of soda in a grocery store
* @author nicomp
*
*/
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[] flavors = {"Coke Classic", "Diet Coke", "Coke Zero", "Dr. Pepper", "Cherry Coke", "Caffeine Free Coke", "New Coke"};
private static String[] UPCs = {"049000050103", "00049000050110", "00049000050141", "00078000082463", " 00049000050165", "00049000006131", "0"};
// I switched the New Coke that did not have any value to the the back because Dr. Pepper was cut out. So I changed the position of new coke with Dr.Pepper for it to work.
private String UPC;
private String flavor;
private double price;
Expand Down Expand Up @@ -44,12 +49,13 @@ public TwoLiter(TwoLiter twoLiter) {
* @param count The number of TwoLiter objects to add
*/
public static void add(Stack<TwoLiter> twoLiterStack, int count ) {
// Random r = new Random(42);
Random r = new Random();
Random r = new Random(42);
Random r1 = new Random();
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()));
twoLiterStack.add(new TwoLiter(UPCs[r1.nextInt(UPCs.length - 1)],
flavors[r1.nextInt(flavors.length - 1)],
1.00 + r1.nextFloat()));

}
}
/**
Expand Down Expand Up @@ -102,3 +108,5 @@ public String toString() {
return UPC + ", " + flavor + ", " + price;
}
}

// I edited the code and I switched "New Coke" with no value to Dr.Pepper that has value and now I get output for Dr.Pepper to be added to the stack. I also added a parameter to the class as well to ensure that Dr.Pepper is added to the stack.