QUESTIONS WITH CORRECT ANSWERS.
8. Cookie Calories
A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are
10 servings in the bag and that a serving equals 300 calories. Write a program that lets the
user enter the number of cookies he or she actually ate and then reports the number of total
calories consumed. - CORRECT ANSWER✅✅package javacookies;
import java.util.Scanner;
public class JavaCookies {
public static void main(String[] args) {
int cookieCount;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter number of cookies eaten:");
cookieCount = keyboard.nextInt();
int servingSize = 40/10;
double caloriesPerCookie = 300/servingSize;
double totalCalories = cookieCount * caloriesPerCookie;
System.out.println("Your calorie intake was: " + totalCalories
+ " calories");
}
, }
A comment starts with what characters? - CORRECT ANSWER✅✅//
Assume that a boolean variable isQuadrilateral has been declared, and that another variable,
numberOfSides has been declared and initialized. Write a statement that assigns the value true if
numberOfSides is exactly 4 and false otherwise. - CORRECT ANSWER✅✅if(numberOfSides==4)
isQuadrilateral = true;
else
isQuadrilateral = false;
Assume that a boolean variable workedOvertime has been declared, and that another variable,
hoursWorked has been declared and initialized. Write a statement that assigns the value true to
workedOvertime if hoursWorked is greater than 40 and false otherwise. - CORRECT
ANSWER✅✅if(hoursWorked > 40)
workedOvertime = true;
else
workedOvertime = false;
Assume that c is a char variable has been declared and already given a value. Write an expression whose
value is true if and only if c is a newline character. - CORRECT ANSWER✅✅c == '\n'
Assume that c is a char variable has been declared and already given a value. Write an expression whose
value is true if and only if c is a tab character. - CORRECT ANSWER✅✅c == '\t'
Assume that isIsosceles is a boolean variable, and that the variables isoCount,triangleCount, and
polygonCount have all been declared and initialized. Write a statement that adds 1 to each of these
count variables (isoCount,triangleCount, andpolygonCount) if isIsosceles is true. - CORRECT
ANSWER✅✅if(isIsosceles == true)
{
isoCount +=1;
triangleCount +=1;