Homework 05
Peanut Butter and Jelly Sandwich
Due 03/20/2026 by 11:55pm
Objective:
Practice object-oriented
principles by making two Peanut Butter and Jelly Sandwiches. The program must
create two sandwiches based on user input. The sandwich information for both
must then print out their details and determine if the two sandwiches are
equal.
Requirements:
- Functionality. (80pts)
- No Syntax Errors.
(80pts*)
- *Code that cannot be
compiled due to syntax errors is nonfunctional code and will receive no
points for this entire section.
- Write a class called Bread with the following: (20pts)
- Instance Variables
- Name: The name brand of
the bread. This value should not be null, and its default value is
“none”.
- Calories: The number of
calories per slice assumed to be between 50 and 250 inclusively, and
its default value is 50.
- Type: The kind of
bread. This can either be “Honey Wheat”, “White”, “Whole Grain”, or
“Whole Wheat”, and its default value is “Whole Grain”.
- Methods
- Accessors and Mutators
for the instance variables
- Make sure in the
mutators check for valid values named in the “Instance Variables”
Section.
- If the value that is
being set is not valid, then set the instance variable to its default
value.
- Equals: This method
takes in another instance of Bread and only returns true if all of the
instance variables match. For name and type case should be ignored.
- ToString: This method
returns a string with all of the instance variable values concatenated
together.
- All above must apply for
full credit.
- Write a class called PeanutButter with the following:
(20pts)
- Instance Variables
- Name: The name brand of
peanut butter. This value should not be null, and its default value is
“none”.
- Calories: The number of
calories per serving assumed to be between 100 and 300 inclusively, and
its default value is 100.
- IsCrunchy: True if the
peanut butter is crunchy and false otherwise, and its default value is
false.
- Methods
- Accessors and Mutators
for the instance variables
- Make sure in the
mutators check for valid values named in the “Instance Variables”
Section.
- If the value that is
being set is not valid, then set the instance variable to its default
value.
- Equals: This method
takes in another instance of Peanut Butter and only returns true if all
of the instance variables match. For name case should be ignored.
- ToString: This method
returns a string with all of the instance variable values concatenated
together.
- All above must apply for
full credit.
- Write a class called Jelly with the following: (20pts)
- Instance Variables
- Name: The brand name of
the Jelly. This value should not be null, and its default value is
“none”.
- Calories: The number of
calories per serving assumed to be between 50 and 200 inclusively, and
its default value is 50.
- FruitType: The type of
fruit the jelly is made from and can only be “Apple”, “Blackberry”,
“Grape”, “Blueberry”, or “Tomato”. Its default value is “Grape”.
- Methods
- Accessors and Mutators
for the instance variables
- Make sure in the
mutators check for valid values named in the “Instance Variables”
Section.
- If the value that is
being set is not valid, then set the instance variable to its default
value.
- Equals: This method
takes in another instance of Jelly and only returns true if all of the
instance variables match. For name and fruit type case should be
ignored.
- ToString: This method
returns a string with all of the instance variable values concatenated
together.
- All above must apply for
full credit.
- Write a class called PBJSandwich with the following:
(10pts)
- Instance Variables
- TopSlice: An instance
of type Bread representing the top slice of bread. This type refers to
the one that was described above, and its default value is the default
Bread.
- PeanutButter: An
instance of type PeanutButter representing the peanut butter. This type
refers to the one that was described above, and its default value is
the default PeanutButter.
- Jelly: An instance of type
Jelly representing the jelly. This type refers to the one that was
described above, and its default value is the default Jelly.
- BottomSlice: Another
instance of type Bread representing the bottom slice of bread. This
type refers to the one that was described above, and its default value
is the default Bread.
- Methods
- Accessors and Mutators
for the instance variables
- Make sure in the
mutators check for valid values named in the Instance Variable
Section.
- Each of the instance
variables must not be null.
- Equals: This method
takes in another instance of PBJSandwich and only returns true if all
of the instance variables match by calling their Equals methods.
- ToString: This method
returns a string with all of the instance variable values.
- All above must apply for
full credit.
- Write a class called PBJFrontEnd with the following:
(10pts)
- Methods
- Main Method
- The program must create
two instances of type PBJSandwich.
- User must be able to enter
all the properties of the sandwiches which include all the properties
of the top slice of bread, bottom slice of bread, jelly, and peanut
butter.
- The program must then print
out the values of the two sandwiches which include all the properties
of the top slice of bread, bottom slice of bread, jelly, and peanut
butter.
- The program must then determine
if they are the same sandwich.
- The program must then
ask the user if they would like to restart or quit.
- All above must apply for
full credit.
- Coding Style. (10pts)
- Code functionality
organized within multiple methods other than the main method, and methods
organized within multiple classes where appropriate. (5pts)
- Readable Code. (5pts)
- Meaningful identifiers
for data and methods.
- Proper indentation that
clearly identifies statements within the body of a class, a method, a
branching statement, a loop statement, etc.
- All the above must apply
for full credit.
- Comments. (10pts)
- Your name in every file.
(5pts)
- At least 5 meaningful
comments in addition to your name. These must describe the function of
the code it is near. (5pts)
Example Dialog:
*The following
Example Dialog demonstrates the interactions between a user and ONE possible
implementation of the required software’s front-end / user interface. The
software’s front-end / user interface may be implemented in MANY different
ways and will receive full credit as long as it meets the most minimal of
the above requirements. While you may use the example dialog as a guide, it is
strongly encouraged to create the front-end / user interface in your own way. *
|
Key
|
|
Unhighlighted Text
|
Program’s Output
|
|
Highlighted
Text
|
User’s
Input
|
-----------------------------------
Welcome to the PBJ Sandwich Maker!
-----------------------------------
-----Sandwich 1-----
Top Slice of Bread Information
Enter name of the bread
Wonder
Bread
Enter the number of calories
80
Enter the type of bread. Must be
"Honey Wheat", "White", "Whole Grain", or
"Whole Wheat"
whole
wheat
Peanut Butter Information
Enter name of the peanut butter
JIF
Enter the number of calories
190
Is it crunchy? Enter
"true", or "false"
false
Jelly Information
Enter name of the jelly
Smuckers
Enter the number of calories
150
Enter the type of bread. Must be
"Apple", "Blueberry", "Grape",
"Strawberry", or "Tomato"
Apple
Bottom Slice of Bread Information
Enter name of the bread
Wonder
Bread
Enter the number of calories
120
Enter the type of bread. Must be
"Honey Wheat", "White", "Whole Grain", or
"Whole Wheat"
honey
Wheat
-----Sandwich 2-----
Top Slice of Bread Information
Enter name of the bread
Pepperidge
Farm
Enter the number of calories
100
Enter the type of bread. Must be
"Honey Wheat", "White", "Whole Grain", or
"Whole Wheat"
Whole
grain
Peanut Butter Information
Enter name of the peanut butter
Peter
Pan
Enter the number of calories
180
Is it crunchy? Enter
"true", or "false"
true
Jelly Information
Enter name of the jelly
Welch's
Enter the number of calories
150
Enter the type of bread. Must be
"Apple", "Blueberry", "Grape",
"Strawberry", or "Tomato"
Grape
Bottom Slice of Bread Information
Enter name of the bread
Lender's
Enter the number of calories
150
Enter the type of bread. Must be
"Honey Wheat", "White", "Whole Grain", or
"Whole Wheat"
Whole
Wheat
-----Sandwich 1-----
PBJ Sandwich
Top Slice:
Bread
Name: Wonder Bread
Calories: 80
Type: whole wheat
Peanut Butter:
Peanut Butter
Name: JIF
Calories: 190
Is Crunchy: true
Jelly:
Jelly
Name: Smuckers
Calories: 100
Fruit Type: Apple
Bottom Slice:
Bread
Name: Wonder Bread
Calories: 120
Type: honey Wheat
-----Sandwich 2-----
PBJ Sandwich
Top Slice:
Bread
Name: Pepperidge Farm
Calories: 100
Type: Whole grain
Peanut Butter:
Peanut Butter
Name: Peter Pan
Calories: 180
Is Crunchy: true
Jelly:
Jelly
Name: Welch's
Calories: 100
Fruit Type: Grape
Bottom Slice:
Bread
Name: Lender's
Calories: 150
Type: Whole Wheat
Are they the same sandwich? false
Example Dialog 2:
-----------------------------------
Welcome to the
PBJ Sandwich Maker!
-----------------------------------
-----Sandwich
1-----
Top Slice of
Bread Information
Enter name of
the bread
Wonder
Enter the
number of calories
100
Enter the type
of bread. Must be "Honey Wheat", "White", "Whole
Grain", or "Whole Wheat"
White
Peanut Butter
Information
Enter name of
the peanut butter
JIF
Enter the
number of calories
150
Is it crunchy?
Enter "true", or "false"
false
Jelly
Information
Enter name of
the jelly
Welchs
Enter the
number of calories
150
Enter the type
of bread. Must be "Apple", "Blueberry", "Grape",
"Strawberry", or "Tomato"
Grape
Bottom Slice
of Bread Information
Enter name of
the bread
Wonder
Enter the
number of calories
100
Enter the type
of bread. Must be "Honey Wheat", "White", "Whole
Grain", or "Whole Wheat"
White
-----Sandwich
2-----
Top Slice of
Bread Information
Enter name of
the bread
Wonder
Enter the
number of calories
100
Enter the type
of bread. Must be "Honey Wheat", "White", "Whole
Grain", or "Whole Wheat"
white
Peanut Butter
Information
Enter name of
the peanut butter
JIF
Enter the
number of calories
150
Is it crunchy?
Enter "true", or "false"
false
Jelly
Information
Enter name of
the jelly
Welchs
Enter the
number of calories
150
Enter the type
of bread. Must be "Apple", "Blueberry", "Grape",
"Strawberry", or "Tomato"
grape
Bottom Slice
of Bread Information
Enter name of
the bread
wonder
Enter the
number of calories
100
Enter the type
of bread. Must be "Honey Wheat", "White", "Whole
Grain", or "Whole Wheat"
white
-----Sandwich
1-----
PBJ Sandwich
Top Slice:
Bread
Name: Wonder
Calories: 100
Type: White
Peanut Butter:
Peanut Butter
Name: JIF
Calories: 150
Is Crunchy:
true
Jelly:
Jelly
Name: Welchs
Calories: 100
Fruit Type:
Grape
Bottom Slice:
Bread
Name: Wonder
Calories: 100
Type: White
-----Sandwich
2-----
PBJ Sandwich
Top Slice:
Bread
Name: Wonder
Calories: 100
Type: white
Peanut Butter:
Peanut Butter
Name: JIF
Calories: 150
Is Crunchy:
true
Jelly:
Jelly
Name: Welchs
Calories: 100
Fruit Type:
grape
Bottom Slice:
Bread
Name: wonder
Calories: 100
Type: white
Are they the
same sandwich? true
Finally:
- Upload the source code file
or files(.JAVA File Extension) to Homework05
- To Blackboard
- Following these instructions.
- If there are problems,
then let the instructor know as soon as possible.