• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/76

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

76 Cards in this Set

  • Front
  • Back

Write a literal representing the false value .

False

Write a literal representing the true value .

True

Declare a variable isACustomer suitable for representing a true or false value .

boolean isACustomer;

Declare a variable hasPassedTest, and initialize it to true .

Boolean hasPassedTest = true;

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.

(grossPay<10000)

Write an expression that evaluates to true if and only if the integer x is greater than the integer y.

(x>y)

Write an expression that evaluates to true if and only if the value of the integer variable x is equal to zero.

(x == 0)

Write an expression that evaluates to true if and only if the variables profits and losses are exactly equal .

(profits == losses)

Write an expression that evaluates to true if the value of index is greater than the value of lastIndex.

(index > lastIndex)

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.

(hoursWorked > 40)

Write an expression that evaluates to true if the value x is greater than or equal to y.

(x >= y)

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)

Given a double variable called average, write an expression that is true if and only if the variable 's value is less than 60.0.

(average < 60.0)

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 == ' ')

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 ifc is a newline character .

(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 space character .

(c == ' ')

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 .

(c == '\t')

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%2 == 0)

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.

(numberOfPrizes % numberOfParticipants == 0)

Write an expression that evaluates to true if the value of the integer variable widthOfBox is not divisible by the value of the integer variable widthOfBook. Assume that widthOfBook is not zero. ("Not divisible" means has a remainder.)

(widthOfBox % widthOfBook != 0)

Write an expression that evaluates to true if and only if the value of the boolean variable workedOvertime is true .

(workedOvertime == true)

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.

if (hoursWorked > 40)


workedOvertime= true;


else


workedOvertime = false;

Write a conditional that assigns 10,000 to the variable bonus if the value of the variable goodsSold is greater than 500,000.

if (goodsSold > 500000) {


bonus = 10000;


}

Write a conditional that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90.

if (outsideTemperature > 90) {


shelfLife = shelfLife - 4;


}

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 (gpa > 3.5)


{


deansList +=1;


System.out.println(studentName);


}

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;

Write an if/else statement that compares the value of the variables soldYesterday and soldToday, and based upon that comparison assigns salesTrend the value -1 or 1.




-1 represents the case where soldYesterday is greater than soldToday; 1 represents the case where soldYesterday is not greater than soldToday.

if (soldYesterday > soldToday)


salesTrend = -1;


else


salesTrend = 1;

NOTE: in mathematics, the square root of a negative number is not real; in Java therefore, passing such a value to the square root function returns a value known as NaN (not-a-number).




Given a double variable named areaOfSquare write the necessary code to read in a value , the area of some square, intoareaOfSquare and print out the length of the side of that square.




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.



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 intocallsReceived andoperatorsOnCalland 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.



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 .



Write a conditional that assigns the boolean value true to the variable fever if the variable temperature is greater than 98.6.

if (temperature > 98.6)


fever = true;

Write a conditional that multiplies the value of the variable pay by one-and-a-half if the value of the boolean variable workedOvertime is true .

if (workedOvertime == true)


pay = pay * 1.5;

Write an if/else statement that assigns true to the variable fever if the variable temperature is greater than 98.6; otherwise it assigns false to fever.

if (temperature > 98.6)


fever = true;


else


fever = false;

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.



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.



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



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 .



Assume that an int variable age has been declared and already given a value . Assume further that the user has just been presented with the following menu:




S: hangar steak, red potatoes, asparagus


T: whole trout, long rice, brussel sprouts


B: cheddar cheeseburger, steak fries, cole slaw




Write some code that reads the String (S or T or B) that the user types in into a String variable choice that has already been declared and prints out a recommended accompanying drink as follows: if the value ofage is 21 or lower, the recommendation is "vegetable juice" for steak, "cranberry juice" for trout, and "soda" for the burger. Otherwise, the recommendations are "cabernet", "chardonnay", and "IPA" for steak, trout, and burger respectively. Regardless of the value ofage, your code should print "invalid menu selection" if the character read into choice was not S or T or B.




ASSUME the availability of a variable , stdin, that references a Scanner object associated with standard input.



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 isPremiumCustomerand the int variable nbooksPurchased.



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 ifc is 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).

(c == ' ' || c== '\n' || c == '\t')

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 ifc 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).

!(c == ' ' || c== '\n' || c == '\t')

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 >= 0 && y<0)

Given that the variables x and y have already been declared and assigned values , write an expression that evaluates to true if x is positive (including zero) or y is negative.

(x>=0 || y<0)

Given the integer variables yearsWithCompany and department, write an expression that evaluates to true if yearsWithCompany is less than 5 and department is not equal to 99.

(yearsWithCompany < 5 && department !=99)

Given the variables temperature and humidity, write an expression that evaluates to true if and only if the temperature is greater than 90 and the humidity is less than 10.

(temperature>90 && humidity < 10)

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==true || numberOfCredits==3)

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==false && numberOfCredits>2)

Given two variables , isEmpty of type boolean , indicating whether a class roster is empty or not, and numberOfCredits of type integer , 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 one or three credits.

(isEmpty==false && (numberOfCredits == 1 || numberOfCredits == 3))

Given the variables isFullTimeStudent and age, write an expression that evaluates to true if age is less than 19 or isFullTimeStudent is true .

(age < 19 || isFullTimeStudent == true)

Write an expression that evaluates to true if and only if value of the boolean variable isAMember is false .

(isAMember==false)

Write a statement that toggles the value of onOffSwitch. That is, if onOffSwitch is false , its value is changed to true ; if onOffSwitch is true , its value is changed to false .



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 (numberOfSides == 4)


isQuadrilateral = true;


else


isQuadrilateral = false;

Assign to the boolean variable 'possibleCandidate' the value false if the int variable 'n' is even and greater than 2, or if the variable 'n' is less than or equal to 0; otherwise, assign true to 'possibleCandidate'.




Assume 'possibleCandidate' and 'n' are already declared and 'n' assigned a value .



Clunker Motors Inc. is recalling all vehicles from model years 2001-2006. A boolean variable named recalled has been declared . Given a variable modelYear write a statement that assigns true torecalled if the value of modelYear falls within the recall range and assigns false otherwise.

recalled = (modelYear >=2001 && modelYear <=2006);

Clunker Motors Inc. is recalling all vehicles from model years 2001-2006. A boolean variable named norecall has been declared . Given a variable modelYear write a statement that assigns true tonorecall if the value of modelYear does NOT within the recall range and assigns false otherwise.

norecall = !(modelYear >=2001 && modelYear <=2006);

Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. A boolean variable named recalled has been declared . Given a variable modelYear write a statement that assigns true torecalled if the value ofmodelYear falls within the two recall ranges and assigns false otherwise.

recalled = ((modelYear >=1995 && modelYear <=1998) || (modelYear >= 2004 && modelYear <= 2006));

Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. A boolean variable named recalled has been declared . Given a variable modelYear write a statement that assigns true tonorecall if the value ofmodelYear does NOT fall within the two recall ranges and assigns false otherwise.

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 NOT a letter.

!((x>='A' && x<='Z') || (x>='a' && x<='z'))

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 upper-case letter.

(x>='A' && x<='Z')

Assume thatx is a char variable has been declared and already given a value . Write an expression whose value is true if and only ifx is a lower-case letter.

(x>='a' && x<='z')

Assume thatx is a char variable has been declared and already given a value . Write an expression whose value is true if and only ifx is a decimal digit (0-9).

(x>='0' && x<='9')

Assume thatx is a char variable has been declared and already given a value . Write an expression whose value is true if and only ifx is a letter.

((x>='A' && x<='Z') || (x>='a' && x<='z'))

Assume thatx is a char variable has been declared and already given a value . Write an expression whose value is true if and only ifx is alphanumeric , that is either a letter or a decimal digit.

((x>='A' && x<='Z') || (x>='a' && x<='z') || (x>='0' && x<='9'))

Assume thatx is a char variable has been declared and already given a value . Write an expression whose value is true if and only ifx is an hexadecimal (Base 16) digit (0-9 plus A-F or a-f).

(( x>='0' && x<='9') || ( x>='a' && x<='f' ) || ( x>='A' && x<='F'))

Assume thatx is a char variable has been declared and already given a value . Write an expression whose value is true if and only ifx is NOT a upper-case letter.

!(x>='A' && x<='Z')

Clunker Motors Inc. is recalling all vehicles from model years 2001-2006. 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");

Clunker Motors Inc. is recalling all vehicles from model years 2001-2006. 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 >= 2001 && modelYear <= 2006)


System.out.println("RECALL");

Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. Given a variable modelYear write a statement that prints the message "RECALL" to standard output if the value ofmodelYear falls within those two ranges.

if ((modelYear >= 1995 && modelYear <= 1998) || (modelYear >=2004 && modelYear<=2006))


System.out.println("RECALL");

Write a switch statement that tests the value of the char variable response and performs the following actions:




if response is y, the message Your request is being processed is printed




if response is n, the message Thank you anyway for your consideration is printed




if response is h, the message Sorry, no help is currently available is printed




for any other value of response, the message Invalid entry; please try again is printed



HTTP is the protocol that governs communications between web servers and web clients (i.e. browsers). Part of the protocol includes a status code returned by the server to tell the browser the status of its most recent page request. Some of the codes and their meanings are listed below:




200, OK (fulfilled)


403, forbidden


404, not found


500, server error




Given an int variable status, write a switch statement that prints out, on a line by itself, the appropriate label from the above list based on status.



In the Happy Valley School System, children are classified by age as follows:




less than 2, ineligible


2, toddler


3-5, early childhood


6-7, young reader


8-10, elementary


11 and 12, middle


13, impossible


14-16, high school


17-18, scholar


greater than 18, ineligible




Given an int variable age, write a switch statement that prints out, on a line by itself, the appropriate label from the above list based on age.



Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessary code to read a value into intoresponse and then carry out the following:




if the value typed in is a 1 or a 2 then increment yesCount and print out "YES WAS RECORDED"




if the value typed in is a 3 or an 4 then increment noCount and print out "NO WAS RECORDED"




If the input is invalid just print the message "INVALID" and do nothing else.




ASSUME the availability of a variable , stdin, that references a Scanner object associated with standard input



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)

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

(x >= 5 ? x : -x)

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.

(x1 < x2 ? x2 : x1) - (y1 < y2 ? y1 : y2)

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".

(credits < 30) ? "freshman" : (credits >= 30 && credits < 60) ?"sophomore" : (credits >= 60 && credits < 90) ? "junior" : "senior"