Write an expression that evaluates to true if and only if the value of the integer variable x is equal to zero.
  • (x >= 5) ? x: -x
  • c !=' '
  • profits == losses
  • x == 0
Declare a variable isACustomer suitable for representing a true or false value .
  • numberOfMen >= numberOfWomen
  • boolean isACustomer
  • (x>='0' && x<='9')
  • (x>='a' && x<='z')
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 .
  • c == '\n'
  • (x>='A' && x<='Z')
  • !(x>='a' && x<='z') && !(x>='A' && x<='Z')
  • c == ' '
Given an int variable grossPay, write an expression that evaluates to true if and only if the value of grossPay is less than 10,000.
  • if (temperature > 98.6) fever = true;else fever = false;
  • if (grossPay <= 10,000)
  • workedOvertime == true
  • (x >= 0 && y<0)
Write an if/else statement that compares the variable age with 65, adds 1 to the variable seniorCitizens if age is greater than or equal to 65, and adds 1 to the variable nonSeniors otherwise.
  • if (age >= 65) seniorCitizens += 1; else nonSeniors += 1;
  • if ( temperature > 98.6 ) fever = true ;
  • if (workedOvertime == true) pay = pay * 1.5;
  • if(age < 18){ minors = minors + 1;}else if(age > 17 && age < 65){ adults = adults + 1;}else{ seniors = seniors + 1;}
3-5) (Find future dates) Write a program that prompts the user to enter an integer for today's day of the week (Sunday is 0, Monday is 1, ..., and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and dis- play the future day of the week.
  • import java.util.Scanner; public class FindFutureDates{ public static void main(String[]args) {Scanner input = new Scanner(System.in);System.out.print("Enter today's day:");int today = input.nextInt();System.out.print("Enter the number of days elapsed since today:");int elapsedDays = input.nextInt();int futureDay = (today + elapsedDays)%7;System.out.print("Today is ");switch(today) { case 0: System.out.print("Sunday"); break; case 1: System.out.print("Monday"); break; case 2: System.out.print("Tueday"); break; case 3: System.out.print("Wednesay"); break; case 4: System.out.print("Thursday"); break; case 5: System.out.print("Friday"); break; case 6: System.out.print("Saturday"); break; default: System.out.print(" an invalid starting day. Today's day must be 0-6."); } System.out.print(" and the future day is "); switch(futureDay) { case 0: System.out.println("Sunday"); break; case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesay"); break; case 4: System.out.println("Thursday"); break; case 5: System.out.println("Friday"); break; case 6: System.out.println("Saturday"); break; default: System.out.println("Unknown day"); } }}
  • if (soldYesterday > soldToday) salesTrend = -1; else salesTrend = 1;
  • callsReceived = stdin.nextInt(); operatorsOnCall = stdin.nextInt(); if (operatorsOnCall == 0) System.out.println("INVALID"); else System.out.println(callsReceived/operatorsOnCall);
  • !isEmpty && numberOfCredits > 2
Write an expression that evaluates to true if and only if value of the boolean variable isAMember is false .
  • isAMember == false
  • workedOvertime == true
  • index > lastIndex
  • profits == losses
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.
  • (x>='A' && x<='Z')
  • if (numberOfSides == 4)isQuadrilateral = true;elseisQuadrilateral = false;
  • (x>=48 && x<=55)
  • workedOvertime= hoursWorked > 40;
Clunker Motors Inc. is recalling all vehicles from model years 2001-Given a variable modelYear write a statement that prints the message "RECALL" to standard output if the value of modelYear falls within that range.
  • if (modelYear > 2006 || modelYear < 2001) System.out.println("NO RECALL");
  • norecall=!((modelYear>=1995 && modelYear <=1998) || (modelYear>=2004 && modelYear<=2006));
  • if (modelYear >= 2001 && modelYear <= 2006) System.out.println("RECALL");
  • if ((modelYear >= 1995 && modelYear <= 1998) || (modelYear >=2004 && modelYear<=2006))System.out.println("RECALL");
Write an expression that evaluates to true if the integer variable x contains an even value , and false if it contains an odd value .
  • (x >= 0 && y<0)
  • profits == losses
  • x>y
  • x % 2 == 0
Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults if age is 18 through 64 and adds 1 to the variable seniors if age is 65 or older.
  • if(gpa > 3.5){ deansList = deansList + 1; System.out.println(studentName);}
  • if (speed < 0) reverseDrivers += 1; else if (speed < 1) parkedDrivers += 1;else if (speed < 40) slowDrivers += 1;else if (speed <= 65) safeDrivers += 1; else speeders += 1;
  • if (age >= 65) seniorCitizens += 1; else nonSeniors += 1;
  • if(age < 18){ minors = minors + 1;}else if(age > 17 && age < 65){ adults = adults + 1;}else{ seniors = seniors + 1;}
Clunker Motors Inc. is recalling all vehicles from model years 2001-Given a variable modelYear write a statement that prints the message "NO RECALL" to standard output if the value of modelYear DOES NOT fall within that range.
  • if (modelYear > 2006 || modelYear < 2001) System.out.println("NO RECALL");
  • if (modelYear >= 2001 && modelYear <= 2006) System.out.println("RECALL");
  • if (isIsosceles == true) { isoCount += 1; triangleCount += 1; polygonCount += 1; }
  • norecall=!(modelYear >= 2001 && modelYear <= 2006);
Write an expression that evaluates to true if the value of the integer variable numberOfPrizes is divisible (with no remainder) by the integer variable numberOfParticipants. Assume that numberOfParticipants is not zero.
  • workedOvertime == true
  • if (soldYesterday > soldToday) salesTrend = -1; else salesTrend = 1;
  • numberOfPrizes % numberOfParticipants == 0
  • numberOfMen >= numberOfWomen
Write an expression that evaluates to true if the value x is greater than or equal to y.
  • x>y
  • x >= y
  • x == 0
  • index > lastIndex
Given the char variable c, write an expression that is true if and only if the value of c is not the space character .
  • c !=' '
  • c == '\n'
  • x % 2 == 0
  • (x >= 0 && y<0)
Assume that x is a char variable has been declared and already given a value . Write an expression whose value is true if and only if x is NOT a letter.
  • !(x>='a' && x<='z') && !(x>='A' && x<='Z')
  • (x>='A' && x<='Z')
  • (x>='0' && x<='9')
  • c == '\t'
Given two variables , isEmpty of type boolean , indicating whether a class roster is empty or not, and numberOfCredits of type int , containing the number of credits for a class , write an expression that evaluates to true if the class roster is empty or the class is exactly three credits.
  • isEmpty || numberOfCredits == 3
  • temperature>90 && humidity<10 == true
  • !isEmpty && numberOfCredits > 2
  • !(c == ' ' || c== '\n' || c == '\t')
Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer division with truncation will do).HOWEVER: if any value read in is not valid input, just print the message "INVALID".ASSUME the availability of a variable , stdin, that references a Scanner object associated with standard input.
  • freeBooks = 0;if (isPremiumCustomer == true){ if (nbooksPurchased >= 5) freeBooks = 1; if (nbooksPurchased >= 8) freeBooks = 2;}else if (isPremiumCustomer == false){ if (nbooksPurchased >= 7) freeBooks = 1; if (nbooksPurchased >= 12) freeBooks = 2;}
  • if (grossPay <= 10,000)
  • callsReceived = stdin.nextInt(); operatorsOnCall = stdin.nextInt(); if (operatorsOnCall == 0) System.out.println("INVALID"); else System.out.println(callsReceived/operatorsOnCall);
  • if (speed < 0) reverseDrivers += 1; else if (speed < 1) parkedDrivers += 1;else if (speed < 40) slowDrivers += 1;else if (speed <= 65) safeDrivers += 1; else speeders += 1;
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 .
  • (x>='0' && x<='9')
  • c == '\t'
  • (x>=48 && x<=55)
  • (x>='A' && x<='Z')
Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2, the message "player1 wins" is printed to standard out. When score2 exceeds score1, the message "player2 wins" is printed to standard out. In each case, the variables player1Wins,, player1Losses, player2Wins, and player2Losses,, are incremented when appropriate.Finally, in the event of a tie, the message "tie" is printed and the variable tieCount is incremented .
  • if (speed < 0) reverseDrivers += 1; else if (speed < 1) parkedDrivers += 1;else if (speed < 40) slowDrivers += 1;else if (speed <= 65) safeDrivers += 1; else speeders += 1;
  • if ((modelYear >= 1995 && modelYear <= 1998) || (modelYear >=2004 && modelYear<=2006))System.out.println("RECALL");
  • if (score1 > score2){ System.out.print("player1 wins"); player1Wins += 1; player2Losses += 1;}else if (score2 > score1){ System.out.print("player2 wins"); player1Losses += 1; player2Wins += 1;}else { System.out.print("tie"); tieCount += 1;}
  • if (pH < 7){ neutral = 0; base = 0; acid = 1;}else if (pH > 7){ neutral = 0; base = 1; acid = 0;}else { neutral = 1; base = 0; acid = 0;}
Write an expression using the conditional operator (? :) that compares the value of the variable x to 5 and results in: x if x is greater than or equal to 5 -x if x is less than 5
  • isAMember == false
  • (x >= 5) ? x: -x
  • profits == losses
  • x == 0
Working overtime is defined as having worked more than 40 hours during the week. Given the variable hoursWorked, write an expression that evaluates to true if the employee worked overtime.
  • (x >= 5) ? x: -x
  • onOffSwitch = !onOffSwitch;
  • hoursWorked > 40
  • (x>=48 && x<=55)
Assume that x is a char variable has been declared and already given a value . Write an expression whose value is true if and only if x is an octal (Base 8) digit (0-7).
  • (x>='A' && x<='Z')
  • (x >= 0 && y<0)
  • (x>=48 && x<=55)
  • (x>='0' && x<='9')
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.
  • if(gpa > 3.5){ deansList = deansList + 1; System.out.println(studentName);}
  • if (modelYear > 2006 || modelYear < 2001) System.out.println("NO RECALL");
  • if (isIsosceles == true) { isoCount += 1; triangleCount += 1; polygonCount += 1; }
  • if (numberOfSides == 4)isQuadrilateral = true;elseisQuadrilateral = false;
Assume that the variables gpa, deansList and studentName, have been declared and initialized . Write a statement that adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.
  • if (isIsosceles == true) { isoCount += 1; triangleCount += 1; polygonCount += 1; }
  • !(x>='a' && x<='z') && !(x>='A' && x<='Z')
  • if(gpa > 3.5){ deansList = deansList + 1; System.out.println(studentName);}
  • if (age >= 65) seniorCitizens += 1; else nonSeniors += 1;
Assume that credits is an int variable whose value is 0 or positive. Write an expression whose value is "freshman" or "sophomore" or "junior" or "senior" based on the value of credits. In particular: if the value of credits is less than 30 the expression 's value is "freshman"; 30-59 would be a "sophomore", 60-89 would be "junior" and 90 or more would be a "senior".
  • if (isIsosceles == true) { isoCount += 1; triangleCount += 1; polygonCount += 1; }
  • (credits < 30) ? "freshman" : (credits >= 30 && credits < 60) ?"sophomore" : (credits >= 60 && credits < 90) ? "junior" : "senior"
  • !(c == ' ' || c== '\n' || c == '\t')
  • if (numberOfSides == 4)isQuadrilateral = true;elseisQuadrilateral = false;
Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books.Write a statement that assigns freeBooks the appropriate value based on the values of the boolean variable isPremiumCustomer and the int variable nbooksPurchased.
  • if (speed < 0) reverseDrivers += 1; else if (speed < 1) parkedDrivers += 1;else if (speed < 40) slowDrivers += 1;else if (speed <= 65) safeDrivers += 1; else speeders += 1;
  • freeBooks = 0;if (isPremiumCustomer == true){ if (nbooksPurchased >= 5) freeBooks = 1; if (nbooksPurchased >= 8) freeBooks = 2;}else if (isPremiumCustomer == false){ if (nbooksPurchased >= 7) freeBooks = 1; if (nbooksPurchased >= 12) freeBooks = 2;}
  • (credits < 30) ? "freshman" : (credits >= 30 && credits < 60) ?"sophomore" : (credits >= 60 && credits < 90) ? "junior" : "senior"
  • (month==1)?"jan":(month==2)?"feb": (month==3)?"mar": (month==4)?"apr": (month==5)?"may":(month==6)?"jun": (month==7)?"jul":(month==8)?"aug":(month==9)?"sep": (month==10)?"oct": (month==11)?"nov": (month==12)?"dec":null
Write a conditional that assigns 10,000 to the variable bonus if the value of the variable goodsSold is greater than 500,000.
  • if (temperature > 98.6) fever = true;else fever = false;
  • if (goodsSold > 500000)bonus = 10000;
  • if (age >= 65) seniorCitizens += 1; else nonSeniors += 1;
  • if (grossPay <= 10,000)
NOTE: in mathematics, division by zero is undefined. So, in Java, division by zero is always an error.Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer division with truncation will do).HOWEVER: if any value read in is not valid input, just print the message "INVALID".ASSUME the availability of a variable , stdin, that references a Scanner object associated with standard input.
  • callsReceived = stdin.nextInt(); operatorsOnCall = stdin.nextInt(); if (operatorsOnCall == 0) System.out.println("INVALID"); else System.out.println(callsReceived/operatorsOnCall);
  • freeBooks = 0;if (isPremiumCustomer == true){ if (nbooksPurchased >= 5) freeBooks = 1; if (nbooksPurchased >= 8) freeBooks = 2;}else if (isPremiumCustomer == false){ if (nbooksPurchased >= 7) freeBooks = 1; if (nbooksPurchased >= 12) freeBooks = 2;}
  • if (score1 > score2){ System.out.print("player1 wins"); player1Wins += 1; player2Losses += 1;}else if (score2 > score1){ System.out.print("player2 wins"); player1Losses += 1; player2Wins += 1;}else { System.out.print("tie"); tieCount += 1;}
  • if (pH < 7){ neutral = 0; base = 0; acid = 1;}else if (pH > 7){ neutral = 0; base = 1; acid = 0;}else { neutral = 1; base = 0; acid = 0;}
Four int variables , x1, x2, y1, and y2, have been declared and been given values . Write an expression whose value is the difference between the larger of x1 and x2 and the smaller of y1 and y2.
  • !isEmpty && numberOfCredits > 2
  • (x < y ? y : x)
  • (x >= 5) ? x: -x
  • (x1 < x2 ? x2 : x1) - (y1 < y2 ? y1 : y2)
Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-A boolean variable named recalled has been declared . Given a variable modelYear write a statement that assigns true to norecall if the value of modelYear does NOT fall within the two recall ranges and assigns false otherwise.Do not use an if statement in this exercise!
  • recalled = (modelYear >= 1995 && modelYear <= 1998) || (modelYear >= 2004 && modelYear <= 2006);
  • if (isIsosceles == true) { isoCount += 1; triangleCount += 1; polygonCount += 1; }
  • norecall=!(modelYear >= 2001 && modelYear <= 2006);
  • norecall=!((modelYear>=1995 && modelYear <=1998) || (modelYear>=2004 && modelYear<=2006));
Assume that x is a char variable has been declared and already given a value . Write an expression whose value is true if and only if x is a decimal digit (0-9).
  • (x>='0' && x<='9')
  • !(x>='a' && x<='z') && !(x>='A' && x<='Z')
  • (x>='A' && x<='Z')
  • 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 .
  • (credits < 30) ? "freshman" : (credits >= 30 && credits < 60) ?"sophomore" : (credits >= 60 && credits < 90) ? "junior" : "senior"
  • if (isIsosceles == true) { isoCount += 1; triangleCount += 1; polygonCount += 1; }
  • if ((modelYear >= 1995 && modelYear <= 1998) || (modelYear >=2004 && modelYear<=2006))System.out.println("RECALL");
  • if (numberOfSides == 4)isQuadrilateral = true;elseisQuadrilateral = false;
Clunker Motors Inc. is recalling all vehicles from model years 2001-A boolean variable named norecall has been declared . Given a variable modelYear write a statement that assigns true to norecall if the value of modelYear does NOT within the recall range and assigns false otherwise.Do not use an if statement in this exercise!
  • recalled = (modelYear >= 1995 && modelYear <= 1998) || (modelYear >= 2004 && modelYear <= 2006);
  • workedOvertime= hoursWorked > 40;
  • norecall=!(modelYear >= 2001 && modelYear <= 2006);
  • if ((modelYear >= 1995 && modelYear <= 1998) || (modelYear >=2004 && modelYear<=2006))System.out.println("RECALL");
Given the variables numberOfMen and numberOfWomen, write an expression that evaluates to true if the number of men is greater than or equal to the number of women.
  • numberOfMen >= numberOfWomen
  • isEmpty || numberOfCredits == 3
  • temperature>90 && humidity<10 == true
  • !isEmpty && numberOfCredits > 2
Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the int variables neutral, base, and acid: 0,0,1 if pH is less than 7 0,1,0 if pH is greater than 7 1,0,0 if pH is equal to 7
  • if (age >= 65) seniorCitizens += 1; else nonSeniors += 1;
  • if (speed < 0) reverseDrivers += 1; else if (speed < 1) parkedDrivers += 1;else if (speed < 40) slowDrivers += 1;else if (speed <= 65) safeDrivers += 1; else speeders += 1;
  • if (pH < 7){ neutral = 0; base = 0; acid = 1;}else if (pH > 7){ neutral = 0; base = 1; acid = 0;}else { neutral = 1; base = 0; acid = 0;}
  • if (soldYesterday > soldToday) salesTrend = -1; else salesTrend = 1;
Write an expression that evaluates to true if the value of index is greater than the value of lastIndex.
  • index > lastIndex
  • x % 2 == 0
  • x >= y
  • profits == losses
Given two variables , isEmpty of type boolean , indicating whether a class roster is empty or not, and numberOfCredits of type int , containing the number of credits for a class , write an expression that evaluates to true if the class roster is not empty and the class is more than two credits.
  • !isEmpty && (numberOfCredits == 1 || numberOfCredits == 3)
  • isEmpty || numberOfCredits == 3
  • !isEmpty && numberOfCredits > 2
  • numberOfMen >= numberOfWomen
Write an expression that evaluates to true if and only if the variables profits and losses are exactly equal .
  • index > lastIndex
  • (x >= 5) ? x: -x
  • profits == losses
  • x % 2 == 0
Write a statement that adds 1 to the variable reverseDrivers if the variable speed is less than 0,adds 1 to the variable parkedDrivers if the variable speed is less than 1,adds 1 to the variable slowDrivers if the variable speed is less than 40,adds 1 to the variable safeDrivers if the variable speed is less than or equal to 65, and otherwise adds 1 to the variable speeders.
  • if (pH < 7){ neutral = 0; base = 0; acid = 1;}else if (pH > 7){ neutral = 0; base = 1; acid = 0;}else { neutral = 1; base = 0; acid = 0;}
  • if (score1 > score2){ System.out.print("player1 wins"); player1Wins += 1; player2Losses += 1;}else if (score2 > score1){ System.out.print("player2 wins"); player1Losses += 1; player2Wins += 1;}else { System.out.print("tie"); tieCount += 1;}
  • if(age < 18){ minors = minors + 1;}else if(age > 17 && age < 65){ adults = adults + 1;}else{ seniors = seniors + 1;}
  • if (speed < 0) reverseDrivers += 1; else if (speed < 1) parkedDrivers += 1;else if (speed < 40) slowDrivers += 1;else if (speed <= 65) safeDrivers += 1; else speeders += 1;
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 space character .
  • c !=' '
  • c == '\t'
  • c == '\n'
  • c == ' '
Write a conditional that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90.
  • if (temperature > 98.6) fever = true;else fever = false;
  • if(age < 18){ minors = minors + 1;}else if(age > 17 && age < 65){ adults = adults + 1;}else{ seniors = seniors + 1;}
  • if(outsideTemperature > 90) shelfLife = shelfLife - 4;
  • numberOfPrizes % numberOfParticipants == 0
Write an expression using the conditional operator (? :) that compares the values of the variables x and y. The result (that is the value ) of this expression should be the value of the larger of the two variables .
  • (x < y ? y : x)
  • (x >= 5) ? x: -x
  • index > lastIndex
  • widthOfBox % widthOfBook !=0
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 NOT what is called a whitespace character (that is a space or a tab or a newline-- none of which result in ink being printed on paper).
  • (x>='a' && x<='z')
  • !(c == ' ' || c== '\n' || c == '\t')
  • c == ' '
  • workedOvertime= hoursWorked > 40;
Write an expression that evaluates to true if and only if the value of the boolean variable workedOvertime is true .
  • workedOvertime == true
  • isAMember == false
  • numberOfPrizes % numberOfParticipants == 0
  • widthOfBox % widthOfBook !=0
Clunker Motors Inc. is recalling all vehicles from model years 2001-A boolean variable named recalled has been declared . Given a variable modelYear write a statement that assigns true to recalled if the value of modelYear falls within the recall range and assigns false otherwise.Do not use an if statement in this exercise!
  • recalled=(modelYear>=2001 && modelYear<=2006);
  • !(c == ' ' || c== '\n' || c == '\t')
  • workedOvertime= hoursWorked > 40;
  • if ((modelYear >= 1995 && modelYear <= 1998) || (modelYear >=2004 && modelYear<=2006))System.out.println("RECALL");
Write an expression that evaluates to true if and only if the integer x is greater than the integer y.
  • (x >= 5) ? x: -x
  • x>y
  • widthOfBox % widthOfBook !=0
  • index > lastIndex
Given that the variables x and y have already been declared and assigned values , write an expression that evaluates to true if x is non-negative and y is negative.
  • x % 2 == 0
  • (x >= 0 && y<0)
  • (x>='a' && x<='z')
  • (x>=0 || y<0)
0:0:1



Answered

Not Answered

Not Visited
Correct : 0
Incorrect : 0