MyProgrammingLab 2.6, 2.7, 2.8, 2.9
Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So, if the value of price was 4321, your code would print "43 dollars and 21 cents". If the value was 501 it would print "5 dollars and 1 cents". If the value was 99 your code would print "0 dollars and 99 cents".
System.out.println(price/100 + " dollars and " + price%100 + " cents");
Given the variables taxablePurchases and taxFreePurchases (already declared and assigned values), write an expression corresponding to the total amount purchased.
taxablePurchases + taxFreePurchases
Given three already declared int variables, i, j, and temp, write some code that swaps the values in i and j. Use temp to hold the value of i and then assign j's value to i. The original value of i, which was saved in temp, can now be assigned to j.
temp = i; i=j; j=temp;
Write an expression that computes the sum of two double variables total1 and total2, which have been already declared and assigned values.
total1 + total2
You are given two double variables, already declared and assigned values, named totalWeight, containing the weight of a shipment, and weightOfBox, containing the weight of the box in which a product is shipped. Write an expression that calculates the net weight of the product.
totalWeight - weightOfBox
Write an expression that computes the sum of two variables verbalScore and mathScore (already declared and assigned values).
verbalScore + mathScore
Assume that an int variable x that has already been declared, and initialized to a non-negative value. Write an expression whose value is the last (rightmost) digit of x.
x%10
QUESTION 2: Correct Which of the following is NOT an operator? % ! + ;
;
QUESTION 1: Correct Which of the following is NOT an operator? / + add ( ) *
add
Given the variables costOfBusRental and maxBusRiders of type int , write an expression corresponding to the cost per rider (assuming the bus is full). (Do not worry about any fractional part of the expression-- let integer arithmetic, with truncation, act here.)
costOfBusRental / maxBusRiders
Given two double variables, bestValue and secondBestValue, write some code that swaps their values. Declare any additional variables as necessary.
double temp; temp = bestValue; bestValue = secondBestValue; secondBestValue = temp;
Given an integer variable drivingAge that has already been declared, write a statement that assigns the value 17 to drivingAge.
drivingAge = 17;
Write an expression that computes the difference of the variables endingTime and startingTime.
endingTime - startingTime
Declare a constant MONTHS_IN_DECADE, whose value is the value of the constant MONTHS_IN_YEAR (already declared) multiplied by 10.
final int MONTHS_IN_DECADE = MONTHS_IN_YEAR*10;
Declare an integer constant, MONTHS_IN_YEAR, whose value is 12.
final int MONTHS_IN_YEAR = 12;
Given the variables fullAdmissionPrice and discountAmount (already declared and assigned values), write an expression corresponding to the price of a discount admission.
fullAdmissionPrice - discountAmount
Given two integer variables matricAge and gradAge, write a statement that gives gradAge a value that is 4 more than the value of matricAge.
gradAge = matricAge + 4;
QUESTION 1: Correct Of the following variable names, which is the best one for keeping track of whether a patient has a fever or not? temperature feverTest hasFever fever
hasFever
Given two int variables, firstPlaceWinner and secondPlaceWinner, write some code that swaps their values. Declare any additional variables as necessary.
int i; i=firstPlaceWinner; firstPlaceWinner=secondPlaceWinner; secondPlaceWinner=i;
Declare and initialize the following variables: monthOfYear, initialized to the value 11 companyRevenue, initialized to the value 5666777 firstClassTicketPrice, initialized to the value 6000 totalPopulation, initialized to the value 1222333
int monthOfYear = 11; int companyRevenue = 5666777; int firstClassTicketPrice = 6000; int totalPopulation = 1222333;
Four integer variables, pos1, pos2, pos3, pos4 have been declared and initialized. Write the code necessary to "left rotate" their values: for each variable to get the value of the successive variable, with pos4 getting pos1's value.
int temp; temp = pos1; pos1 = pos2; pos2 = pos3; pos3 = pos4; pos4 = temp;
Given two int variables, i and j, which have been declared and initialized, and two other int variables, itemp and jtemp, which have been declared, write some code that swaps the values in i and j by copying their values to itemp and jtemp respectively, and then copying itemp and jtemp to j and i respectively.
jtemp = j; itemp=i; j= itemp; i=jtemp;
Declare a long integer variable named grossNationalProduct.
long grossNationalProduct;
QUESTION 2: Correct Of the following variable names, which is the best one for keeping track of whether an integer might be prime or not? divisible isPrime mightBePrime number
mightBePrime
QUESTION 1: Correct Which is the best identifier for a variable to represent the amount of money your boss pays you each month? notEnough wages paymentAmount monthlyPay money
monthlyPay
Given two integer variables oldRecord and newRecord, write a statement that gives newRecord the same value that oldRecord has.
newRecord = oldRecord;
You are given two variables, already declared and assigned values, one of type double, named price, containing the price of an order, and the other of type int, named totalNumber, containing the number of orders. Write an expression that calculates the total price for all orders.
price * totalNumber
Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is paid for with a minimum amount of change and just single dollars, write an expression for the number of single dollars that would have to be paid.
price / 100
Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is paid for with a minimum amount of change and just single dollars, write an expression for the amount of change (in cents) that would have to be paid.
price%100
Given the variable pricePerCase, write an expression corresponding to the price of a dozen cases.
pricePerCase * 12
Write an expression that computes the remainder of the variable principal when divided by the variable divisor. (Assume both are type int.)
principal % divisor
Write an expression that computes the difference of two double variables salesSummer and salesSpring, which have been already declared and assigned values.
salesSummer - salesSpring
Declare a short variable named patientsAge.
short patientsAge;
A wall has been built with two pieces of sheetrock, a smaller one and a larger one. The length of the smaller one is stored in the variable small. Similarly, the length of the larger one is stored in the variable large. Write a single expression whose value is the length of this wall.
small+large