
Concept explainers
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...
Want to see the full answer?
Check out a sample textbook solution
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Degarmo's Materials And Processes In Manufacturing
Starting Out with C++ from Control Structures to Objects (9th Edition)
Electric Circuits. (11th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Management Information Systems: Managing The Digital Firm (16th Edition)
- Need help writing code to answer this question in Python! (image attached)arrow_forwardNeed help with python code! How do I simplify my code for a beginner to understand, simple fixed format and centering? Such as: print(f"As an int variable: {age_int:^7}") print(f"In numeric binary: {age_int:^7b}") My Code:name = input("Enter your name: ")print(f"In text name is: {' '.join(name)}")decimal_values = []binary_values = []for letter in name: ascii_val = ord(letter) binary_val = format(ascii_val, '08b') decimal_values.append(str(ascii_val)) binary_values.append(binary_val)# Loop through each letter:print(f"In ASCII decimal: {' '.join(decimal_values)}")print(f"In ASCII binary: {' '.join(binary_values)}")# Ageage_str = input("Enter your age: ")age_int = int(age_str)print(f"As a string \"{age_str}\": {' '.join(age_str)}")age_decimal_values = []age_binary_values = []for digit in age_str: ascii_val = ord(digit) binary_val = format(ascii_val, '07b') age_decimal_values.append(str(ascii_val)) age_binary_values.append(binary_val)print(f"In ASCII decimal: {'…arrow_forwardDon't use chatgpt or any other AIarrow_forward
- Don't use chatgpt or any other AIarrow_forwardGiven a relation schema R = (A, B, C, D, E,G) with a set of functional dependencies F {ABCD BC → DE B→ D D→ A}. (a) Show that R is not in BCNF using the functional dependency A → BCD. (b) Show that AG is a superkey for R (c) Compute a canonical cover Fc for the set of functional dependencies F. Show your work. (d) Give a 3NF decomposition of R based on the canonical cover found in (c). Show your work. (e) Give a BCNF decomposition of R using F. Show your work.arrow_forwardThe following entity-relationship (ER) diagram models a database that helps car deal- ers maintain records of customers and cars in their inventory. Construct a relational database schema from the ER diagram. Your set of schemas should include primary-key and foreign-key constraints and you should ensure there are no redundant schemas. has_model model modelID name vehicle has_vehicle VIN dealer_ID brand name has_available_option has_option has_dealer options options_ID specification dealer dealer ID name customer_ID owned_by customer customer ID namearrow_forward
- A relation schema R = (A, B, C, D, E) with a set of functional dependencies F= {D A CAB} is decomposed into R₁ = (A, B, C) and R2 = (C, D, E). (a) Is this a lossless-join decomposition? Why or why not? (b) Is the decomposition dependency preserving? Why or why not?arrow_forwardNo chatgpt pleasearrow_forwardPlease help draw alu diagraarrow_forward
- 1. Level the resources (R) for the following network. Show exactly which activity is being moved at each cycle and how many days it is being moved. Show all cycles required to utilize the free float and the back float. B H 3 3 L 2 0-0-0 A C F G K N P Q T 0 3 2 2 1 2-2-2 7R 8R 4R 6R 4R 2R 5R 4R D 1 2R 2 M 000 4R 2 4R 1 2 3 4 B5 B BE B 5 5 7 D 2003 C NO C MBSCM В H 5 2 F 7 7 8 SH2F80 5 Н Н 6 7 7L3G4+ 6H2G4 J 4 4 14 8 L K 00 36 9 10 11 12 13 14 15 P 2 Z+ N N 4 4 Z t 2334 4 Σ + M M 4 +arrow_forward2. Perform resource allocation for the following project. Resource limits are 6 labors and 2 helpers. Legend: Activity Dur Resources G H 2 3 2L 1H 2L OH A 1 3L 1H + B D F J K 3 4 6 2 4 4L 2H 3L OH 4L 1H 2L 2H 4L 2H C E 2 2 I 1 2L 1H 3L 1H 5L 1Harrow_forwardNeed Java method please. Thank you.arrow_forward
Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning




