SlideShare a Scribd company logo
1 of 13
Download to read offline
JellyBean.java
package jellybeantester;
public class JellyBean
{
//These are the 3 instance variables of a JellyBean object:
private String flavor;
private String color;
private 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
this.flavor=aFlavor;
this.color=aColor;
}
//Setters and getters.
public String getFlavor()
{
return flavor;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isEatMe() {
return eatMe;
}
public void setEatMe(boolean eatMe) {
this.eatMe = eatMe;
}
public void setFlavor(String aFlavor)
{
flavor = aFlavor;
}
/**
*
* @return a String representation of all the attributes in the JellyBean class
*/
public String toString()
{
return " Flavour = "+getFlavor()+" Color = "+getColor()+" Eat Me = "+isEatMe()+" ";
}
}
______________________________________________
JellyBeanTester.java
package jellybeantester;
import java.util.Scanner;
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;
static Scanner sc=new Scanner(System.in);
/**
* @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:
System.out.print("Enter the Color of the First Jelly Bean :");
userInputJBColor=sc.next();
//Ask the user to enter the flavor of the first jelly bean object, and save their answer in
userInputJBFlavor:
System.out.print("Enter the Flavour of First the Jelly Bean :");
userInputJBFlavor=sc.next();
//Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor:
jb1 = new JellyBean(userInputJBFlavor, userInputJBColor);
//Ask the user to enter the color of the second jelly bean object, and save their answer in
userInputJBColor:
System.out.print(" Enter the Color of the second Jelly Bean :");
userInputJBColor=sc.next();
//Ask the user to enter the flavor of the second jelly bean object, and save their answer in
userInputJBFlavor:
System.out.print("Enter the Flavour of Second the Jelly Bean :");
userInputJBFlavor=sc.next();
//Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor:
jb2 = new JellyBean(userInputJBFlavor, userInputJBColor);
//Ask the user to enter the color of the third jelly bean object, and save their answer in
userInputJBColor:
System.out.print(" Enter the Color of the third Jelly Bean :");
userInputJBColor=sc.next();
//Ask the user to enter the flavor of the third jelly bean object, and save their answer in
userInputJBFlavor:
System.out.print("Enter the Flavour of third the Jelly Bean :");
userInputJBFlavor=sc.next();
//Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor:
jb3 = new JellyBean(userInputJBFlavor, userInputJBColor);
}
/**
* 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;
int otherJellyBeanCounter = 0;
String uColor = jb1.getColor().toUpperCase();
switch (uColor)
{ case "ORANGE":
orangeJellyBeanCounter++;
jb1.setEatMe(true);
break;
default :
otherJellyBeanCounter++;
}
String uColor1 = jb2.getColor().toUpperCase();
switch (uColor1)
{ case "ORANGE":
orangeJellyBeanCounter++;
jb2.setEatMe(true);
break;
default :
otherJellyBeanCounter++;
}
String uColor2 = jb3.getColor().toUpperCase();
switch (uColor2)
{ case "ORANGE":
orangeJellyBeanCounter++;
jb3.setEatMe(true);
break;
default :
otherJellyBeanCounter++;
}
//Print out the total number of orange JellyBeans, and the non-orange JellyBeans:
System.out.println(" No of Orange Color Jelly Beans :"+orangeJellyBeanCounter);
//Print out each of the 3 JellyBean objects:
System.out.println("First Jelly Bean Object Information :"+jb1.toString());
System.out.println("Second Jelly Bean Object Information :"+jb2.toString());
System.out.println("Third Jelly Bean Object Information :"+jb3.toString());
}
}
_________________________________________________
Output:
Enter the Color of the First Jelly Bean :Orange
Enter the Flavour of First the Jelly Bean :Chocolate
Enter the Color of the second Jelly Bean :Green
Enter the Flavour of Second the Jelly Bean :Mango
Enter the Color of the third Jelly Bean :Orange
Enter the Flavour of third the Jelly Bean :Orange
No of Orange Color Jelly Beans :2
First Jelly Bean Object Information :
Flavour = Chocolate
Color = Orange
Eat Me = true
Second Jelly Bean Object Information :
Flavour = Mango
Color = Green
Eat Me = false
Third Jelly Bean Object Information :
Flavour = Orange
Color = Orange
Eat Me = true
_________________________________________Thank You
Solution
JellyBean.java
package jellybeantester;
public class JellyBean
{
//These are the 3 instance variables of a JellyBean object:
private String flavor;
private String color;
private 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
this.flavor=aFlavor;
this.color=aColor;
}
//Setters and getters.
public String getFlavor()
{
return flavor;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isEatMe() {
return eatMe;
}
public void setEatMe(boolean eatMe) {
this.eatMe = eatMe;
}
public void setFlavor(String aFlavor)
{
flavor = aFlavor;
}
/**
*
* @return a String representation of all the attributes in the JellyBean class
*/
public String toString()
{
return " Flavour = "+getFlavor()+" Color = "+getColor()+" Eat Me = "+isEatMe()+" ";
}
}
______________________________________________
JellyBeanTester.java
package jellybeantester;
import java.util.Scanner;
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;
static Scanner sc=new Scanner(System.in);
/**
* @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:
System.out.print("Enter the Color of the First Jelly Bean :");
userInputJBColor=sc.next();
//Ask the user to enter the flavor of the first jelly bean object, and save their answer in
userInputJBFlavor:
System.out.print("Enter the Flavour of First the Jelly Bean :");
userInputJBFlavor=sc.next();
//Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor:
jb1 = new JellyBean(userInputJBFlavor, userInputJBColor);
//Ask the user to enter the color of the second jelly bean object, and save their answer in
userInputJBColor:
System.out.print(" Enter the Color of the second Jelly Bean :");
userInputJBColor=sc.next();
//Ask the user to enter the flavor of the second jelly bean object, and save their answer in
userInputJBFlavor:
System.out.print("Enter the Flavour of Second the Jelly Bean :");
userInputJBFlavor=sc.next();
//Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor:
jb2 = new JellyBean(userInputJBFlavor, userInputJBColor);
//Ask the user to enter the color of the third jelly bean object, and save their answer in
userInputJBColor:
System.out.print(" Enter the Color of the third Jelly Bean :");
userInputJBColor=sc.next();
//Ask the user to enter the flavor of the third jelly bean object, and save their answer in
userInputJBFlavor:
System.out.print("Enter the Flavour of third the Jelly Bean :");
userInputJBFlavor=sc.next();
//Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor:
jb3 = new JellyBean(userInputJBFlavor, userInputJBColor);
}
/**
* 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;
int otherJellyBeanCounter = 0;
String uColor = jb1.getColor().toUpperCase();
switch (uColor)
{ case "ORANGE":
orangeJellyBeanCounter++;
jb1.setEatMe(true);
break;
default :
otherJellyBeanCounter++;
}
String uColor1 = jb2.getColor().toUpperCase();
switch (uColor1)
{ case "ORANGE":
orangeJellyBeanCounter++;
jb2.setEatMe(true);
break;
default :
otherJellyBeanCounter++;
}
String uColor2 = jb3.getColor().toUpperCase();
switch (uColor2)
{ case "ORANGE":
orangeJellyBeanCounter++;
jb3.setEatMe(true);
break;
default :
otherJellyBeanCounter++;
}
//Print out the total number of orange JellyBeans, and the non-orange JellyBeans:
System.out.println(" No of Orange Color Jelly Beans :"+orangeJellyBeanCounter);
//Print out each of the 3 JellyBean objects:
System.out.println("First Jelly Bean Object Information :"+jb1.toString());
System.out.println("Second Jelly Bean Object Information :"+jb2.toString());
System.out.println("Third Jelly Bean Object Information :"+jb3.toString());
}
}
_________________________________________________
Output:
Enter the Color of the First Jelly Bean :Orange
Enter the Flavour of First the Jelly Bean :Chocolate
Enter the Color of the second Jelly Bean :Green
Enter the Flavour of Second the Jelly Bean :Mango
Enter the Color of the third Jelly Bean :Orange
Enter the Flavour of third the Jelly Bean :Orange
No of Orange Color Jelly Beans :2
First Jelly Bean Object Information :
Flavour = Chocolate
Color = Orange
Eat Me = true
Second Jelly Bean Object Information :
Flavour = Mango
Color = Green
Eat Me = false
Third Jelly Bean Object Information :
Flavour = Orange
Color = Orange
Eat Me = true
_________________________________________Thank You

More Related Content

More from anandatalapatra

Solution It is for the auditors and other people involved in the .pdf
Solution It is for the auditors and other people involved in the .pdfSolution It is for the auditors and other people involved in the .pdf
Solution It is for the auditors and other people involved in the .pdfanandatalapatra
 
Ques-1 Answer C. neutrophilsReasonInnate immune system is wit.pdf
Ques-1 Answer C. neutrophilsReasonInnate immune system is wit.pdfQues-1 Answer C. neutrophilsReasonInnate immune system is wit.pdf
Ques-1 Answer C. neutrophilsReasonInnate immune system is wit.pdfanandatalapatra
 
relation between concentration and cell potential is given as Ecel.pdf
relation between concentration and cell potential is given as Ecel.pdfrelation between concentration and cell potential is given as Ecel.pdf
relation between concentration and cell potential is given as Ecel.pdfanandatalapatra
 
Part I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdf
Part I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdfPart I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdf
Part I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdfanandatalapatra
 
PrintTest.java import java.util.Scanner;public class PrintTest.pdf
PrintTest.java import java.util.Scanner;public class PrintTest.pdfPrintTest.java import java.util.Scanner;public class PrintTest.pdf
PrintTest.java import java.util.Scanner;public class PrintTest.pdfanandatalapatra
 
Existence of hydrogen bonding increases boiling p.pdf
                     Existence of hydrogen bonding increases boiling p.pdf                     Existence of hydrogen bonding increases boiling p.pdf
Existence of hydrogen bonding increases boiling p.pdfanandatalapatra
 
In present DNA microarray technology, the different test-samples are.pdf
In present DNA microarray technology, the different test-samples are.pdfIn present DNA microarray technology, the different test-samples are.pdf
In present DNA microarray technology, the different test-samples are.pdfanandatalapatra
 
In computer graphics vectors perform the operations are...1.Rotati.pdf
In computer graphics vectors perform the operations are...1.Rotati.pdfIn computer graphics vectors perform the operations are...1.Rotati.pdf
In computer graphics vectors perform the operations are...1.Rotati.pdfanandatalapatra
 
copper iodide are incompatible in oxidising media.pdf
                     copper iodide are incompatible in oxidising media.pdf                     copper iodide are incompatible in oxidising media.pdf
copper iodide are incompatible in oxidising media.pdfanandatalapatra
 
Dirac theoremFor a simple network with n 3 vertices, if each ver.pdf
Dirac theoremFor a simple network with n  3 vertices, if each ver.pdfDirac theoremFor a simple network with n  3 vertices, if each ver.pdf
Dirac theoremFor a simple network with n 3 vertices, if each ver.pdfanandatalapatra
 
Construction Supervisor ResponsibilitiesCompletes construction pr.pdf
Construction Supervisor ResponsibilitiesCompletes construction pr.pdfConstruction Supervisor ResponsibilitiesCompletes construction pr.pdf
Construction Supervisor ResponsibilitiesCompletes construction pr.pdfanandatalapatra
 
Border Gateway Protocol (BGP) is the protocol whi.pdf
                     Border Gateway Protocol (BGP) is the protocol whi.pdf                     Border Gateway Protocol (BGP) is the protocol whi.pdf
Border Gateway Protocol (BGP) is the protocol whi.pdfanandatalapatra
 
Answer-The hierarchical aspect of the Ip addressesnetwork -host .pdf
Answer-The hierarchical aspect of the Ip addressesnetwork -host .pdfAnswer-The hierarchical aspect of the Ip addressesnetwork -host .pdf
Answer-The hierarchical aspect of the Ip addressesnetwork -host .pdfanandatalapatra
 
Aedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdf
Aedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdfAedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdf
Aedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdfanandatalapatra
 
Ans.)C) Lower right-hand corner (Ruderal)In climates where streams.pdf
Ans.)C) Lower right-hand corner (Ruderal)In climates where streams.pdfAns.)C) Lower right-hand corner (Ruderal)In climates where streams.pdf
Ans.)C) Lower right-hand corner (Ruderal)In climates where streams.pdfanandatalapatra
 
All chordates possess the same four structures in the early embryo. .pdf
All chordates possess the same four structures in the early embryo. .pdfAll chordates possess the same four structures in the early embryo. .pdf
All chordates possess the same four structures in the early embryo. .pdfanandatalapatra
 
a) False (because it is not always the case).Many electronegative .pdf
a) False (because it is not always the case).Many electronegative .pdfa) False (because it is not always the case).Many electronegative .pdf
a) False (because it is not always the case).Many electronegative .pdfanandatalapatra
 
1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdf
1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdf1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdf
1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdfanandatalapatra
 
(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdf
(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdf(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdf
(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdfanandatalapatra
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdfanandatalapatra
 

More from anandatalapatra (20)

Solution It is for the auditors and other people involved in the .pdf
Solution It is for the auditors and other people involved in the .pdfSolution It is for the auditors and other people involved in the .pdf
Solution It is for the auditors and other people involved in the .pdf
 
Ques-1 Answer C. neutrophilsReasonInnate immune system is wit.pdf
Ques-1 Answer C. neutrophilsReasonInnate immune system is wit.pdfQues-1 Answer C. neutrophilsReasonInnate immune system is wit.pdf
Ques-1 Answer C. neutrophilsReasonInnate immune system is wit.pdf
 
relation between concentration and cell potential is given as Ecel.pdf
relation between concentration and cell potential is given as Ecel.pdfrelation between concentration and cell potential is given as Ecel.pdf
relation between concentration and cell potential is given as Ecel.pdf
 
Part I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdf
Part I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdfPart I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdf
Part I Identifying Your Customer’s Needs and Goals Chapter 1 A.pdf
 
PrintTest.java import java.util.Scanner;public class PrintTest.pdf
PrintTest.java import java.util.Scanner;public class PrintTest.pdfPrintTest.java import java.util.Scanner;public class PrintTest.pdf
PrintTest.java import java.util.Scanner;public class PrintTest.pdf
 
Existence of hydrogen bonding increases boiling p.pdf
                     Existence of hydrogen bonding increases boiling p.pdf                     Existence of hydrogen bonding increases boiling p.pdf
Existence of hydrogen bonding increases boiling p.pdf
 
In present DNA microarray technology, the different test-samples are.pdf
In present DNA microarray technology, the different test-samples are.pdfIn present DNA microarray technology, the different test-samples are.pdf
In present DNA microarray technology, the different test-samples are.pdf
 
In computer graphics vectors perform the operations are...1.Rotati.pdf
In computer graphics vectors perform the operations are...1.Rotati.pdfIn computer graphics vectors perform the operations are...1.Rotati.pdf
In computer graphics vectors perform the operations are...1.Rotati.pdf
 
copper iodide are incompatible in oxidising media.pdf
                     copper iodide are incompatible in oxidising media.pdf                     copper iodide are incompatible in oxidising media.pdf
copper iodide are incompatible in oxidising media.pdf
 
Dirac theoremFor a simple network with n 3 vertices, if each ver.pdf
Dirac theoremFor a simple network with n  3 vertices, if each ver.pdfDirac theoremFor a simple network with n  3 vertices, if each ver.pdf
Dirac theoremFor a simple network with n 3 vertices, if each ver.pdf
 
Construction Supervisor ResponsibilitiesCompletes construction pr.pdf
Construction Supervisor ResponsibilitiesCompletes construction pr.pdfConstruction Supervisor ResponsibilitiesCompletes construction pr.pdf
Construction Supervisor ResponsibilitiesCompletes construction pr.pdf
 
Border Gateway Protocol (BGP) is the protocol whi.pdf
                     Border Gateway Protocol (BGP) is the protocol whi.pdf                     Border Gateway Protocol (BGP) is the protocol whi.pdf
Border Gateway Protocol (BGP) is the protocol whi.pdf
 
Answer-The hierarchical aspect of the Ip addressesnetwork -host .pdf
Answer-The hierarchical aspect of the Ip addressesnetwork -host .pdfAnswer-The hierarchical aspect of the Ip addressesnetwork -host .pdf
Answer-The hierarchical aspect of the Ip addressesnetwork -host .pdf
 
Aedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdf
Aedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdfAedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdf
Aedes albopictus, Psorophora ciliate, floodwater mosquitoes, Aedes a.pdf
 
Ans.)C) Lower right-hand corner (Ruderal)In climates where streams.pdf
Ans.)C) Lower right-hand corner (Ruderal)In climates where streams.pdfAns.)C) Lower right-hand corner (Ruderal)In climates where streams.pdf
Ans.)C) Lower right-hand corner (Ruderal)In climates where streams.pdf
 
All chordates possess the same four structures in the early embryo. .pdf
All chordates possess the same four structures in the early embryo. .pdfAll chordates possess the same four structures in the early embryo. .pdf
All chordates possess the same four structures in the early embryo. .pdf
 
a) False (because it is not always the case).Many electronegative .pdf
a) False (because it is not always the case).Many electronegative .pdfa) False (because it is not always the case).Many electronegative .pdf
a) False (because it is not always the case).Many electronegative .pdf
 
1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdf
1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdf1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdf
1.The Open Systems Interconnect (OSI) model has seven layers.The mod.pdf
 
(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdf
(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdf(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdf
(1) ACQUISITION EXPENSES Acquirers may incur millions in direct an.pdf
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 

Recently uploaded

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 

Recently uploaded (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 

JellyBean.javapackage jellybeantester;public class JellyBean {.pdf

  • 1. JellyBean.java package jellybeantester; public class JellyBean { //These are the 3 instance variables of a JellyBean object: private String flavor; private String color; private 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 this.flavor=aFlavor; this.color=aColor; } //Setters and getters. public String getFlavor() { return flavor; } public String getColor() { return color; }
  • 2. public void setColor(String color) { this.color = color; } public boolean isEatMe() { return eatMe; } public void setEatMe(boolean eatMe) { this.eatMe = eatMe; } public void setFlavor(String aFlavor) { flavor = aFlavor; } /** * * @return a String representation of all the attributes in the JellyBean class */ public String toString() { return " Flavour = "+getFlavor()+" Color = "+getColor()+" Eat Me = "+isEatMe()+" "; } } ______________________________________________ JellyBeanTester.java package jellybeantester; import java.util.Scanner; public class JellyBeanTester {
  • 3. // 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; static Scanner sc=new Scanner(System.in); /** * @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: System.out.print("Enter the Color of the First Jelly Bean :"); userInputJBColor=sc.next(); //Ask the user to enter the flavor of the first jelly bean object, and save their answer in userInputJBFlavor: System.out.print("Enter the Flavour of First the Jelly Bean :"); userInputJBFlavor=sc.next();
  • 4. //Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor: jb1 = new JellyBean(userInputJBFlavor, userInputJBColor); //Ask the user to enter the color of the second jelly bean object, and save their answer in userInputJBColor: System.out.print(" Enter the Color of the second Jelly Bean :"); userInputJBColor=sc.next(); //Ask the user to enter the flavor of the second jelly bean object, and save their answer in userInputJBFlavor: System.out.print("Enter the Flavour of Second the Jelly Bean :"); userInputJBFlavor=sc.next(); //Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor: jb2 = new JellyBean(userInputJBFlavor, userInputJBColor); //Ask the user to enter the color of the third jelly bean object, and save their answer in userInputJBColor: System.out.print(" Enter the Color of the third Jelly Bean :"); userInputJBColor=sc.next(); //Ask the user to enter the flavor of the third jelly bean object, and save their answer in userInputJBFlavor: System.out.print("Enter the Flavour of third the Jelly Bean :"); userInputJBFlavor=sc.next(); //Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor: jb3 = new JellyBean(userInputJBFlavor, userInputJBColor); } /** * The processJellyBeanBag() method will check how many JellyBean objects have the color of
  • 5. 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; int otherJellyBeanCounter = 0; String uColor = jb1.getColor().toUpperCase(); switch (uColor) { case "ORANGE": orangeJellyBeanCounter++; jb1.setEatMe(true); break; default : otherJellyBeanCounter++; } String uColor1 = jb2.getColor().toUpperCase(); switch (uColor1) { case "ORANGE": orangeJellyBeanCounter++; jb2.setEatMe(true); break; default : otherJellyBeanCounter++; } String uColor2 = jb3.getColor().toUpperCase(); switch (uColor2)
  • 6. { case "ORANGE": orangeJellyBeanCounter++; jb3.setEatMe(true); break; default : otherJellyBeanCounter++; } //Print out the total number of orange JellyBeans, and the non-orange JellyBeans: System.out.println(" No of Orange Color Jelly Beans :"+orangeJellyBeanCounter); //Print out each of the 3 JellyBean objects: System.out.println("First Jelly Bean Object Information :"+jb1.toString()); System.out.println("Second Jelly Bean Object Information :"+jb2.toString()); System.out.println("Third Jelly Bean Object Information :"+jb3.toString()); } } _________________________________________________ Output: Enter the Color of the First Jelly Bean :Orange Enter the Flavour of First the Jelly Bean :Chocolate Enter the Color of the second Jelly Bean :Green Enter the Flavour of Second the Jelly Bean :Mango Enter the Color of the third Jelly Bean :Orange Enter the Flavour of third the Jelly Bean :Orange No of Orange Color Jelly Beans :2 First Jelly Bean Object Information : Flavour = Chocolate Color = Orange
  • 7. Eat Me = true Second Jelly Bean Object Information : Flavour = Mango Color = Green Eat Me = false Third Jelly Bean Object Information : Flavour = Orange Color = Orange Eat Me = true _________________________________________Thank You Solution JellyBean.java package jellybeantester; public class JellyBean { //These are the 3 instance variables of a JellyBean object: private String flavor; private String color; private 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 this.flavor=aFlavor; this.color=aColor;
  • 8. } //Setters and getters. public String getFlavor() { return flavor; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public boolean isEatMe() { return eatMe; } public void setEatMe(boolean eatMe) { this.eatMe = eatMe; } public void setFlavor(String aFlavor) { flavor = aFlavor; } /** * * @return a String representation of all the attributes in the JellyBean class */ public String toString()
  • 9. { return " Flavour = "+getFlavor()+" Color = "+getColor()+" Eat Me = "+isEatMe()+" "; } } ______________________________________________ JellyBeanTester.java package jellybeantester; import java.util.Scanner; 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; static Scanner sc=new Scanner(System.in); /** * @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;
  • 10. String userInputJBFlavor; //Ask the user to enter the color of the first jelly bean object, and save their answer in userInputJBColor: System.out.print("Enter the Color of the First Jelly Bean :"); userInputJBColor=sc.next(); //Ask the user to enter the flavor of the first jelly bean object, and save their answer in userInputJBFlavor: System.out.print("Enter the Flavour of First the Jelly Bean :"); userInputJBFlavor=sc.next(); //Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor: jb1 = new JellyBean(userInputJBFlavor, userInputJBColor); //Ask the user to enter the color of the second jelly bean object, and save their answer in userInputJBColor: System.out.print(" Enter the Color of the second Jelly Bean :"); userInputJBColor=sc.next(); //Ask the user to enter the flavor of the second jelly bean object, and save their answer in userInputJBFlavor: System.out.print("Enter the Flavour of Second the Jelly Bean :"); userInputJBFlavor=sc.next(); //Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor: jb2 = new JellyBean(userInputJBFlavor, userInputJBColor); //Ask the user to enter the color of the third jelly bean object, and save their answer in userInputJBColor: System.out.print(" Enter the Color of the third Jelly Bean :"); userInputJBColor=sc.next(); //Ask the user to enter the flavor of the third jelly bean object, and save their answer in
  • 11. userInputJBFlavor: System.out.print("Enter the Flavour of third the Jelly Bean :"); userInputJBFlavor=sc.next(); //Instantiate a JellyBean object using the userInputJBFlavor and userInputJBColor: jb3 = new JellyBean(userInputJBFlavor, userInputJBColor); } /** * 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; int otherJellyBeanCounter = 0; String uColor = jb1.getColor().toUpperCase(); switch (uColor) { case "ORANGE": orangeJellyBeanCounter++; jb1.setEatMe(true); break; default : otherJellyBeanCounter++; } String uColor1 = jb2.getColor().toUpperCase();
  • 12. switch (uColor1) { case "ORANGE": orangeJellyBeanCounter++; jb2.setEatMe(true); break; default : otherJellyBeanCounter++; } String uColor2 = jb3.getColor().toUpperCase(); switch (uColor2) { case "ORANGE": orangeJellyBeanCounter++; jb3.setEatMe(true); break; default : otherJellyBeanCounter++; } //Print out the total number of orange JellyBeans, and the non-orange JellyBeans: System.out.println(" No of Orange Color Jelly Beans :"+orangeJellyBeanCounter); //Print out each of the 3 JellyBean objects: System.out.println("First Jelly Bean Object Information :"+jb1.toString()); System.out.println("Second Jelly Bean Object Information :"+jb2.toString()); System.out.println("Third Jelly Bean Object Information :"+jb3.toString()); } }
  • 13. _________________________________________________ Output: Enter the Color of the First Jelly Bean :Orange Enter the Flavour of First the Jelly Bean :Chocolate Enter the Color of the second Jelly Bean :Green Enter the Flavour of Second the Jelly Bean :Mango Enter the Color of the third Jelly Bean :Orange Enter the Flavour of third the Jelly Bean :Orange No of Orange Color Jelly Beans :2 First Jelly Bean Object Information : Flavour = Chocolate Color = Orange Eat Me = true Second Jelly Bean Object Information : Flavour = Mango Color = Green Eat Me = false Third Jelly Bean Object Information : Flavour = Orange Color = Orange Eat Me = true _________________________________________Thank You