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
2) You have learned in class the major steps that occur when a laptop requests a webpage after connecting to a network. In this assignment, you will apply that knowledge to another scenario: opening and playing a YouTube video that resides in Google's data-center infrastructure. Explain, in as much detail as you can, all the steps involved from your device's initial connection to the home/university network, to DNS resolution, routing across multiple networks, reaching Google's servers, and finally receiving the video data. To support your explanation, use tools such as ipconfig, nslookup, and tracert on your own computer, as well as any online IP-lookup tools of your choice. For each stage, include relevant information such as IP addresses, MAC addresses, router hops, and any other details you can gather. You are not expected to find every piece of information, but be as comprehensive as possible based on what you have learned in class, and justify your reasoning with screenshots from…
Please no use of AI
help me with this project. provide what I should put on each slide (words, example images, etc); example Slide 1: Intro. here are the directions: Submit a report that includes the source code, compiled code, description of the algorithm(s) implemented, data structures used, implementation details including time complexity analysis, sample inputs/outputs, and a conclusion section.

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