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
6 changes: 6 additions & 0 deletions TwoLiterStack/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
7 changes: 6 additions & 1 deletion TwoLiterStack/src/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.text.DecimalFormat;
import java.util.Stack;

import main.TwoLiter;

public class Main {

public static void main(String[] args) {
Expand All @@ -28,13 +30,16 @@ public static void main(String[] args) {

// 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 because there is a random number of soda's being put in
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) {
if (twoLiter.getFlavor().equals("Dr. Pepper")) {totalDrPepper++;}
if (twoLiter.getFlavor().equals("Cherry Coke")) {
totalDrPepper++;
}
}
System.out.println("Total Dr. Pepper = " + totalDrPepper);
}
Expand Down
4 changes: 2 additions & 2 deletions TwoLiterStack/src/main/TwoLiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static void add(Stack<TwoLiter> twoLiterStack, int count ) {
// Random r = new Random(42);
Random r = 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)],
twoLiterStack.add(new TwoLiter(UPCs[r.nextInt(UPCs.length)],
flavors[r.nextInt(flavors.length)],
1.00 + r.nextFloat()));
}
}
Expand Down