From f2e66c5c3cef492e8a1a54afc01abc01a63a4d3d Mon Sep 17 00:00:00 2001 From: Alicia Date: Tue, 5 Apr 2022 01:39:16 -0400 Subject: [PATCH 1/6] It was missing the JRE System Library so I added it, at least on my end. I also removed the - 1 from r.nextInt for both UPCs and flavors in the for loop in the add method. --- TwoLiterStack/src/main/Main.java | 41 -------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 TwoLiterStack/src/main/Main.java diff --git a/TwoLiterStack/src/main/Main.java b/TwoLiterStack/src/main/Main.java deleted file mode 100644 index b5e47e3..0000000 --- a/TwoLiterStack/src/main/Main.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Bill Nicholson - * nicholdw@ucmail.uc.edu - */ -package main; - -import java.text.DecimalFormat; -import java.util.Stack; - -public class Main { - - 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); - - // 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) { - 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; - for (TwoLiter twoLiter : twoLiterStack) { - if (twoLiter.getFlavor().equals("Dr. Pepper")) {totalDrPepper++;} - } - System.out.println("Total Dr. Pepper = " + totalDrPepper); - } -} From 37ee7f86b40317a4d8b211dab29585ce63389d30 Mon Sep 17 00:00:00 2001 From: Alicia Date: Tue, 5 Apr 2022 01:42:08 -0400 Subject: [PATCH 2/6] It was missing the JRE System Library so I added it, at least on my end. I then removed the - 1 from r.nextInt for both UPCs and flavors in the for loop in the add method. --- TwoLiterStack/.classpath | 6 ++++ TwoLiterStack/src/main/Main.java | 49 ++++++++++++++++++++++++++++ TwoLiterStack/src/main/TwoLiter.java | 12 +++++-- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 TwoLiterStack/.classpath create mode 100644 TwoLiterStack/src/main/Main.java diff --git a/TwoLiterStack/.classpath b/TwoLiterStack/.classpath new file mode 100644 index 0000000..d171cd4 --- /dev/null +++ b/TwoLiterStack/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TwoLiterStack/src/main/Main.java b/TwoLiterStack/src/main/Main.java new file mode 100644 index 0000000..d4a1376 --- /dev/null +++ b/TwoLiterStack/src/main/Main.java @@ -0,0 +1,49 @@ +/* + * 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 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); + + // 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) { + 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; + 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..631b32c 100644 --- a/TwoLiterStack/src/main/TwoLiter.java +++ b/TwoLiterStack/src/main/TwoLiter.java @@ -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; @@ -47,8 +55,8 @@ public static void add(Stack 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())); } } From 7e3c6414ae39e2373361e6ea9830db110c3cf018 Mon Sep 17 00:00:00 2001 From: Alicia Date: Tue, 5 Apr 2022 01:45:35 -0400 Subject: [PATCH 3/6] It was missing the JRE System Library so I added it, at least on my end. I then removed the - 1 from r.nextInt for both UPCs and flavors in the for loop in the add method. --- TwoLiterStack/src/main/Main.java | 1 - TwoLiterStack/src/main/TwoLiter.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/TwoLiterStack/src/main/Main.java b/TwoLiterStack/src/main/Main.java index d4a1376..07410dc 100644 --- a/TwoLiterStack/src/main/Main.java +++ b/TwoLiterStack/src/main/Main.java @@ -33,7 +33,6 @@ 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("#.##"); diff --git a/TwoLiterStack/src/main/TwoLiter.java b/TwoLiterStack/src/main/TwoLiter.java index 631b32c..fc50cb7 100644 --- a/TwoLiterStack/src/main/TwoLiter.java +++ b/TwoLiterStack/src/main/TwoLiter.java @@ -26,6 +26,7 @@ public class TwoLiter { private String UPC; private String flavor; private double price; + /** * Constructor * @param UPC The Universal Product Code that uniquely identifies this type of product From 8a6967adf4a61eb21e5f09928e6154d360b8a0b2 Mon Sep 17 00:00:00 2001 From: Alicia Date: Tue, 5 Apr 2022 01:48:24 -0400 Subject: [PATCH 4/6] It was missing the JRE System Library so I added it, at least on my end. I then removed the - 1 from r.nextInt for both UPCs and flavors in the for loop in the add method. --- TwoLiterStack/src/main/Main.java | 2 +- TwoLiterStack/src/main/TwoLiter.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TwoLiterStack/src/main/Main.java b/TwoLiterStack/src/main/Main.java index 07410dc..5fa84b5 100644 --- a/TwoLiterStack/src/main/Main.java +++ b/TwoLiterStack/src/main/Main.java @@ -25,7 +25,7 @@ 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; diff --git a/TwoLiterStack/src/main/TwoLiter.java b/TwoLiterStack/src/main/TwoLiter.java index fc50cb7..588ed3b 100644 --- a/TwoLiterStack/src/main/TwoLiter.java +++ b/TwoLiterStack/src/main/TwoLiter.java @@ -56,8 +56,8 @@ public static void add(Stack 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)], - flavors[r.nextInt(flavors.length)], + twoLiterStack.add(new TwoLiter(UPCs[r.nextInt(UPCs.length )], + flavors[r.nextInt(flavors.length )], 1.00 + r.nextFloat())); } } From 5f76f176192e5ecf816031717c69dc2816727a1c Mon Sep 17 00:00:00 2001 From: Alicia Date: Tue, 5 Apr 2022 01:52:14 -0400 Subject: [PATCH 5/6] It was missing the JRE System Library so I added it, at least on my end. I then removed the - 1 from r.nextInt for both UPCs and flavors in the for loop in the add method. --- TwoLiterStack/src/main/Main.java | 2 +- TwoLiterStack/src/main/TwoLiter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TwoLiterStack/src/main/Main.java b/TwoLiterStack/src/main/Main.java index 5fa84b5..1609c31 100644 --- a/TwoLiterStack/src/main/Main.java +++ b/TwoLiterStack/src/main/Main.java @@ -25,7 +25,7 @@ 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; diff --git a/TwoLiterStack/src/main/TwoLiter.java b/TwoLiterStack/src/main/TwoLiter.java index 588ed3b..c693b1e 100644 --- a/TwoLiterStack/src/main/TwoLiter.java +++ b/TwoLiterStack/src/main/TwoLiter.java @@ -9,7 +9,7 @@ * 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; From e5c9a39b2c456f5920448f49ea0d5524823b45c5 Mon Sep 17 00:00:00 2001 From: Alicia Date: Tue, 5 Apr 2022 22:14:03 -0400 Subject: [PATCH 6/6] It was missing the JRE System Library so I added it, at least on my end. I then removed the - 1 from r.nextInt for both UPCs and flavors in the for loop in the add method. --- TwoLiterStack/src/main/Main.java | 2 +- TwoLiterStack/src/main/TwoLiter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TwoLiterStack/src/main/Main.java b/TwoLiterStack/src/main/Main.java index 1609c31..fbfad72 100644 --- a/TwoLiterStack/src/main/Main.java +++ b/TwoLiterStack/src/main/Main.java @@ -15,7 +15,7 @@ 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 diff --git a/TwoLiterStack/src/main/TwoLiter.java b/TwoLiterStack/src/main/TwoLiter.java index c693b1e..2ee00ae 100644 --- a/TwoLiterStack/src/main/TwoLiter.java +++ b/TwoLiterStack/src/main/TwoLiter.java @@ -25,7 +25,7 @@ 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