Problem 2
State whether each of the following is true or \(f\) alse. If false , explain why. a) An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which they execute. b) \(\mathrm{A}\) set of statements contained within a pair of parentheses is called a block. c) A selection statement specifies that an action is to be repeated while some condition remains true. d) A nested control statement appears in the body of another control statement. e) Java provides the arithmetic compound assignment operators \(+=,-=,^{2}=, \quad /=\) and \(\aleph=\) for abbreviating assignment cxpressions. The primitive types (boolean, char, byte, short, int, long, float and double) are portable across only Windows platforms. g) Specifying the order in which statements (actions) execute in a program is called program control. h) The unary cast operator (double) creates a temporary integer copy of its operand. i) Instance variables of type boolean are given the value true by default. j) Pseudocode helps a programmer think out a program before attempting to write it in a programming language.
Problem 3
Write four different Java statements that cach add 1 to integer variable x.
Problem 5
Write a Java statement to accomplish each of the following tasks: a) Declare variables sum and \(x\) to be of type int. b) Assign 1 to variable x. c) Assign 0 to variable sum. d) Add variable \(\times\) to variable sum, and assign the result to variable sum. e) Print "The sum is: ", followed by the value of variable sum.
Problem 10
Compare and contrast the if single-selection statement and the while repetition statement. How are these two statements similar? How are they different?
Problem 11
Explain what happens when a Java program attempts to divide one integer by another. What happens to the fractional part of the calculation? How can a programmer avoid that outcome?
Problem 13
What type of repetition would be appropriate for calculating the sum of the first 100 positive integers? What type of repetition would be appropriate for calculating the sum of an arbitrary number of positive integers? Briefly describe how each of these tasks could be performed.
Problem 14
What is the difference between preincrementing and postincrementing a variable?
Problem 17
a) Read the problem statement. b) Formulate the algorithm using pseudocode and top-down, stepwise refinement. c) Write a Java program. d) Test, debug and execute the Java program. e) Process three complete sets of data. Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a Java application that will input the miles driven and gallons used (both as integers) for each tankful. The program should calculate and display the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up to this point. All averaging calculations should produce floating-point results. Use class Scanner and sentinel-controlled repetition to obtain the data from the user.
Problem 18
a) Read the problem statement. b) Formulate the algorithm using pseudocode and top-down, stepwise refinement. c) Write a Java program. d) Test, debug and execute the Java program. e) Process three complete sets of data. Develop a Java application that will determine whether any of several department-store customers has exceeded the credit limit on a charge account. For each customer, the following facts are available: a) account number b) balance at the beginning of the month c) total of all items charged by the customer this month d) total of all credits applied to the customer's account this month e) allowed credit limit. The program should input all these facts as integers, calculate the new balance ( = brginming balance \(+\text { duarges }-\text { credits }),\) display the new balance and determine whether the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the message "Credit 1 imit exceeded".
Problem 20
Develop a Java application that will determine the gross pay for each of three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40 hours. You are given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee. Your program should input this information for each employee and should determine and display the employee's gross pay. Use class Scanner to input the data.