Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 7.2, Problem 8STQ

Explanation of Solution

Modified method definition of “displayResults” in Listing 7.4:

/* Modified "displayResults" method */

public void displayResults( )

{

    //Display statement for average sales per associate

    System.out.print("Average sales per associate is ");

/* Display the amount of sales by calling method "writeln" in "DollarFormat" class */

    DollarFormat.writeln(averageSales);

    //Display statement for highest sales figure

    System.out.print("The highest sales figure is ");

/* Display the highest by calling method "writeln" in "DollarFormat" class */

    DollarFormat.writeln(highestSales);

    //For next line

    System.out.println( );

    //Display statement for highest sales

System.out.println("The following had the highest sales:");

    //Compute highest sales by using "for" loop

    for (int i = 1; i <= numberOfAssociates; i++)

    {

        //Store the next sales

        double nextSales = team[i].getSales( );

        //Check condition

        if (nextSales == highestSales)

        {

/* Call "writeOutput" method to display associate name and sales amount */

            team[i].writeOutput( );

/* Display above average sales by calling "write" method in "DollarFormat" class */

DollarFormat.write(nextSales - averageSales);

System.out.println(" above the average.");

            System.out.println( );

        }

    }

    //Display given statement

    System.out.println("The rest performed as follows:");

    /* Compute rest sales using "for" loop */

    for (int i = 1; i <= numberOfAssociates; i++)

    {

        //Compute next sales

        double nextSales = team[i].getSales( );

/* If the values in getSales is not equal to highest sales, then */

        if (team[i].getSales( ) != highestSales)

        {

            /* Call "writeOutput" method */

            team[i].writeOutput( );

/* If the value of "nextSales" is greater than or equal to "averageSales", then */

            if (nextSales >= averageSales)

            {

/* Display above average by calling "write" method in "DollarFormat" class */

DollarFormat.write(nextSales - averageSales);

                //Display statement

System.out.println(" above the average.");

            }

            //Otherwise

            else

            {

/* Display below average by calling "write" method in "DollarFormat" class */

DollarFormat.write(averageSales - nextSales);

                //Display statement

System.out.println(" below the average.");

            }

            //For next line

            System.out.println( );

        }

    }

}

Explanation:

The “displayResults” method is used to display the sales reports on the screen.

  • • Display statement for average sales per associate.
  • • Display the amount of sales with dollar symbol by calling method “writeln()” in “DollarFormat” class.
  • • Display statement for highest sales figure.
  • • Display the highest sales with dollar symbol by calling method “writeln()” in “DollarFormat” class.
  • • Display statement for highest sales.
  • • Compute highest sales by using “for” loop.
    • ○ Compute the value of “nextSales” by using method “getSales()”.
    • ○ Check condition. If the value of “nextSales” is equal to “highestSales”, then call “writeOutput()” method in “salesAssociate” class to displays associate name and sales amount.
    • ○ Display above average sales with dollar symbol by calling method “write()” in “DollarFormat” class.
  • • Compute the rest of the sales using “for” loop.
    • ○ Compute the value of “nextSales” by using method “getSales()”.
    • ○ Check condition. If the values in “getSales()” is not equal to highest sales, then call “writeOutput()” method in “salesAssociate” class to prints the name and sales amount.
      • ■ If the value of “nextSales” is greater than or equal to “averageSales”, then display above average value by calling “write()” method in “DollarFormat” class.
      • ■ Otherwise, display below average value by calling “write()” method in “DollarFormat” class.

Completed code for method definition of “displayResults”:

The complete executable code after modifying the definition of “displayResults” method is given below:

Modified “SalesReporter.java”

//Import required package

import java.util.Scanner;

//Define "SalesReporter" class

public class SalesReporter

{

  //Declare required variables

    private double highestSales;

    private double averageSales;

    private SalesAssociate[] team; 

    private int numberOfAssociates;

/* Method definition for read the number of sales associates and data for each one */  

    public void getData( )

    {

        //Create object for scanner class

        Scanner keyboard = new Scanner(System.in);

        //Read the number of scales associates

System.out.println("Enter number of sales associates:");

        numberOfAssociates = keyboard.nextInt( );

        //Create object for "SalesAssociate" class

team = new SalesAssociate[numberOfAssociates + 1];

        //Read data for each sales associates

        for (int i = 1; i <= numberOfAssociates; i++)

        {

            team[i] = new SalesAssociate( );

System.out.println("Enter data for associate " + i);

            team[i].readInput( );

            System.out.println( );

        }

    }

/* Method definition for computes the average and highest sales figures */

    public void computeStats( )

    {

        double nextSales = team[1].getSales( );

        highestSales = nextSales;

        double sum = nextSales;

        for (int i = 2; i <= numberOfAssociates; i++)

        {

            nextSales = team[i].getSales( );

            sum = sum + nextSales;

            if (nextSales > highestSales)

highestSales = nextSales; //highest sales so far.

        }

        averageSales = sum / numberOfAssociates;

    }

    /* Modified "displayResults" method */

    public void displayResults( )

    {

//Display statement for average sales per associate

System...

Blurred answer
Students have asked these similar questions
Answer all of the questions with steps by step explanation to every question.
W Go Tools Window Help mac283_quiz3_fall2025.pdf Page 2 of 2 @ Q Q Û • ¨ ® - Qy Search X 00 01 11 10 0 1 1 1 0 1 1 1 1 1 A ABC 88% Problem 3. Draw the combinational circuit that directly implements the Boolean expression: F(x, y, z) = xyz + (y²+z) Problem 4. Find the truth table that describes the following circuit. y- z - X Problem 5. a) Describe how a decoder works and indicate typical inputs and outputs. b) How many inputs does a decoder have if it has 64 outputs? NOV 6 M tv♫ zoom
CPS 2390 Extra Credit Assignment For each problem, choose the best answer and explain how you arrived at your answer. (15 points each.) 1.If control is redirected to location x4444 after the execution of the following instructions, what should have been the relationship between R1 and R2 before these instructions were executed? Address Instruction x4400 1001100010111111 x4401 0001100100100001 x4402 0001100001000100 x4403 0000100001000000 A. R1 R2 (R1 was greater than R2) B. R1 R2 (R2 was greater than R1) C. R1 R2 (R1 and R2 were equal) = D. Cannot be determined with the given information. 2. If the value stored in RO is 5 at the end of the execution of the following instructions, what can be inferred about R5? Address x3000 Instruction 0101000000100000 x3001 0101111111100000 x3002 0001110111100001 x3003 0101100101000110 x3004 0000010000000001 x3005 0001000000100001 x3006 0001110110000110 x3007 0001111111100001 x3008 0001001111111000 x3009 0000100111111000 x300A 0101111111100000 A. The…

Chapter 7 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
The thick saw blade can be used as a broach or not.

Degarmo's Materials And Processes In Manufacturing

An exception is an event which takes place during the execution of a program. It interrupts the flow of the pro...

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY