Java How to Program, Early Objects (11th Global Edition) - Does NOT include MyLab Programming
11th Edition
ISBN: 9780134800301
Author: Harvey Deitel, Paul J. Deitel
Publisher: Pearson Global Edition
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2, Problem 3.4SRE
Explanation of Solution
Prompt a string in single line:
//define a class
class Main
{
//define main function
public static void main(String[] args)
{
//print the values
System.out...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Question
Task: Loop, input, and variable review: objects not required.
Write a Java program that can make change for a vending machine. Your program
should take two numbers as input, one for the amount charged and one for the money
given. You can assume both amounts are less than $10, and that the user will give more
money than the amount due.
Use the following U.S. coins: dollar, quarter, dime, nickel, penny. The program displays
the number of each kind of coin to give back. Try to design your program so that it
returns the fewest number of coins possible.
Output of a sample program run:
You bought something worth $1.25.
You paid $2.10.
Your change is:
0 dollar coins
3 quarters
1 dimes
0 nickels
0 pennies
Correct the following wrong statements.
In Java, once a variable is declared in a method as local variable, it will be visible and could be used in any other method in the program.
Chapter 2 Solutions
Java How to Program, Early Objects (11th Global Edition) - Does NOT include MyLab Programming
Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Prob. 1.7SRECh. 2 - State whether each of the following is true or...Ch. 2 - State whether each of the following is true or...Ch. 2 - State whether each of the following is true or...
Ch. 2 - State whether each of the following is true or...Ch. 2 - State whether each of the following is true or...Ch. 2 - Prob. 2.6SRECh. 2 - Write statements to accomplish each of the...Ch. 2 - Write statements to accomplish each of the...Ch. 2 - Write statements to accomplish each of the...Ch. 2 - Prob. 3.4SRECh. 2 - Prob. 3.5SRECh. 2 - Write statements to accomplish each of the...Ch. 2 - Prob. 4.1SRECh. 2 - Identify and correct the errors in each of the...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Write declarations, statements or comments that...Ch. 2 - Using the statements you wrote in Exercise 2.5,...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Fill in the blanks in each of the following...Ch. 2 - Prob. 1.4ECh. 2 - Fill in the blanks in each of the following...Ch. 2 - Write Java statements that accomplish each of the...Ch. 2 - Write Java statements that accomplish each of the...Ch. 2 - Write Java statements that accomplish each of the...Ch. 2 - Prob. 3.1ECh. 2 - State whether each of the following is true or...Ch. 2 - State whether each of the following is true or...Ch. 2 - State whether each of the following is true or...Ch. 2 - Assuming that x = 2 and y = 3, what does each of...Ch. 2 - Assuming that x = 2 and y = 3, what does each of...Ch. 2 - Assuming that x = 2 and y = 3, what does each of...Ch. 2 - Prob. 4.4ECh. 2 - Prob. 5.1ECh. 2 - Which of the following Java statements contain...Ch. 2 - Prob. 5.3ECh. 2 - Which of the following Java statements contain...Ch. 2 - Given that y=ax3+7, which of the following are...Ch. 2 - Given that y=ax3+7, which of the following are...Ch. 2 - Given that y=ax3+7, which of the following are...Ch. 2 - Given that y=ax3+7, which of the following are...Ch. 2 - Given that y=ax3+7, which of the following are...Ch. 2 - Given that y=ax3+7, which of the following are...Ch. 2 - State the order of evaluation of the operators in...Ch. 2 - Prob. 7.2ECh. 2 - State the order of evaluation of the operators in...Ch. 2 - Display the message "Enter an integer: ", leaving...Ch. 2 - Assign the product of variables b and c to the int...Ch. 2 - Use a comment to state that a program performs a...Ch. 2 - Prob. 9.1ECh. 2 - (Comparing Integers) Write an application that...Ch. 2 - Which of the following Java statements contain...Ch. 2 - Given that y = ax3 + 7, which of the following are...Ch. 2 - State the order of evaluation of the operators in...Ch. 2 - What does the following code print?...Ch. 2 - What does the following code print?...Ch. 2 - What does the following code print?...Ch. 2 - What does the following code print?...Ch. 2 - (Largest and Smallest Integers) Write an...Ch. 2 - (Odd or Even) Write an application that reads an...Ch. 2 - Write an application that reads two integers,...Ch. 2 - Write an application that displays a checkerboard...Ch. 2 - Circumference and Area of a Circle) Heres a peek...Ch. 2 - (Integer Value of a Character) Heres another peek...Ch. 2 - (Separating the Digits in an Integer) Write an...Ch. 2 - Prob. 25.1ECh. 2 - Prob. 26.1ECh. 2 - (Body Mass Index Calculator) We introduced the...Ch. 2 - (World Population Growth Calculator) Search the...
Knowledge Booster
Similar questions
- Methods Java Write the appropriate method headings using the provided method name for the following processes: 1.) Given the radius of a circle, print the area of a circle - printArea. 2.) Accept an integer, compute for the square of the number and return the String equivalent of the square of the number - makeString 3.) Calculate and return the sum of two decimal numbers - getSum. 4.) Given a student’s name and three test scores (of type int), print the student’s name and average test score - printStudentDetails. 5) Compute and return the average speed of a car, given the distance traveled (as type double) and traveling time (in hours and minutes, both of type int) - getAverageSpeed. Âarrow_forwardPart 4: Methods The following is Java pseudocode. For this exercise, you can assume the input function provides an appropriate integer value. Line numbers are provided on the left. System.out.print will print the information to the same line. System.out.println will print the information and then go to the next line. // is a comment. Do not worry about public static. Code execution starts with the main method. For each method used, make sure to provide a separate table showing what the values are and how they change (i.e. tracing through the code). All variables passed in have values. Don’t worry about showing how the input() method works. 7 public static int test1(int x1, int x2){ 8 9 if(x1==0){ 10 x1=10; 11 } 12 if(x2==0){ 13 x2=10 14 } 15 16 return x1*x2; 17 } 18 19 public static int test2(int x2, int x1){ 20 return x2-x1; 21 } 22 public static int input(){…arrow_forwardTask 1: Write a Java Program which will determine whether a number is even or odd. Take the number as an input from the user. Perform the checking in a separate method other than main method. Print the results in main method. Task 2: Find out the area of three geometric shape: Circle, Triangle, Square. Give the user an option to select which geometric shape's area he/she wants to find out. Based on the choice take necessary input and find out the result. Use different area method for each geometric shape. Print the result in main method.arrow_forward
- Using Javaarrow_forward7- Read about the format() string method , list the reference that you referred to and give examples that verify that the method is working as explained in the reference. 8- Read about the strftime() method , list the reference that you referred to and give examples that verify that the method is working as explained in the reference. 9- Write a program that finds out the used python versionarrow_forwardCreate a Java program that does the following: 1. Ask the user to enter a retail price 2. Ask the user to enter a discount percentage (you can decide the format - 20 or .20) 3. Code a new method, calcSalePrice that accepts the retail price and discount percentage as parameters, and returns the sale price using the formula: retail price - (retail price * discount percentage) 4. Create a variable that will hold the return value from the method. 5. Assign the calcSalePrice return value to the variable, and then print out the sale price from the main method.arrow_forward
- Correct the following wrong statements. 1. do … while repetition statement gives full control on the code block to be repeated.2. In Java, once a variable is declared in a method as local variable, it will be visible and couldbe used in any other method in the program.3. All binary operators except for the assignment operators are evaluated as user intention.4. In Java, byte code is translated to native code by java compiler.5. Each row in a single dimensional array could be dealt with as 2-dimensional array.6. The indices of elements in a single dimensional array named arrElem are from 1 toarrElements[]length.7. In Java, method overloading means that a program may contain more than one methodwith same signatures. Each column in a 2D array could be dealt with as 1D array.8. The following statement creates and initializes the 2-dimensional array values:short values[][] = {10, 20, 30, 40, 50};9. A ragged 2D array is a 2D array in which each row may contain the same number ofcolumns.10.…arrow_forwardPROGRAMMING LANGUAGE: Javaarrow_forwardFill the box with the correct answerarrow_forward
- Java code pleasearrow_forwardObjective: Create a program that invokes static methods and uses static variables. Note: Please see attached pictures. Also please send a screenshot of the code (Java programming language only)arrow_forwardJAVA Notes: all program codes should be written with method/s separated from the main() structure. Use a separate code files for each. Programming Problems: 1. Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, otherwise return false. Also write a program to test your method. 2. Write a program that prompts the user to enter a sequence of characters and output the number of vowels and consonants separately. (use the method isVowel written in problem 1). 3. Write a program that output inflation rates for two successive years and whether the inflation rates are increasing or decreasing. Ask the user to input the current price of an item and its price, one year and two years ago. To calculate the inflation rate for a year, subtract the price of the item for that year and from the price of the item from one year ago and then divide the result by the price a year ago. Your program must contain a method to calculate the results. Use…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage