Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
7th Edition
ISBN: 9780133862119
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3.1, Problem 10STQ
What output is produced by the following code?
int time = 2, tide = 3;
if (time + tide > 6)
System.out.println(“Time and tide wait for no one.”);
else if (time + tide > 5)
System.out.println(“Time and tide wait for someone.”);
else if (time + tide > 4)
System.out.println(“Time and tide wait for everyone.”);
else
System.out.println(“Time and tide wait for me.”);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What is the output of the following, if n=1, n=2, n=3, n=4, and n=5, respectively?
int n = scan.nextInt();
switch (n)
{
case 1:
case 2:
System.out.print(“less than 3”);
break;
case 3:
case 4:
System.out.print(“less than 5 but bigger than 2”);
break;
default:
System.out.print(“Other situations”);
}
THIS IS IN JAVA
Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, items in parentheses are evaluated first.
<pre><code>(x == 5) || (y == 2) && (z == 5)</code></pre>
A. false OR (true AND false) --> false OR false --> false
B. false OR (true AND false) --> false OR true --> true
C. (false OR true) AND false --> true AND false --> false
D. (false OR true) AND false --> true AND false --> true
Write a program that calculates the estimated hours and minutes for a trip given the number of miles traveled and the speed in miles per hour.
Specifically, write a program that
Welcomes the user to the Travel Time Calculator.
Asks user for number of miles traveled(allow user to enter fractional values)
Asks user for the speed in miles per hour (allow user to enter fractional values)
Calculates the number of hours and minutes for the trip to the nearest integer value. Hint: You can use the built-in function round that rounds a given number to the rounded integer value. e.g. round(4) will return 4, round(4.125) will return 4, round(4.5) will return 4 and round (4.75) will return 5.
Prints the number of hours and minutes for the trip.
Here are some sample runs:
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Ch. 3.1 - Suppose goals is a variable of type int. Write an...Ch. 3.1 - Suppose goals and errors are variables of type...Ch. 3.1 - Suppose salary and deductions are variables of...Ch. 3.1 - Suppose speed and visibility are variables of type...Ch. 3.1 - Suppose salary and bonus are variables of type...Ch. 3.1 - Assume that nextWord is a string variable that has...Ch. 3.1 - Prob. 7STQCh. 3.1 - What output is produced by the following code? int...Ch. 3.1 - Suppose you change the code in the previous...Ch. 3.1 - What output is produced by the following code? int...
Ch. 3.2 - Suppose number is a variable of type int that has...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the code in the previous...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the first line of the code in...Ch. 3.3 - Prob. 20STQCh. 3.4 - Prob. 21STQCh. 3.4 - Prob. 22STQCh. 3.4 - Write code for a JOptionPane dialog that will ask...Ch. 3 - Write a fragment of code that will test whether an...Ch. 3 - Write a fragment of code that will change the...Ch. 3 - Suppose you are writing a program that asks the...Ch. 3 - Prob. 4ECh. 3 - Consider the following fragment of code: What is...Ch. 3 - We would like to assess a service charge for...Ch. 3 - What is the value of each of the following boolean...Ch. 3 - The following code fragment will not compile. Why?...Ch. 3 - Prob. 9ECh. 3 - Consider the boolean expression (2 5) (x 100))....Ch. 3 - Write a switch statement to convert a letter grade...Ch. 3 - Consider the previous question, but include + or ...Ch. 3 - Imagine a program that displays a menu of five...Ch. 3 - Repeat the previous exercise, but define an...Ch. 3 - Repeat Exercise 13, but use a multibranch if-else...Ch. 3 - Given that the int variable temp contains a...Ch. 3 - Write Java statements that create a yes-or-no...Ch. 3 - A number x is divisible by y if the remainder...Ch. 3 - Write a program to read in three nonnegative...Ch. 3 - Write a program that reads three strings from the...Ch. 3 - Write a program that reads a one-line sentence as...Ch. 3 - Write a program that allows the user to convert a...Ch. 3 - Write a program that inputs an integer. If the...Ch. 3 - Prob. 7PCh. 3 - Repeat Programming Project 5 of Chapter 2, but...Ch. 3 - Repeat any of the previous Practice Programs using...Ch. 3 - Suppose that we are working for an online service...Ch. 3 - Write a program that reads a string from the...Ch. 3 - Repeat the calorie-counting program described in...Ch. 3 - Repeat Programming Project 5 but in addition ask...Ch. 3 - Repeat Programming Project 11 in Chapter 2, but if...Ch. 3 - Write a program to play the rock-paper-scissor...Ch. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 8 in Chapter 1, but add...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What part of the computer actually runs programs?
Starting out with Visual C# (4th Edition)
What is the main advantage of parallel transfer over serial transfer of binary data?
Digital Fundamentals (11th Edition)
Once a class is declared, how many objects can be created from it? A) 1 B) 2 C) Many
Starting Out with C++: Early Objects (9th Edition)
Look at the following description of a problem domain: The bank offers the following types of accounts to its c...
Starting Out with Programming Logic and Design (4th Edition)
What is the output of the following loop? Comment on the code. (This is not the same as the previous exercise.)...
Absolute Java (6th Edition)
Minimum / Maximum Write a program that asks the user to enter two numbers. The program should use the condition...
Starting Out with C++: Early Objects
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write an application that asks a user to type an even number or the sentinel value 999 to stop. When the user types an even number, display the message “Good job!” and then ask for another input. When the user types an odd number, display an error message, "x is not an even number", and then ask for another input. When the user types the sentinel value 999, end the program.arrow_forwardThe following code is in Java:Assume the following declaration exists: enum Coffee { MEDIUM, DARK, DECAF } 1. How can the error in the following code be fixed? Coffee myCup = DARK; switch (myCup) { case Coffee.MEDIUM : System.out.println("Mild flavor."); break; case Coffee.DARK : System.out.println("Strong flavor."); break; case Coffee.DECAF : System.out.println("Won't keep you awake."); break; default: System.out.println("Never heard of it.");arrow_forwardAsk the user for a number of seconds. Display the number of minutes , seconds, and hours accordingly. 60 seconds in 1 minute 3,600 seconds in 1 hour 86,400 seconds in 1 day Please write a code in Java that results like test case examples.arrow_forward
- This is in JAVA. If the input is 5, what is the output? intx;x = scnr.nextInt();if (x < 10) {System.out.print("Live "); }else if (x < 20) {System.out.print("long ");}else if (x < 30) {System.out.print("and ");}System.out.print("prosper!"); A. Live B. Live long C. Live prosper! D. Error: The compiler will complain about a missing else statementarrow_forwardUSE JAVA Question/Prompt is in the picture attached, and use example outputs as a guide. second picture is the inventory used in prompt Please be precise. EXAMPLE OUTPUT 1 Welcome to the 1331 Giveaway! Would you like to take an item? [Y]es, [N]o, or [E]xitY |x|x|StuffedPython|x|CSalt||hAIrspray|x|x|x|x||x|x|x|JavaBeans|x||x|RustedMetal|SwiftShoes|x|x||FuRniture|x|x|GroovyGear|RadiantRuby| What item are you interested in taking?0 5 Location does not exist. What item are you interested in taking?0 4 You successfully took the CSalt! |x|x|StuffedPython|x|x||hAIrspray|x|x|x|x||x|x|x|JavaBeans|x||x|RustedMetal|SwiftShoes|x|x||FuRniture|x|x|GroovyGear|RadiantRuby| Would you like to take an item? [Y]es, [N]o, or [E]xitZ Please input ‘Y’, ‘N’, or ‘E’. Would you like to take an item? [Y]es, [N]o, or [E]xitEHave a good day! EXAMPLE OUTPUT 2 Welcome to the 1331 Giveaway! Would you like to take an item? [Y]es, [N]o, or [E]xitY…arrow_forwardWhat output is produced by the following code?int key = 1;switch (key + 1){case 1:System.out.println("Cake");break;case 2:System.out.println("Pie");break;case 3:System.out.println("Ice cream");case 4:System.out.println("Cookies");break; default: System.out.println("Diet time"); }arrow_forward
- What is the output produced by the following lines?System.out.println(2 + " " + 2);System.out.println(2 + 2);arrow_forwardWrite a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature. Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.arrow_forwardI ran this code but it was correct half way; public class DebugEight2 { publicstaticvoidmain(Stringargs[]) { int[] someNums = {4,17,22,8,35}; int tot =0, avg =0; int x; for(x =0; x < someNums.length; ++x) tot += someNums[x]; avg = tot / someNums.length; System.out.println("Sum is " + tot); System.out.println("Average is " + avg); } } Please see attached screenshot of the program and output and alsoarrow_forward
- Use the class provided, TestOverloadCall printMax to print the highest of 33 and 89Call printMax to print the highest of 55, 11, 99Submit, a print screen of the code and the output public class TestOverload {public static void main(String[] args) {//Call printMax to print the highest of 33 and 89//Call printMax to print the highest of 55, 11, 99}public static void printMax (int num1, int num2){if (num1 > num2)System.out.println("The highest is " + num1);elseSystem.out.println("The highest is " + num2);}//End of printMaxpublic static void printMax (int num1, int num2, int num3){if (num1 > num2 && num1 > num3)System.out.println("The highest is " + num1);else if (num2 > num1 && num2 > num3 )System.out.println("The highest is " + num2);elseSystem.out.println("The highest is " + num3);}//End of printMax}//End of TestOverloadarrow_forwardWhat is the output of the following code?double[] a = {1.1, 2.2, 3.3};System.out.println(a[0] + " " + a[1] + " " + a[2]);a[1] = a[2];System.out.println(a[0] + " " + a[1] + " " + a[2]);arrow_forwardThis is the question: only using the "while loop" Write a java program which asks the user to enter name and age and calls the following methods: printName(): Takes name as parameter and prints it 20 times using a while loop. printAge(): Takes age as parameter and prints all the numbers from 1 upto age. Write a java program that will print first 10 multiples of 3 in a single line.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY