Question: This lab will require that you create both the domain and the driver class using the skeleton provided. Here are the specifications for each class:
This lab will require that you create both the domain and the driver class using the skeleton provided. Here are the specifications for each class:
JellyBean (domain) Class 1.) Define 3 attributes: String color, String flavor, boolean eatMe 2.) Create 1 constructor and pass it 2 parameters to initialize the color and flavor attributes. In the constructor, initialize the eatMe attribute to false. 3.) Create setters & getters for the 3 attributes, remembering that setters receive a value to move to the attribute, while getters return the attribute value. 4.) Create a toString() method that will return a String with the 3 attributes concatenated together: color, flavor and eatMe
JellyBeanTester Class - The purpose of this Tester class is to create 3 JellyBean objects from the user's input, and to count how many of these JellyBean objects have a flavor of orange. At the end, display the number of orange-flavored jellybean objects.
1.) At the beginning of the tester class, above all the methods, define the following 3 static global variables:
static JellyBean jb1; static JellyBean jb2; static JellyBean jb3;
By defining them outside of any methods, they become global variables that can be accessed from any method in the tester class.
2. In the main method, call the following 2 static methods: createJellyBeanBag(); processJellyBeanBag();
3.) In the createJellyBeanBag method:
a.) Define 2 local variables at the beginning of the method, called: String userInputJBColor, userInputJBFlavor;
b.) Ask the user to enter the color of his/her first jelly bean, and store it in userInputJBColor.
c.) Ask the user to enter the flavor of his/her first jelly bean, and store it in userInputJBFlavor.
d.) Instantiate a new JellyBean object, passing it the userInputJBColor and the userInputJBFlavor. Hint: jb1 = new JellyBean(userInputJBColor, userInputJBFlavor);
e.) Repeat steps 3b, 3c, & 3d to create a 2 more jelly bean objects. Store them in jb2 and jb3.
4.) In the processJellyBeanBag() method:
a.) Define a local variable that will be used to count the number of orange jelly beans: int orangeJellyBeanCounter = 0;
b.) Write an if-statement that will ask each of the jelly bean objects if their color is equal to "ORANGE." Since we are comparing Strings, use the equalsIgnoreCase method, like this:
if (jb1.getColor().equalsIgnoreCase("Orange")) ...
c.) When the color DOES equal "Orange", add 1 to the orangeJellyBeanCounter, and change the eatMe attribute's to true by passing true to the setEatMe(true) method.
d.) Repeat steps a.) and b.) to count the rest of the Jelly Bean objects that may have an orange color.
e.) Display the count of the number of jelly bean objects that are orange in color.
f.) Then, display the contents of the 3 jelly bean objects. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package jellybeantester; /** * * @author */ public class JellyBean { //These are the 3 instance variables of a JellyBean object: String flavor; String color; boolean eatMe; /** * The purpose of this constructor is to move the parameters passed to the constructor * into the instance variables of the JellyBean object The 2 parameters are: * @param aFlavor * @param aColor */ public JellyBean(String aFlavor, String aColor) { //Initialize each of the instance variables of the JellyBean object with the parameters passed to the constructor //Then, set eatMe attribute to false } public String getFlavor() { return flavor; } //Define the getters for color and eatMe: public void setFlavor(String aFlavor) { flavor = aFlavor; } //Define the setters for color and eatMe: /** * * @return a String representation of all the attributes in the JellyBean class */ public String toString() { //return all the attributes of the JellyBean object, all concatenated together } } /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package jellybeantester; import java.util.Scanner; /** * * @author */ public class JellyBeanTester { // These are the 3 global variables that will each hold a JellyBean object. These variables // can be accessed by any method in the tester class because they are global. static JellyBean jb1; static JellyBean jb2; static JellyBean jb3; /** * @param args the command line arguments */ public static void main(String[] args) { createJellyBeanBag(); processJellyBeanBag(); } /** * The createJellyBeanBag method will ask the user for input, and will * use that input to create 3 JellyBean objects. */ public static void createJellyBeanBag() { String userInputJBColor; String userInputJBFlavor; //Ask the user to enter the color of the first jelly bean object, and save their answer in userInputJBColor: //Ask the user to enter the flavor of the first jelly bean object, and save their answer in userInputJBFlavor: //Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor: jb1 = new JellyBean(userInputJBFlavor, userInputJBColor); //*** Repeat the above steps for JellyBean #2 //*** Repeat the above steps for JellyBean #3 } /** * The processJellyBeanBag() method will check how many JellyBean objects have the color of orange, * and will change each of the orange JellyBeans' eatMe attribute to true. The processJellyBeanBag() method will also * count how many JellyBeans are orange in color, and will display that count at the end of the method. * It will also display the content of each of the 3 JellyBean objects. */ public static void processJellyBeanBag() { int orangeJellyBeanCounter = 0; // Check if jb1.getColor().equalsIgnoreCase("orange")) // if it does, then do the following 2 actions: // add 1 to the orangeJellyBeanCounter. // Hint: orangeJellyBeanCounter ++; // use the eatMe attribute's setter method to change its value to true. // Hint: jb1.setEatMe(true); //Repeat the check for the jb2 object: //Repeat the check for the jb3 object: //Print out the total number of orange JellyBeans, and the non-orange JellyBeans: //Print out each of the 3 JellyBean objects: } } Need help completing this. using netbeans
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
