MyProgrammingLab - Chapter 2: Java Fundamentals (Tony Gaddis)

Ace your homework & exams now with Quizwiz!

Calculate the average (as a double) of the values contained in the integer variables num1, num2, num3 and assign that average to the double variable avg. Assume the variables num1, num2, and num3 have been declared and assigned values, and the variable avg declared.

avg = (double)(num1+num2+num3)/3;

Declare a variable hasPassedTest, and initialize it to true.

boolean hasPassedTest = true;

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

boolean isACustomer;

Given an integer variable bridgePlayers, write a statement that increases the value of that variable by 4.

bridgePlayers += 4;

Declare a character variable named c.

char c;

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

Declare two double variables, one named length with a value of 3.5 and the other named width with a value of 1.55.

double length = 3.5, width = 1.55;

Declare a variable precise and initialize it to the value 1.09388641.

double precise = 1.09388641;

Declare a variable temperature and initialize it to 98.6.

double temperature = 98.6;

Declare a variable x, suitable for storing values like 3.14159 and 6.02E23.

double x;

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 three String variables that have been declared and given values, firstName, middleName, and lastName, write an expression whose value is the values of each these variables joined by a single space. So if firstName, middleName, and lastName, had the values "Big", "Bill", and "Broonzy", the expression's value would be "Big Bill Broonzy". Alternatively, if firstName, middleName, and lastName, had the values "Jerry", "Lee", and "Lewis", the expression's value would be "Jerry Lee Lewis".

firstName + " " + middleName + " " + lastName

Write a statement that reads a word from standard input into firstWord. Assume that firstWord. has already been declared as a String variable. Assume also that stdin is a variable that references a Scanner object associated with standard input.

firstWord = stdin.nextLine();

Assume that the String variable named foreground has already been declared. Assign it the value "red".

foreground = "red";

Given three String variables that have been declared and given values, gold, silver, and bronze, write an expression whose value is the values of each these variables joined by a newline character. So if gold, silver, and bronze, had the values "Arakawa", "Cohen", and "Slutskaya", the expression, if it were printed would have the names "Arakawa", "Cohen", and "Slutskaya" each appearing on a separate line. (Do NOT print anything in this exercise: just write the expression.)

gold + "\n" + silver + "\n" + bronze

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;

In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Assume that n is an integer variable whose value is some positive integer N. Assume also that hn is a variable whose value is the Nth harmonic number. Write an expression whose value is the (N+1)th harmonic number.

hn + 1.0/(n+1)

The import statement needed to use JOptionPane is import javax.swing.JOptionPane ;

import javax.swing.JOptionPane;

Declare an integer variable named degreesCelsius.

int degreesCelsius;

Declare a short variable named patientsAge.

short patientsAge;

The JOptionPane method that gets input from the user is showInputDialog

showInputDialog

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

Given the String variable str, write an expression that evaluates to the character at index 0 of str.

str.charAt(0)

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 a statement that reads a floating point value from standard input into temperature. Assume that temperature. has already been declared as an double variable. Assume also that stdin is a variable that references a Scanner object associated with standard input.

temperature = stdin.nextDouble();

Assume that theString variable named text has already been declared. Assign to it the empty string.

text = "";

Write a statement that reads an integer value from standard input into val. Assume that val has already been declared as an int variable. Assume also that stdin is a variable that references a Scanner object associated with standard input.

val = stdin.nextInt();

Write an expression that computes the sum of two variables verbalScore and mathScore (already declared and assigned values).

verbalScore + mathScore

The dimensions (width and length) of room1 have been read into two variables: width1 and length1. The dimensions of room2 have been read into two other variables: width2 and length2. Write a single expression whose value is the total area of the two rooms.

width1*length1 + width2*length2

Java represents characters using ASCII Unicode EBCDIC Morse Code Gray Code With its encoding Java can work with characters. 65536 65,536

2, 65536

In Java, an argument is a logical sequence of statements proving the correctness of a program. information that a method returns to its caller. information provided to a method. a verbal dispute.

3

Declare a double variable named netWeight.

double netWeight;

Write a literal representing the false value.

false

Declare a float variable named price.

float price;

Given the variables fullAdmissionPrice and discountAmount (already declared and assigned values), write an expression corresponding to the price of a discount admission.

fullAdmissionPrice - discountAmount

Declare an integer variable cardsInHand and initialize it to 13.

int cardsInHand = 13;

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

Write a String constant consisting of exactly 5 exclamation marks.

"!!!!!"

Write a String constant that is the empty string.

""

Given a String variable word, write a String expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the String "(sadly)"

"(" + word + ")"

If a right triangle has sides of length A, B and C and if C is the largest, then it is called the "hypotenuse" and its length is the square root of the sum of the squares of the lengths of the shorter sides (A and B). Assume that variables a and b have been declared as doubles and that a and b contain the lengths of the shorter sides of a right triangle: write an expression for the length of the hypotenuse.

Math.sqrt(Math.pow(a, 2.0) + Math.pow(b, 2.0))

The length of a rectangle is stored in a double variable named length, the width in one named width. Write an expression whose value is the length of the diagonal of the rectangle.

Math.sqrt(Math.pow(length, 2.0) + Math.pow(width, 2.0))

The area of a square is stored in a double variable named area. Write an expression whose value is length of one side of the square.

Math.sqrt(area)

The area of a square is stored in a double variable named area. Write an expression whose value is length of the diagonal of the square.

Math.sqrt(Math.pow(Math.sqrt(area), 2.0) + Math.pow(Math.sqrt(area), 2.0))

Given an int variable datum that has already been declared, write a few statements that read an integer value from standard input into this variable.

Scanner keyboard = new Scanner(System.in); datum = keyboard.nextInt();

Given the String variable address, write an expression that returns the position of the first occurrence of the String "Avenue" in address.

address.indexOf("Avenue")

Write a character literal representing a comma.

','

Write a character literal representing the digit 1.

'1'

Write an expression whose value is the number of characters in the following String:          "CRAZY!\n\\\t\\\\\\\\\\n. . . .\\ \\\r\007'\\'\"TOOMUCH!" Suggestion: copy/paste the above String into your code-- it's too crazy to try to copy it by typing.

"CRAZY!\n\\\t\\\\\\\\\\n. . . .\\ \\\r\007'\\'\"TOOMUCH!".length()

Given a String variable address, write a String expression consisting of the string "http://" concatenated with the variable's String value. So, if the variable refers to "www.turingscraft.com", the value of the expression would be "http://www.turingscraft.com".

"http://" + address

Write a String constant consisting of exactly one character-- any character will do.

"w"

Write a character literal representing the (upper case) letter A.

'A'

Write a literal representing the character whose unicode value is 65.

'A'

Three classes of school children are selling tickets to the school play. The number of tickets sold by these classes, and the number of children in each of the classes have been read into these variables:tickets1, tickets2, tickets3 and class1, class2, class3. Write an expression for the average number of tickets sold per school child.

((double)tickets1 + tickets2 + tickets3) / ((double)class1+class2+class3)

Write an expression that computes the average of the values 12 and 40.

(12 + 40) /2

Assume that children is an integer variable containing the number of children in a community and that families is an integer variable containing the number of families in the same community. Write an expression whose value is the average number of children per family.

(double)children/families

Given two integer variables distance and speed, write an expression that divides distance by speed using floating point arithmetic, i.e. a fractional result should be produced.

(double)distance/(double)speed

Write an expression that computes the integer average of the int variables exam1 and exam2 (both declared and assigned values).

(exam1 + exam2)/2

Each of the walls of a room with square dimensions has been built with two pieces of sheetrock, a smaller one and a larger one. The length of all the smaller ones is the same and is stored in the variable small. Similarly, the length of all the larger ones is the same and is stored in the variable large. Write a single expression whose value is the total area of this room. DO NOT USE any method invocations.

(small+large) * (small + large)

What's the difference in UNICODE value between 'E' and 'A'? (consult a table of UNICODE values): *4 * What's the difference in UNICODE value between 'e' and 'a'? (consult a table of UNICODE values): *4 * What's the difference in UNICODE value between '3' and '0'? (consult a table of UNICODE values): *3 * What's the difference in UNICODE value between '6' and '0'? (consult a table of UNICODE values): *6 *

, 64c1=4::::c2=3::::

The character escape sequence to force the cursor to go to the next line is: \n endl This will accomplish the same when used with cout, say, but it is not a character. '\n' You have the right idea, but the question doesn't ask for a character literal, just the sequence itself. Omit the quotes. "\n" You have the right idea, but the question doesn't ask for a string literal, just the sequence itself. Omit the quotes. The character escape sequence to force the cursor to advance forward to the next tab setting is: \t '\t' You have the right idea, but the question doesn't ask for a character literal, just the sequence itself. Omit the quotes. "\t" You have the right idea, but the question doesn't ask for a string literal, just the sequence itself. Omit the quotes. The character escape sequence to represent a single quote is: \' '\'' You have the right idea, but the question doesn't ask for a character literal, just the sequence itself. Omit the quotes. "\'" You have the right idea, but the question doesn't ask for a string literal, just the sequence itself. Omit the quotes. The character escape sequence to represent a double quote is: \" '\"' You have the right idea, but the question doesn't ask for a character literal, just the sequence itself. Omit the quotes. "\"" You have the right idea, but the question doesn't ask for a string literal, just the sequence itself. Omit the quotes. The character escape sequence to represent a backslash is: \\ '\\' You have the right idea, but the question doesn't ask for a character literal, just the sequence itself. Omit the quotes. "\\" You have the right idea, but the question doesn't ask for a string literal, just the sequence itself. Omit the quotes.

, \"\\c0=\n::::c1=\t::::c2=\'::::

Given two double variables, bestValue and secondBestValue, write some code that swaps their values. Declare any additional variables as necessary.

/* Too precise for MPL *facepalm* bestValue = bestValue + secondBestValue; secondBestValue = bestValue - secondBestValue; bestValue = bestValue - secondBestValue; */ double tmp = bestValue; bestValue = secondBestValue; secondBestValue = tmp;

A comment starts with what characters? *// */\* The text of a comment is checked by the compiler for accuracy. No, the C++ (and all compilers for that matter) ignore the comment entirely. must appear in the first line of the program. No, comments can be placed anywhere in the program. is printed out when the program runs. No, the comment only appears in the source code. can be anything the programmer wants to write. Yes, but it's best if the comment helps the reader understand the program.

//, 4

Write a literal representing the integer value zero.

0

Write a floating point literal corresponding to the value zero.

0.0

In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Write an expression whose value is the 8th harmonic number.

1 + .5 + (double)1/3 + (double)1/4 + (double)1/5 + (double)1/6 + (double)1/7 + (double)1/8

Which of the following lines contains a valid, though not necessarily accurate, comment? int twoPi = 3.14159; /* holds the value of two times pi */ int twoPi = 2*3.14159; /* holds the value of two times pi //* int twoPi = 2*3.14159; / / *holds the value of 6 //* double twoPi = 2*3.14159; /* // holds the value of two time pi */ [comment] // Which of the following lines does NOT consist of (a) valid, though boastful, comment(s)? // /* This is a */ First Rate Program //**// This is a //**// First Rate Program //**// //* This is a //*// First Rate Program //*// /* This is a //*// First Rate Program //*//

1, 4

Before a variable is used it must be defined declared imported evaluated assigned

2

We hope you never have to encounter anything like the following expression in a program, but consider it for a moment and indicate its value: ( /* 5 + 3 */ - 9 + 6/*8*//2 ) //*+4*/ -10 3 -7 -6 5 -8

3

Which of the following IS a legal identifier? 5_And_10 Can't start with a digit. Five_&_Ten Can't contain special characters like & ____________ Weird, but valid. LovePotion#9 Can't contain a #. "Hello World" Can't contain double quotes. This is actually a string literal.

3

Of the following variable names, which is the best one for keeping track of whether a patient has a fever or not? temperature First of all, everybody has a temperature. The question is whether the temperature is too high. Secondly, temperature is a number normally: we want to represent a boolean yes-or-no situation. Thirdly: we like to represent boolean conditions by predicates. feverTest The problem here is that it is not 100% clear that feverTest being true means that the patient has a fever. hasFever fever This is not too bad a name, but it does not read as well as a predicate. The predicate form, "has fever" reads a little bit more clearly. Of the following variable names, which is the best one for keeping track of whether an integer might be prime or not? divisible Yes, divisibility comes into the picture, but this name does not tell us precisely what information we're keeping track of here. isPrime This name has the right form (predicate) but is actually misleading: "might be" and "is" are different things! mightBePrime number One would expect a number to have numerical values, not boolean-- and this name doesn't indicate precisely what information the variable is providing.

3, 3

Which of the following is NOT an operator? / + add ( ) A pair of parentheses actually constitutes an operator-- it can be used in expressions to define a sub-expression. * Which of the following is NOT an operator? % ! this is an operator that is used with input streams like cin + ; semicolons are tokens used for terminating certain statements-- they are not operators *

3, 4

Write a literal corresponding to the value of the first 6 digits of PI ("three point one four one five nine").

3.14159

Which comment below is the most helpful? int volume; // declare an int int volume; // declare volume int volume; // declare volume to be an int variable int volume; // size of trunk in cubic feet

4

Which is the best identifier for a variable to represent the amount of money your boss pays you each month? notEnough An understandable sentiment, but how would another programmer know this is your pay? Maybe it could be vacation days? wages There's a better choice here. paymentAmount There's a better choice here. monthlyPay money There's a better choice here.

4

Which of the following names in a program is equivalent to the name int? Int Case matters. INT Case matters All of the above Case matters. None of the above Only int is int: case matters.

4

Which of the following is NOT a legal identifier? outrageouslyAndShockinglyLongRunon _42 _ lovePotionNumber9 7thheaven

5

Write a literal representing the largest character value.

65535

The class allows non-GUI applications to interact with users using dialog boxes. JOptionPane

JOptionPane

Data returned by JOptionPane is always of the type (excluding yes-or-no questions). String

String

Write the declaration of two String variable named background and selectionColor and initialize them to "white" and "blue" respectively.

String background = "white", selectionColor = "blue";

Declare a String variable named empty, and initialize it to the empty String.

String empty = "";

Declare a String variable named mailingAddress.

String mailingAddress;

Declare a String variable named oneSpace, and initialize it to a String consisting of a single space.

String oneSpace = " ";

Write the declaration of a String variable named title.

String title;

There are two String variables, s1 and s2, that have already been declared and initialized. Write some code that exchanges their values. Declare any other variables as necessary.

String tmp = s1; s1 = s2; s2 = tmp;

Write the declaration of three String variables named win, place, and show.

String win,place,show;

Write a statement that prints Hello, world to the screen.

System.out.print("Hello, world");

Suppose your name was Alan Turing. Write a statement that would print your last name, followed by a comma, followed by a space and your first name.

System.out.print("Turing, Alan");

Given an integer variable count, write a statement that displays the value of count on the screen. Do not display anything else on the screen -- just the value of count.

System.out.print(count);

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");

Assume that word is a String variable. Write a statement to display the message "Today's Word-Of-The-Day is: " followed by the value of word. The message and the value of word should appear together, on  a single line on standard output.

System.out.println("Today's Word-Of-The-Day is: " + word);

Write a single statement that will print the message "first is " followed by the value of first, and then a space, followed by "second = ", followed by the value of second. Print everything on one line and go to a new line after printing. Assume that first has already been declared as a double and that second has been declared as an int. Assume also that the variables have already been given values.

System.out.println("first is " + first + " second = " + second);

The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything. Given an integer variable i and a floating-point variable f, that have already been given values, write a statement that writes both of their values to standard output in the following format: i=value-of-i f=value-of-f Thus, if i's value were 25 and f's value were 12.34, the output would be: i=25 f=12.34 But you don't know what i's value and f's value are. They might be 187 and 24.06. If that's what their values are, the output from your statement should be: i=187 f=24.06 On the other hand, they might be 19 and 2.001. If that's what their values are, the output from your statement should be: i=19 f=2.001 Remember: you are GIVEN i and f-- that means they are already declared and they already have values! Don't change their values by assigning or initializing them! Just print them out the way we have shown above. Just write one statement to produce the output. Remember: in your output you must be displaying both the name of the variable (like i) and its value.

System.out.println("i=" + i + " f=" + f);

Given a floating point variable fraction, write a statement that displays the value of fraction on the screen. Do not display anything else on the screen-- just the value of fraction.

System.out.println(fraction);

Assume that message is a String variable. Write a statement to display its value on standard output.

System.out.println(message);

Two variables, num and cost have been declared and given values: num is an integer and cost is a double. Write a single statement that outputs num and cost to standard output. Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character. Do not output any thing else.

System.out.println(num + " " + cost);

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, companyRevenue = 5666777, firstClassTicketPrice = 6000, totalPopulation = 1222333;

Declare a variable populationChange, suitable for holding numbers like -593142 and 8930522.

int populationChange;

Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear.

int profitStartOfQuarter, cashFlowEndOfYear;

Given two int variables, firstPlaceWinner and secondPlaceWinner, write some code that swaps their values. Declare any additional variables as necessary.

int tmp = firstPlaceWinner; firstPlaceWinner = secondPlaceWinner; secondPlaceWinner = tmp;

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[] tmps = {pos1, pos2, pos3, pos4); pos4 = tmps[0]; pos3 = tmps[3]; pos2 = tmps[2]; pos1 = tmps[1];

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.

itemp = i; jtemp = j; i = jtemp; j = itemp;

Given a String variable named line1 and given a Scanner reference variable stdin that has been assigned a reference to a Scanner object, read the next line from stdin and save it in line1. (Do not concern yourself with any possible exceptions here-- assume they are handled elsewhere.)

line1 = stdin.nextLine();

Assume that name has been declared suitably for storing names (like "Amy", "Fritz" and "Moustafa"). Assume also that stdin is a variable that references a Scanner object associated with standard input. Write some code that reads a value into name then prints the message "Greetings, NAMEVALUE!!!" on a line by itself where NAMEVALUE is replaced the value that was read into name. For example, if your code read in "Hassan" it would print out "Greetings, Hassan!!!" on a line by itself. 

name = stdin.next(); System.out.println("Greetings, " + name + "!!!");

Assume that name has been declared suitably for storing names (like "Misha", "Emily" and "Sofia"). Assume also that stdin is a variable that references a Scanner object associated with standard input Write some code that reads a value into name then prints the message "Greetings, NAME" on a line by itself, where NAME is replaced the value that was read into name. For example, if your code read in "Rachel" it would print out "Greetings, Rachel" on a line by itself.

name = stdin.next(); System.out.println("Greetings, " + name);

Assume that name and age have been declared suitably for storing names (like "Abdullah", "Alexandra" and "Zoe") and ages respectively. Assume also that stdin is a variable that references a Scanner object associated with standard input. Write some code that reads in a name and an age and then prints the message "The age of NAME is AGE" on a line by itself, where NAME and AGE are replaced by the values read in for the variables name and age. For example, if your code read in "Rohit" and 70 then it would print out "The age of Rohit is 70" on a line by itself. There should NOT be a period in the output.

name = stdin.next(); age = stdin.nextInt(); System.out.println("The age of " + name + " is " + age);

Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is the first character of the value of name. So if the value of name were "Smith" the expression's value would be 'S'.

name.charAt(0)

Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is the second character of the value of name. So if the value of name were "Smith" the expression's value would be 'm'.

name.charAt(1)

Write an expression that whose value is the fifth character of the String name.

name.charAt(4)

Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is the last character of the value of name. So if the value of name were "Blair" the expression's value would be 'r'.

name.charAt(name.length()-1)

Given a String variable named sentence that has been initialized, write an expression whose value is the the very last character in the String referred to by sentence.

sentence.charAt(sentence.length()-1)

Given a String variable named sentence that has been initialized, write an expression whose value is the number of characters in the String referred to by sentence.

sentence.length()

Three business partners are forming a company whose name will be of the form "Name1, Name2 and Name3". However, they can't agree whose name should be first, second or last. Help them out by writing code that reads in their three names and prints each possible combination exactly once, on a line by itself (that is, each possible combination is terminated with a newline character). Assume that name1, name2 and name3 have already been declared and use them in your code. Assume also that stdin is a variable that references a Scanner object associated with standard input. For example, if your code read in "Larry", "Curly" and "Moe" it would print out "Larry, Curly and Moe", "Curly, Larry and Moe", etc., each on a separate line.

name1 = stdin.next(); name2 = stdin.next(); name3 = stdin.next(); System.out.println( name1 + ", " + name2 + " and " + name3); System.out.println( name1 +", "+ name3+ " and " + name2); System.out.println( name2 +", "+ name1 + " and " + name3); System.out.println( name2 +", "+ name3+ " and " + name1 ); System.out.println( name3 +", "+ name1+ " and " + name2); System.out.println( name3 +", "+ name2+ " and " + name1 );

Given two integer variables oldRecord and newRecord, write a statement that gives newRecord the same value that oldRecord has.

newRecord = oldRecord;

Write an expression that concatenates the String variable suffix onto the end of the String variable prefix .

prefix + suffix

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

Given an integer variable profits, write a statement that increases the value of that variable by a factor of 10.

profits *= 10;

Write a complete program whose class name is Hello and that displays Hello, world on the screen.

public class Hello { public static void main(String[] args) { System.out.println("Hello, world"); } }

Rearrange the following code so that it forms a correct program that prints out the letter Q:

public class Q { public static void main(String[] args) { System.out.println("Q"); } }

Suppose your name was George Gershwin. Write a complete main method that would print your last name, followed by a comma, followed by a space and your first name.

public static void main(String[] args) { System.out.println("Gershwin, George"); }

Write a complete main  method that prints Hello, world to the screen.

public static void main(String[] args) { System.out.println("Hello, world"); }

Write an expression that computes the difference of two double variables salesSummer and salesSpring, which have been already declared and assigned values.

salesSummer - salesSpring

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

You are given two variables, already declared and assigned values, one of type double, named totalWeight, containing the weight of a shipment, and the other of type int, named quantity, containing the number of items in the shipment. Write an expression that calculates the weight of one item.

totalWeight / quantity

Write a literal representing the true value.

true


Related study sets

Nutrition Chapter 2 (Nutrient Recommendations

View Set

Series 6: Variable Products (Variable Annuity Taxation)

View Set

General Practice Exam-MD Accident, Health & Life Producer Practice Exam B

View Set

Praxis Elem. Ed- Math(5003) Chapter 1 - Rational Number Operations & Properties Quiz Questions, Praxis Elem. Ed- Math(5003) Chpt 2 - Representing Rational Numbers & Operations Quiz Questions, Praxis Elem. Ed- Math(5003) Chpt 4 - Number Theory & Mathe...

View Set

CHAPTER 9 ONLINE RETAIL AND SERVICE

View Set

Working with Windows and CLI Systems Chapter 5

View Set

Music Humanities Quiz 2 Terminology

View Set

Valvular Heart Disease Practice Questions

View Set