Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 12MC
Which Scanner class method would you use to read a double as input?
- a. nextDouble
- b. getDouble
- c. readDouble
- d. None of these; you cannot read a double with the Scanner class
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Look at the image for the expected output. Use if class, scanner class, return class to do this program.
Look image for the valid user input.
Task 5: ScanningMoney.java
Write a program that reads User Input using the Scanner class. Your program should ask the user how many quarters,
nickels, dimes, and pennies they have, then display the total amount in dollars. This can be done in main method.
Expected Output
The highlighted text denotes text that you type into the console yourself. It is not printed by the program.
Due to floating point values being used your answer may have the trailing 1 or not.
----JGRASP exec: java ScanningMoney
Quarters: 4
Dimes: 3
Nickels: 2
Pennies: 1
You have $1.4100000000000001
----JGRASP: operation complete.
Why did we use the PrintStream and Scanner classes for file output and input, respectively?
A
They're the only classes available for file input and output.
B
They allow us to use the same input and output method call formats we used for keyboard input and display output.
C
Those are not classes we used for file input and output.
D
Only the PrintStream class can create a file that the Scanner class can read.
Chapter 2 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 2.1 - Prob. 2.1CPCh. 2.1 - When the program in Question 2.1 is saved to a...Ch. 2.1 - Complete the following program skeleton so it...Ch. 2.1 - On paper, write a program that will display your...Ch. 2.1 - Prob. 2.5CPCh. 2.1 - Every Java application program must have...Ch. 2.2 - The following program will not compile because the...Ch. 2.2 - Study the following program and show what it will...Ch. 2.2 - On paper, write a program that will display your...Ch. 2.3 - Examine the following program. // This program...
Ch. 2.3 - What will the following program display on the...Ch. 2.4 - Which of the following are illegal variable names...Ch. 2.4 - Prob. 2.13CPCh. 2.4 - Prob. 2.14CPCh. 2.4 - Prob. 2.15CPCh. 2.4 - A program declares a float variable named number,...Ch. 2.4 - Prob. 2.17CPCh. 2.4 - Prob. 2.18CPCh. 2.4 - Prob. 2.19CPCh. 2.4 - Prob. 2.20CPCh. 2.4 - What is wrong with the following statement? char...Ch. 2.5 - Prob. 2.22CPCh. 2.5 - Prob. 2.23CPCh. 2.6 - Write statements using combined assignment...Ch. 2.7 - The following declaration appears in a program:...Ch. 2.7 - The variable a is a float and the variable b is a...Ch. 2.9 - Write a statement that declares a String variable...Ch. 2.9 - Assume that stringLength is an int variable. Write...Ch. 2.9 - Prob. 2.29CPCh. 2.9 - Prob. 2.30CPCh. 2.9 - Prob. 2.31CPCh. 2.11 - Prob. 2.32CPCh. 2.11 - How are documentation comments different from...Ch. 2.14 - Prob. 2.34CPCh. 2.14 - Write code that will display each of the dialog...Ch. 2.14 - Write code that displays an input dialog asking...Ch. 2.14 - Prob. 2.37CPCh. 2 - Every complete statement ends with a __________....Ch. 2 - The following data 72 'A' Hello World 2.8712 are...Ch. 2 - A group of statements, such as the contents of a...Ch. 2 - Which of the following are not valid assignment...Ch. 2 - Which of the following are nor valid println...Ch. 2 - The negation operator is __________. a. unary b....Ch. 2 - This key word is used to declare a named constant....Ch. 2 - These characters mark the beginning of a...Ch. 2 - These characters mark the beginning of a...Ch. 2 - These characters mark the beginning of a...Ch. 2 - Which Scanner class method would you use to read a...Ch. 2 - Which Scanner class method would you use to read a...Ch. 2 - You can use this class to display dialog boxes. a....Ch. 2 - Prob. 14MCCh. 2 - Prob. 15MCCh. 2 - True or False: A left brace in a Java program is...Ch. 2 - True or False: A variable must be declared before...Ch. 2 - True or False: Variable names may begin with a...Ch. 2 - True or False: You cannot change the value of a...Ch. 2 - True or False: Comments that begin with / / can be...Ch. 2 - True or False: If one of an operators operands is...Ch. 2 - What will the following code segments print on the...Ch. 2 - int x = 0, y=2; x = y 4; System.out.println(x +...Ch. 2 - System.out.print(I am the incredible);...Ch. 2 - System.out.print(Be careful\n);...Ch. 2 - int a, x = 23; a = x % 2; System.out.println(x +...Ch. 2 - Find the Error There are a number of syntax errors...Ch. 2 - Show how the double variables temp, weight, and...Ch. 2 - Prob. 2AWCh. 2 - Write assignment statements that perform the...Ch. 2 - Assume the variables result, w, x, y, and z are...Ch. 2 - Prob. 5AWCh. 2 - Modify the following program so it prints two...Ch. 2 - What will the following code output? int apples =...Ch. 2 - What will the following code output? double d =...Ch. 2 - What will the following code output? String...Ch. 2 - What will the following code output? String...Ch. 2 - Convert the following pseudocode to Java code. Be...Ch. 2 - Prob. 12AWCh. 2 - Write the code to set up all the necessary objects...Ch. 2 - Prob. 14AWCh. 2 - A program has a float variable named total and a...Ch. 2 - Is the following comment a single-line style...Ch. 2 - Is the following comment a single-line style...Ch. 2 - Describe what the phrase self-documenting program...Ch. 2 - Prob. 4SACh. 2 - Prob. 5SACh. 2 - Prob. 6SACh. 2 - Prob. 7SACh. 2 - Prob. 8SACh. 2 - Briefly describe the difference between variable...Ch. 2 - What is the difference between comments that start...Ch. 2 - Briefly describe what programming style means. Why...Ch. 2 - Assume that a program uses the named constant PI...Ch. 2 - Assume the file Sales Average, java is a Java...Ch. 2 - Prob. 14SACh. 2 - Name, Age, and Annual Income Write a program that...Ch. 2 - Name and Initials Write a program that has the...Ch. 2 - Personal Information Write a program that displays...Ch. 2 - Star Pattern Write a program that displays the...Ch. 2 - Sales Prediction The East Coast sales division of...Ch. 2 - Land Calculation One acre of land is equivalent to...Ch. 2 - Sales Tax Write a program that will ask the user...Ch. 2 - Cookie Calories A bag of cookies holds 40 cookies....Ch. 2 - Miles-per-Gallon A cars miles-per-gallon (MPG) can...Ch. 2 - Test Average Write a program that asks the user to...Ch. 2 - Circuit Board Profit An electronics company sells...Ch. 2 - Prob. 12PCCh. 2 - Restaurant Bill Write a program that computes the...Ch. 2 - Male and Female Percentages Write a program that...Ch. 2 - Stock Commission Kathryn bought 600 shares of...Ch. 2 - Energy Drink Consumption A soft drink company...Ch. 2 - Ingredient Adjuster A cookie recipe calls for the...Ch. 2 - Word Game Write a program that plays a word game...Ch. 2 - Stock Transaction Program Last month Joe purchased...Ch. 2 - Planting Grapevines A vineyard owner is planting...Ch. 2 - Compound Interest When a bank account pays...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Does the following program represent an algorithm in the strict sense? Why or why not? Count = 0 while (Count !...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
In one approach to identifying the classes in a problem, the programmer identifies the _______ in a description...
Starting Out with Python (4th Edition)
How would the number 479 be stored in a text file? (Show the character and ASCII code representation.)
Starting Out with C++: Early Objects (9th Edition)
Letter Frequencies The letter e is the most frequently used letter in English prose, and the letter z is the le...
Starting Out with C++: Early Objects
Look at the following code, which is the first line of a class definition. What is the name of the superclass? ...
Starting Out with Python (3rd Edition)
A palindrome is a string that reads the same forward and backward, such as radar. Write a static recursive meth...
Java: An Introduction to Problem Solving and Programming (8th Edition)
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
- Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs Yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: Yes Ex: If the input is: 42,000 or 1995! the output is: No Hint: Use a loop and the Character.isDigit() function.arrow_forwardWrite an import statement that makes the Scanner class available to yourprogram or other class.arrow_forwardi need the code in java and and use text file to get the data from it and save the data on itarrow_forward
- Please write a program which prints out the following story. The user gives a name and a year, which should be inserted into the printout. Please type in a name: Mary Please type in a year: 1572 Mary is a valiant knight, born in the year 1572. One morning Mary woke up to an awful racket: a dragon was approaching the village. Only Mary could save the village's residents. The story should change according to the input given by the user. Sample output 1arrow_forwardPlease include a gui for the encryption and decryption java code. Example of the gui in the photos Java encryption and decryption code below import java.util.*; public class Main { //Inputs a one character string and returns True if the character is a letter (i.e. a to z or A to Z). Returns false if it is not. A function to check that the password or encryption key is valid. public static boolean isALetter(char letter){ if( (letter >= 'a' && letter = 'A' && letter =-32767 && encryptKeyarrow_forwardimport java.util.Scanner; /** * Question 2 - This program allows money to be input in one currency and then its converted to a second * currency. The user must input the amount of money and 2 currency codes which should be USD (for dollar), * GBP (pound) and EUR (Euro). If either of the currency codes are incorrect, the program should display an error message * and end. If the user types in two currency codes that are the same, they should be trapped in a loop until the codes are different. * The money should be converted to the other currancy and the value of the monies in both currencies should be displayed. * * Student Number: * * Student Name: * */public class ChangeCurrency { public static void main(String[] args) { Scanner scan = new Scanner(System.in); double money = 0, convertedMoney = 0; String firstCurrency = "", secondCurrency = ""; //The following are the exchance rates so euroToDollar = 1.14 means 1 euro is equal to…arrow_forward
- Please be aware that your score will be zero if your codes are the same as others'. Do not cheat. 填空题 The JDK command to compile a class in the file Test.java is The main method header is written as Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read a double type number? What is y after the following statement is executed? x = -1; y = (x < 0) ? 10: -10; What is the index variable for the element at the first row and first column in array a? 1. 2. 3. 4. 5.arrow_forwardin C++ here is my code that will ask to answer the multiplication fo teo random numbers when the user enter the right answer, it says very good then it keeps asking the next random set of numbers multiplication answer, till the user answer incorrectly, it says please try again then it exists, i want the program not to exit but to say please try again till the user puts the right answer then it says very good and does to the next question ...etc... can you implemnt what i just asked ? and thank you code: #include<iostream>// to be able to use input output stream#include<math.h>//h is a header file in the standard library of the C programming language designed for basic mathematical operations#include<cstdlib>//Converts a string into a long integer, also carry the library for definition of memory allocation and random processe#include<ctime>//converts the given time since epoch to a calendar local time and then to a character representation.using namespace…arrow_forwardThe Body Mass Index – BMI is a parameter used to measure the health status of an individual. Various BMI values depicts how healthy or otherwise a person is. Mathematically BMI = WEIGHT/ HIEGHT * HEIGHT Write a java program using either JOptionPane or Scanner to collect the following values of an individual: 1.a. Namea b. Weight c. Height 2. Compute the BMI of that individual 3. Make the following decisions if: a. BMI < 18.5 is under weight b. BMI >=18.5 but <25 considerably healthy c. BMI >=25 but <30 overweight d. BMI >= 30 but <40 Obesity e. BMI >= 40 Morbid Obesity 4. Display the results of the individual 5. Explain your answerarrow_forward
- use java : write an application that reads English-Language phrase and encodes it into morse code. also write an application that reads a phrase in morse code and converts it into the English-Language equivalent . Use one blank between each Morse-code letter and three blanks between each Morse-coded word.arrow_forwardJAVA Program ASAP Please modify this program with further modifications which are below so it passes the test cases in Hypergrade. I have provided the failed test cases. 1) For test cases 2 and 3 for the outputted numbers there needs to be commas and there needs to be nothing after that 2)for test case 1 outputted numbers there needs to be nothing after that, 3) for test 4 when file is not found there needs to be nothing after that 4) and for test case 5 and 7 afer a file is not found it needs to display Please re-enter the file name or type QUIT to exit: so you input the text file and displays the numbers. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.InputMismatchException;import java.util.Scanner;public class FileSorting { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please…arrow_forwardPart 2 - OddOrEven ClassIn bluej. Write a program that prompts the user to enter an integer. The program should display “The input is odd" to the screen if the input is odd and displays “The input is even" to the screen if the input is even. Hint: Consider using the mod (%) operator.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Files & File Systems: Crash Course Computer Science #20; Author: CrashCourse;https://www.youtube.com/watch?v=KN8YgJnShPM;License: Standard YouTube License, CC-BY
UNIX Programming (Part - 10) The File System (Directories and Files Names); Author: ITUTEES;https://www.youtube.com/watch?v=K35faWBhzrw;License: Standard Youtube License