SlideShare a Scribd company logo
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 .pdf
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
Construction Supervisor ResponsibilitiesCompletes construction pr.pdf
Construction Supervisor ResponsibilitiesCompletes construction pr.pdfConstruction Supervisor ResponsibilitiesCompletes construction pr.pdf
Construction Supervisor ResponsibilitiesCompletes construction pr.pdf
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
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
anandatalapatra
 
(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
anandatalapatra
 
#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
anandatalapatra
 

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

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 

Recently uploaded (20)

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 

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