Professional Documents
Culture Documents
Praneshajay - CST8116-Lab Exercise 8 File
Praneshajay - CST8116-Lab Exercise 8 File
VERSION 1
Understand the Problem
Peewee eggs: 15 oz.
In the program, I’ll need to create an array with 8 elements, one for each of the egg sizes, and two extra for too small
and too large, then use a loop with a sentinel value to ask for egg weights to be input until told to stop. An if statement
can be used to size the eggs: If weight < 15 then too small, if weight < 18 then Peewee, if weight < 21 then Small, if
weight < 24 then medium, if weight < 27 then Large, if weight <30 then extra-large, if weight < 33 then Jumbo, otherwise
too-large.
Algorithm
UML Class Diagrams
Pseudocode
declarations
String shouldContinue;
double weight;
int size;
do {
weight = console.nextDouble();
console.nextLine();
size = sizeEgg(weight);
eggCounts[size] = eggCounts[size] + 1;
shouldContinue = console.nextLine();
} while (shouldContinue.equalsIgnoreCase("Y"));
int index = 0;
index++;
}}
int size;
size = 1;
size = 2;
size = 3;
size = 4;
size = 5;
size = 6;
else {
size = 7;
return size;
public class
counter.enterEggs();
counter.printReport();
System.out.println("Program by Praneshajay");
Flowchart
Test Plan
Input Values Expected Output Actual Output Description
14 too small: 1 too small: 1 Testing boundary for each egg
size & Program works correctly.
Y peewee: 1 peewee: 1
15 small: 1 small: 1
Y medium: 1 medium: 1
18 large: 1 large: 1
Y extra-large: 1 extra-large: 1
21 jumbo: 1 jumbo: 1
Y too large: 1 too large: 1
24
Y
27
Y
30
Y
33
N
Screenshot of Version 1
VERSION 2
Understand the Problem
Peewee eggs: 15 oz.
In the program, The loop that creates the report was created as a while-loop but I need to convert the logic to use a
for-loop instead.
Pseudocode
public class Eggversion2 {
String shouldContinue;
double weight;
int size;
do {
weight = console.nextDouble();
console.nextLine();
size = sizeEgg(weight);
eggCounts[size] = eggCounts[size] + 1;
shouldContinue = console.nextLine();
} while (shouldContinue.equalsIgnoreCase("Y"));
int size;
size = TOO_SMALL;
size = PEEWEE;
size = SMALL;
size = MEDIUM;
size = LARGE;
size = EXTRA_LARGE;
}
else if (weight < 33) {
size = JUMBO;
else {
size = TOO_LARGE;
return size;
counter.enterEggs();
counter.printReport();
System.out.println("Program by Praneshajay");
Test Plan
Input Values Expected Output Actual Output Description
14 too small: 1 too small: 1 Testing boundary for each egg
size and program without any
Y peewee: 1 peewee: 1 bugs or errors.
15 small: 1 small: 1
Y medium: 1 medium: 1
18 large: 1 large: 1
Y extra-large: 1 extra-large: 1
21 jumbo: 1 jumbo: 1
Y too large: 1 too large: 1
24
Y
27
Y
30
Y
33
N
Screenshot of Version 2
VERSION 3
Understand the Problem:
The printReport() method already prints out labels, so I can modify it to print the asterisks as well.
A nested loop, that prints one * per iteration based on egg count will work, just before printing the labels.
Algorithm
Pseudocode
Declarations
String shouldContinue;
double weight;
int size;
do {
weight = console.nextDouble();
console.nextLine();
size = sizeEgg(weight);
eggCounts[size] = eggCounts[size] + 1;
shouldContinue = console.nextLine();
} while (shouldContinue.equalsIgnoreCase("Y"));
System.out.print("*");
}}
int size;
size = TOO_SMALL;
}
size = PEEWEE;
size = SMALL;
size = MEDIUM;
size = LARGE;
size = EXTRA_LARGE;
size = JUMBO;
else {
size = TOO_LARGE;
return size;
counter.enterEggs();
counter.printReport();
System.out.println("Program by Praneshajay");
Test Plan
Input Values Expected Output Actual Output Description
14 Testing bar chart outputs.
Y
14 The number of * correspond to
Y the number of eggs counted for
14 each size.
Y *** (too small: 3) *** (too small: 3)
15
Y
15
Y ** (peewee: 2) ** (peewee: 2)
21 (small: 0 ,no 18,19,20 (small: 0 ,no 18,19,20
Y have entered) have entered)
24 * (medium: 1) * (medium: 1)
Y
27 * (large: 1) * (large: 1)
Y
30 * (extra-large: 1) * (extra-large: 1)
Y
30
Y
30
Y
30
Y
33 **** (jumbo: 4) **** (jumbo: 4)
n
* (too large: 1) * (too large: 1)
Screenshot of Version 3