Question: Celebrities & Chocolates
When celebrities get together for a party, they like to have chocolates.
A celebrity party is successful when the number of chocolates is between 20 and 40, inclusive.
Unless it is the weekend, in which case there is no upper bound on the number of chocolates.
You have to write a method Met that prints true if the party is successful and false if the party fails.
Write a method Met that takes 2 parameters: an integer and a boolean value.
The integer has the number of chocolates
the boolean is true if it’s the weekend and false if it’s not the weekend.
Met has to print true or false to tell us if the party is successful or not with the given values.
Only write the method - assume that the Main class & main method have been defined.
Use the System.out.println() statement for printing.
Example Input: 30 false
Output: true
Example Input: 50 false
Output: false
Example Input: 70 true
Output: true
bhan61:
can anyone tell me the answer
Answers
Answered by
22
public static void met(int chocolate, boolean weekend ){
if(weekend){
if(chocolate>=20){
System.out.println("true");
}
else{
System.out.println("false");
}
}
else{
if(chocolate>=20 && chocolate<=40){
System.out.println("true");
}
else{
System.out.println("false");
}
}
}
if(weekend){
if(chocolate>=20){
System.out.println("true");
}
else{
System.out.println("false");
}
}
else{
if(chocolate>=20 && chocolate<=40){
System.out.println("true");
}
else{
System.out.println("false");
}
}
}
Similar questions