Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 7.2, Problem 8STQ
Rewrite the method displayResults of the program SalesReporter (Listing 7.4) so that it uses the methods in the class DollarFormat (Listing 6.14 of Chapter 6) to display the dollar amounts in the correct format for dollars and cents.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Please write in JAVA
In the Print class, implement a static method named printNumbers that will print out numbers in brackets, formatted as [1][2][3], and so on. The method should accept two integer parameters: howMany and lineLength. The signature of the method should be “public static void printNumbers(int howMany, int lineLength)”. The method should print numbers from 1 to howMany in the previous format, but it should not output more than lineLength characters on any one line. It should not start a [ unless it can fit the corresponding ] in the same line. Some sample inputs and expected output is shown below.
Implement the main method below in a class called Grade. The program should read integer points (use the Scanner class) and print the grade (“A”, “B”, “C”, “D”, or “F”) based on the final score associated with a student. Grades are classified as follows:
Number of Points
Final Grade
Greater than or equal to 90
A
Between 80 (inclusive) and 90 (exclusive)
B
Between 70 (inclusive) and 80 (exclusive)
C
Between 60 (inclusive) and 70 (exclusive)
D
Less than 60
F
Restrictions/Assumptions
Use the message “Enter final score” to prompt the user to enter the number of points.
Use the Scanner class to read the number of points, i.e., Scanner sc = new Scanner(System.in);
Use System.out.println(...) to print the final grade.
Assume that the user correctly enters an integer score.
Start with this code:
import java.util.Scanner;
public class Grade {
public static void main(String[] args) {
For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac)
Java Do exercise 9.1 in the book (page 362, or page 384 of the Comprehensive Version of the book)
Also add a method named getDiagonal which computes and returns the diagonal of the rectangle. For example the distance from the top left corner to the bottom right corner. Or equivalently the distance from the top right corner to the bottom left corner.
Call this method and display it's output in your test program. for the two Rectangle objects.
Here is exercise 9.1 from the book:
(The Rectangle class) Following the example of the Circle class in Section 9.2,design a class named Rectangle to represent a rectangle. The class contains:- Two double data fields named width and height that specify the width andheight of the rectangle. The default values are 1 for both width and height.- A no-arg constructor that creates a default rectangle.- A constructor that creates a rectangle with the specified width and height.- A method named getArea() that returns the area of this rectangle.- A method…
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The method getValueFromFile is public and returns an int. It accepts no arguments. The method is capable of thr...
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
In the findFirst method, the loop's condition repeatedly asks the flies collection how many files it is storing...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
What is the purpose of the Application classs abstract start method?
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Which built-in function can be used to read input that has been typed on the keyboard? a. input () b. get input...
Starting Out with Python (4th Edition)
Write an SQL query to list each customer who bought at least one product that belongs to product line Basic in ...
Modern Database Management (12th Edition)
TeamLeader Class In a particular factory, a team leader is an hourly paid productionworker that leads a small t...
Starting out with Visual C# (4th 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
- Create a class with a method. The method has to decide whether a given year is a leap year or not. Note- A year is a leap year if: • It has an extra day i.e. 366 instead of 365. It occurs in every 4 year e.g. 2008, 2012 are leap years. For every 100 years a special rule applies-1900 is not a leap year but 2000 is a leap year. In those cases, we need to check whether it is divisible by 400 or not. > > ClassAssignmentEx2 ©LeapYearDecider javaclassnotes.assignments javaclassnotes.assignments ClassAssignmentEx2() LeapYearDecider() main(String):void A isLeapYear(int):booleanarrow_forwardThe following technique is used in a game of chess: canMoveTo(int x, int y), boolean. A method in the Piece class returns if the piece may travel to position (x, y). Describe how you would put this method to the test.arrow_forwardThe following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a method named spending that accepts two parameters: a Scanner for the console, and a String for a single person's name, and prints the appropriate information about that person's bills. Your method could be called twice (once for John and once for Jane) to replicate the original code's behavior.arrow_forward
- All coding is done in Java, using IntelliJ Idea. 3. Charge Account Validation Create a class with a method that accepts a charge account number as its argument. The method should determine whether the number is valid by comparing it to the following list of valid charge account numbers: 5658845 4520125 7895122 8777541 8451277 1302850 8080152 4562555 5552012 5050552 7825877 1250255 1005231 6545231 3852085 7576651 7881200 4581002 These numbers snould be stored in an array or an ArrayList Object. Prompt the user to choose search methodology between sequential/linear search, and binary search before the search is performed. Have the search locate the number passed as an argument. If the number is in the array, the method should return true, indicating the number is valid. If the number is not…arrow_forwardIn this assignment, you will need to design and implement a class Country (Country.java) that stores the name of the country, its population, and its area. Then write a program (LargestCountry.java) that reads countries from a “coutrydata.txt” and prints • The country with the largest area. • The country with the largest population. • The country with the largest population density (people per square mile). To make it concrete, the followings are the suggested tasks you need to perform: 1.1 Country Class In the first file Country.java, create a class named Country that models a country. It should contain at least the followings (However, you can add any other methods if you like): • Private instance variables name, population, and area; • A constructor takes all three inputs (the name, population and area); • Three getter methods to return each of three instance variables (accessor method); • One getter method to return country population density (accessor method); • Three setter…arrow_forwardAdd a method called multiplesOfFive to the Exercise class. The method must have a void return type and take a single int parameter called limit. In the body of the method, write a while loop that prints out all multiples of 5 between 10 and limit (inclusive) on a single line. For instance, if the value of limit were 15 then the method will print: 10 15 You can use the printEvenNumbers method that is already in the Exercise class as an example to help you work out how to complete this method. In the main method of the Main class, add a call on the Exercise object to your multiplesOfFive method that prints the multiples of 5 between 10 and 25. Add a method called sum to the Exercise class. The method must have a void return type and take no parameters. In the body of the method, write a while loop to sum the values 1 to 10 and print the sum once the loop has finished. In the main method of the Main class, add a call on the Exercise object to your sum method. Check that it prints: 55 Add…arrow_forward
- Write a program that simulates the Magic 8 Ball game. The class should have a method that returns an answer at random. Test your class by outputting the answer several times.arrow_forwardJAVA HELP PLEASE! Write a class Rectangle that has only the following public methods (you can add other non-public methods if you think you need them): Write a constructor that creates a rectangle using the x, y coordinates of its lower left corner, its width and its height (the parameters must be in that order). Creating a rectangle with non-positive width or height should not be allowed; throw an IllegalArgumentException for those cases. The values of x and y are allowed to be negative. Write a method overlap(Rectangle other). This method should return true if this rectangle overlaps with other, false otherwise. Rectangles that touch each other are not considered to be overlapping. Write a method toString that returns a String. The string should be formatted exactly as:“x:2, y:3, w:4, h:5”without the quotation marks and replacing the numbers with the actual attribute values of the object. A class called Rectangle exists in Java already. You are not allowed to use this class in any…arrow_forwardHere is _The output of first method should be that they are not equal. And the output of the second method should be that they are equal. Partial code is given below to help you complete this question. You can ignore this entirely and write your...arrow_forward
- In java create a method long-isogram: determine the longest isogram in the paragraph. An isogram is a word that has no repeating letters.(Differences between uppercase and lowercase letters are ignored.) For example, “computer” is an isogram. The word“science” is not. If there happens to be more than one such longest isogram, then the first one in the paragraph can bechosen. Make certain to exclude any punctuation marks from your determination (for example, when the word appears atthe end of a sentence or contains an apostrophe). For example, the isogram “Kim’s” should be considered four characterslong, with the apostrophe ignored. Return the longest isogram on one line and its length on a second line whencommunicating back to the client. The method should accept a list of strings where each string is line of the paragraph The method should be public static String long_isogram(List<String> par){}arrow_forwardWrite a method orderFood() for the class Food that simulates ordering food. The method takes an integer as argument, which indicates the number of portions that are ordered. It then prints out a string showing the number of portions and the type of food ordered. The string needs to have the format as shown in the examples below. Pythonarrow_forwardAdd another public method dblValue() to the Fraction class which returns the double precision approximation value of the fraction. That is, the floating point result of actually dividing numerator by denominator. N.B. this method does not do any display itself, but can be called by a client program to be used in an output statement. Eg: if a client has a fraction frac that represents 1 / 2,then a method call to frac.dblValue() should return the double number 0.5.Use the client program to test this functionality; i.e. provide an outputstatement to display the double value of a fraction. import java.util.ArrayList;import java.util.Scanner; //Define the class Fractionclass Fraction{private int n, d;public Fraction(){//Initialize the valuesthis.n = this.d = 0;}public Fraction(int n, int d){//Initialize the variablesthis.n = n;this.d = d;}//Define the getter function getNum() that returns the numeratorpublic int getNum(){//Returns numeratorreturn n;}//Define the getter function getDen()…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY