Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 5, Problem 5E
Consider a Java class that you could use to get an acceptable integer value from the user. An object of this class will have the attributes
- Minimum accepted value
- Maximum accepted value
- Prompt string
and the following method:
- getValue displays the prompt and reads a value using the class Scanner. If the value read is not within the allowed range, the method should display an error message and ask the user for a new value, repeating these actions until an acceptable value is entered. The method then returns the value read.
- a. Write preconditions and postconditions for the method getValue.
- b. Implement the class in Java.
- c. Write some Java statements that test the class.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Retail StoreSuppose you have been consulted by a retail shop around your area to build a simple calculator. The calculator must be able to perform arithmetic operations (+, -, *, /) on integers. The program receives an expression from the user. The expression is structured as follows: integer input followed by an operator and another integer input from user prior to displaying the final result.
Write a Java application that can perform the above expression. Create a method that takes two parameters and performs an arithmetic operation on the passed values. Your final output should consist of the expression and the result.
Computer programmin Java
Java
Chapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 5.1 - Consider the program in Listing 5.4 . Suppose you...Ch. 5.1 - Prob. 2STQCh. 5.1 - Prob. 3STQCh. 5.1 - Suppose every species in the world has a peculiar...Ch. 5.1 - Revise the definition of the method writeOutput in...Ch. 5.1 - Revise the definition of the method readInput in...Ch. 5.1 - Revise the definition of the method...Ch. 5.1 - What is the meaning of (int) that appears in the...Ch. 5.1 - Prob. 9STQCh. 5.1 - Define a method called getDensity that could be...
Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.2 - In Listing 5.12, we set the data for the object...Ch. 5.2 - Give preconditions and postconditions for the...Ch. 5.2 - What is an accessor method? What is a mutator...Ch. 5.2 - Give the complete definition of a class called...Ch. 5.2 - Prob. 17STQCh. 5.2 - In the definition of the method in Listing 5.15,...Ch. 5.2 - What is a well-encapsulated class definition?Ch. 5.2 - When should an instance variable in a class...Ch. 5.2 - Prob. 21STQCh. 5.2 - In a class definition, is anything private ever...Ch. 5.2 - In a class definition, is the body of any method...Ch. 5.3 - What is a reference type? Are class types...Ch. 5.3 - When comparing two quantities of a class type to...Ch. 5.3 - Prob. 26STQCh. 5.3 - Write a method definition for a method called...Ch. 5.3 - Given the class Species as defined in Listing...Ch. 5.3 - After correcting the program in the previous...Ch. 5.3 - What is the biggest difference between a parameter...Ch. 5.3 - Prob. 31STQCh. 5.3 - Write an equals method for the class Person...Ch. 5.4 - Rewrite the method drawFaceSansMouth in Listing...Ch. 5 - Design a class to represent a credit card. Think...Ch. 5 - Repeat Exercise 1 for a credit card account...Ch. 5 - Repeat Exercise 1 for a coin instead of a credit...Ch. 5 - Repeat Exercise 1 for a collection of coins...Ch. 5 - Consider a Java class that you could use to get an...Ch. 5 - Consider a class that keeps track of the sales of...Ch. 5 - Consider a class MotorBoat that represents...Ch. 5 - Prob. 8ECh. 5 - Prob. 9ECh. 5 - Prob. 10ECh. 5 - Write a program to answer questions like the...Ch. 5 - Define a class called Counter. An object of this...Ch. 5 - Prob. 3PCh. 5 - Define a Trivia class that contains information...Ch. 5 - Define a Beer class that contains the following...Ch. 5 - Write a grading program for an instructor whose...Ch. 5 - Add methods to the Person class from Self-Test...Ch. 5 - Create a class that represents a grade...Ch. 5 - Write a program that uses the Purchase class in...Ch. 5 - Write a program to answer questions like the...Ch. 5 - Consider a class that could be used to play a game...Ch. 5 - Consider a class BasketballGame that represents...Ch. 5 - Consider a class ConcertPromoter that records the...Ch. 5 - Prob. 9PPCh. 5 - Consider a class Movie that contains information...Ch. 5 - Repeat Programming Project 18 from Chapter 4, but...Ch. 5 - Prob. 12PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write a complete Java program that reads in a line of keyboard input containing two values of type int (separat...
Absolute Java (6th Edition)
Whats wrong with the following array declarations? int[] readings = new int[-1]; double[] measurements = new do...
Starting Out with Java: From Control Structures through Objects (6th Edition)
When working with a sequential access file, you can jump directly to any piece of data in the file without read...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Consider the following code (and assume that it is embedded in a complete and correct program and then run): ch...
Problem Solving with C++ (9th Edition)
Consider the following statement: A car has an engine. If this statement refers to classes, what is the aggrega...
Starting Out with Java: Early Objects (6th Edition)
(Two movable vertices and their distances) Write a program that displays two circles with radius 10 at location...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th 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
- Computer Science Write a Java program that calls a method from main and passes it two integer parameters called minValue and maxValue. The method should prompt the user to enter a number within the range of minValue and maxValue (inclusive), until the user provides a valid input. The method should return the value provided by the user, and the program should display what the user entered after the method is called.arrow_forwardtrue of false: a) The first step in any programming task is to start coding. b) The only places we would ever want to put a comment in our code are above a method and above a class.arrow_forwardThe language is C# Write a program named TestScoreList that accepts eight int values representing student test scores. Display each of the values along with a message that indicates how far it is from the average. An example of how the results should be output is as follows: Test # 0: 89 From average: 6 Test # 1: 78 From average: -5arrow_forward
- JAVAA7-Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. Demonstrate the class in a program by invoking the methods that return the number of vowels and consonants. Print the counts returned.arrow_forwardLab Task 04: Include the methods in the file KMP_Implementation.txt in a complete Java program that prompts for and reads a text string and then a text pattern to search for in the text. It then displays the result of the search. Sample program runs: Enter the text: ABABСАВАВАВСАВАВСАВАВСАВАВКККАВАВСАВАВ Enter the pattern to search for: ABABCABAB Pattern found at these text starting indexes: 0 Enter the text: A KFUPM STUDENT Enter the pattern to search for: KFE Pattern not in text. 7 12 17 29arrow_forwardJAVA Problem description:You are to write a program called Seasons that prompts the user for a month and day and displays the season in which that date occurs. For reference, we will use the following date cutoffs for the various seasons: Winter December 21 – March 19 Spring March 20th – June 20th Summer June 21st – September 20th Fall September 21st – December 20th Data Validation For this program, you'll write a specific method to perform data validation based on the month and day entered. More specifically: Month – the month entered must be a valid month of the year (January – December). Day – the day entered must be a valid day for that month: January, March, May, July, August, October, December have 1-31 days. April, June, September, November have 1-30 days. February has 1-28 days (do not worry about leap years) Required program decomposition String getMonth(Scanner console) This method is called from the main method and should prompt for the month as a string…arrow_forward
- Language/Type: Java classes Write a class of objects named Date that remembers information about a month and day. Ignore leap years and don't store the year in your object. You must include the following public methods: description constructs a new date representing the given month and day returns the number of days in the month stored by your date object returns the day returns the month advances the Date to the next day, wrapping to the next month and/or year if necessary returns a string representation such as "07/04" member name Date (m, d) daysInMonth() getDay() get Month() nextDay() toString() You should define the entire class including the class heading, the private fields, and the declarations and definitions of all the public methods and constructor.arrow_forwardWhich import statement should be included in the source code of a class so that the Math class is explicitly imported? Choose from the given choices. *arrow_forwardTrue or False: When passing multiple arguments to a method, the order in which the arguments are passed is not important.arrow_forward
- Part I: PrintVertical.java Write a program that will prompt the user to enter a sentence (string data), read that sentence into your program as a single string, and then finally process the string by calling the method specified below (vertical). You must process the sentence by calling the method rather than processing the string directly in your main method. Write a void method, vertical, which receives a string as a parameter and prints each letter of the string to the screen on separate lines. Example Execution (user input in green) Please enter a sentence: Hey there! Your sentence printed vertically is: H e t h e rarrow_forwardUsing JAVASCRIPT write an object prototype for a Person that has a name and age, has a printInfo method, and also has a method that increments the persons age by 1 each time the method is called. Create two people using the 'new' keyword, and print both of their infos and increment one persons age by 3 years. Use an arrow function for both methods */ // Create our Person Prototype // Use an arrow to create the printInfo method // Create another arrow function for the addAge method that takes a single parameter // Adding to the agearrow_forwardInteger userValue is read from input. Assume userValue is greater than 1000 and less than 99999. Assign tensDigit with userValue's tens place value. Ex: If the input is 15876, then the output is: The value in the tens place is: 7 2 3 public class ValueFinder { 4 5 6 7 8 9 10 11 12 13 GHE 14 15 16} public static void main(String[] args) { new Scanner(System.in); } Scanner scnr int userValue; int tensDigit; int tempVal; userValue = scnr.nextInt(); Your code goes here */ 11 System.out.println("The value in the tens place is: + tensDigit);arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY