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>
13 changes: 10 additions & 3 deletions TwoLiterStack/src/main/Main.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
/*
* Bill Nicholson
* nicholdw@ucmail.uc.edu
*
* Name Alicia J Davoyan
* Email: davoyaaj@mail.uc.edu
* Assignment #: Assignment 10
* Course/Term: IT2045C Spring 2022
* Description: This is our 10th assignment and we use our debugging skillz to fix the program and figure out why there is no Dr. Pepper and fix it.
* Anything else:
*/

package main;

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

public class Main {
public class Main {

public static void main(String[] args) {
// ToDo Declare and instantiate a TwoLiterStack object
Expand All @@ -17,15 +25,14 @@ public static void main(String[] args) {
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.");
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) {
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("#.##");
Expand Down
15 changes: 12 additions & 3 deletions TwoLiterStack/src/main/TwoLiter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/*
* Bill Nicholson
* nicholdw@ucmail.uc.edu
*
* Name Alicia J Davoyan
* Email: davoyaaj@mail.uc.edu
* Assignment #: Assignment 10
* Course/Term: IT2045C Spring 2022
* Description: This is our 10th assignment and we use our debugging skillz to fix the program and figure out why there is no Dr. Pepper and fix it.
* Anything else:
*/

package main;

import java.util.Random;
Expand All @@ -17,7 +25,8 @@ public class TwoLiter {
private static String[] UPCs = {"049000050103", "00049000050110", "00049000050141", "xxxxxxxxxxxxxx", " 00049000050165", "00049000006131", "00078000082463"};
private String UPC;
private String flavor;
private double price;
private double price;

/**
* Constructor
* @param UPC The Universal Product Code that uniquely identifies this type of product
Expand Down Expand Up @@ -47,8 +56,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