Concept explainers
Suppose salary and deductions are variables of type double that have been given values. Write an if- else statement that displays OK and sets the variable net equal to salary minus deductions, provided that salary is at least as large as deductions. If, however, salary is less than deductions, the if-else statement should simply display the words No way but not change the value of any variables.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Additional Engineering Textbook Solutions
C How to Program (8th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Absolute Java (6th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out With Visual Basic (8th Edition)
- Write the statement in words if: p: Firemen work hard. q: Firemen wear red suspenders 3) ~p → qarrow_forwardSuppose goals is a variable of type int. Write an if-else statement that displays the word Wow if the value of the variable goals is greater than 10 and displays the words Oh Well if the value of goals is at most 10.arrow_forwardSuppose x, y, and z are int variables and w and t are double variables. What are the values of all five variables after all the following statements have been executed? Hint, the mod operator is the same level of precedence as * and /, and be careful about integer division. x = 17; y = 15; x = x + y / 4; z = x % 3 + 4; w = 17 / 3 + 6.5; t = x / 4.0 + 15 % 4 - 3.5;arrow_forward
- Write the following compound statement in terms of the simple statements p, q, and r. "I go to office hours and ask questions, and my professor does not remember me." p: I go to office hours. q: I ask questions. r: My professor remembers me.arrow_forwardWrite an if statement that will print "equal" if the variables first and second agree to seven significant digits and "not equal" otherwise. First and second are variables of type double.arrow_forwardA student makes the following argument. if I receive a good grade, the instructor teaches well. I didn't receive a good grade. Therefore, the instructor didn't teach well. is the student's argument valid? Let A be the statement, "I receive a good grade" and B be the statement, " the instructor teaches well." Then, rewrite the above paragraph using A and B.arrow_forward
- Find the statement that is equivalent to the following conditional statement. If I get a speeding ticket, then my parents will not pay my car insurance. a. I do not get a speeding ticket and my parents will not pay my car insurance. b. If I do not get a speeding ticket, then my parents will pay my car insurance. c.I do not get a speeding ticket or my parents will not pay my car insurance. d.If my parents will not pay my car insurance, then I get a speeding ticket.arrow_forwardRewrite the following expressions using the conditional operator. (Assume that all variables are declared properly.)a. if (x == y)z = x + y;elsez = (x + y) / 2;b. if (hours >= 40.0)wages = 40 * 7.50 + 1.5 * 7.5 * (hours - 40);elsewages = hours * 7.50;c. if (loanAmount >= 200000)closingCosts = 10000;elseclosingCosts = 8000;arrow_forwardSuppose savings and expenses are variables of type double that have beengiven values. Write an if-else statement that outputs the word "Solvent",decreases the value of savings by the value of expenses, and sets the value ofexpenses to zero, provided that savings is larger than expenses. If, however,savings is less than or equal to expenses, the if-else statement should simplyoutput the word "Bankrupt" without changing the value of any variables.arrow_forward
- Write a multiway if-else statement that classifies the value of an int variable ninto one of the following categories and writes out an appropriate message:n < 0 or 0 ≤ n < 100 or n ≥ 100Hint: Remember that the Boolean expressions are checked in order.arrow_forwardWrite a if-elif-else statement that distinguishes between a negative number or 0, a number between 0 and 50, and a number greater than or equal 50 by printing one of these three statements: {"It's negative or zero", "It's between 0 and 50", "It's greater than or equal to 50"}.arrow_forwardConsider the following code, where i, j, and k are boolean variables. if (i) if (j) if (k) humpty(); else; else;else if (j) if (k) dumpty(); else bumpty(); else; Which of the following is not equivalent to the above statement? Group of answer choices if (i && j && k) humpty();else if (j && k) dumpty();else bumpty(); if (k)if (j)if (i) humpty();else dumpty();else;else if (j && !i) bumpty(); if (j)if (i && k) humpty();else if (!i && k) dumpty();else if (!i && !k) bumpty(); if (i && j && k) humpty();else if (!i && j && k) dumpty();else if (!i && j && !k) bumpty();arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT