Question: I am getting how to add user input into this code now, (thank you) but it shouldn't accept negative values and display the results as
I am getting how to add user input into this code now, (thank you) but it shouldn't accept negative values and display the results as attached. Please show me the way the code should be, Thank you
Here is the first java code:
import java.io.*; import java.util.*; import java.text.DecimalFormat;
/** * Chapter 7 * Programming Challenge 6: Quarterly Sales Statistics */
public class SalesStats { public static void main(String[] args) throws IOException { //Create a new Divisions object. Divisions d = new Divisions(); String input; Scanner inFile = new Scanner(System.in); for (int div = 1; div
public static void displaySales(Divisions d) { System.out.println("SALES AMOUNTS BY DIVISION"); System.out.println("========================="); for (int div = 1; div
/** * displayQtrDifference method. * Displays the quareterly increase or decrease for each * division, starting at quarter 2. */
public static void displayQtrDifference(Divisions d) { System.out.println("QUARTERLY INCREASE/DECREASE BY DIVISION"); System.out.println("======================================="); for (int div = 1; div
/** * displaySalesByQtr method. * Displays total sales by quarter. */
public static void displaySalesByQtr(Divisions d) { DecimalFormat dollar = new DecimalFormat("#,##0.00"); System.out.println("SALES AMOUNTS BY QUARTER"); System.out.println("========================"); for (int qtr = 1; qtr
public static void displayCompanyQtrDifference(Divisions d) { double increase; DecimalFormat dollar = new DecimalFormat("#,##0.00"); System.out.println("QUARTERLY INCREASE/DECREASE FOR THE COMPANY"); System.out.println("==========================================="); for (int qtr = 2; qtr
for (int div = 1; div
System.out.println("Quarter " + qtr + ": $" + dollar.format(increase)); } System.out.println(); }
/** * displayAverageSalesPerQuarter method. * Displays the average sales for all divisions per quarter. */
public static void displayAverageSalesPerQtr(Divisions d) { double total, average; DecimalFormat dollar = new DecimalFormat("#,##0.00"); System.out.println("AVERAGE SALES PER QUARTER"); System.out.println("========================="); for (int qtr = 1; qtr
public static void displayHighestDivisionPerQtr(Divisions d) { System.out.println("DIVISION WITH THE HIGHEST SALES PER QUARTER"); System.out.println("==========================================="); for (int qtr = 1; qtr highSales) { highSales = salesQtr; highDiv = div; } } System.out.println("Highest division for quarter " + qtr + " is division " + highDiv); } System.out.println(); } }
*****And here is the Divisions code********
/** * Chapter 7 * Programming Challenge 6: Quarterly Sales Statistics * The Divisions class stores information about a * company's sales figures. */
public class Divisions { private final int DIVISIONS = 6; // Number of divisions private final int QUARTERS = 4; // Number of quarters // Create an array to hold company-wide sales data. private double[][] sales = new double[DIVISIONS][QUARTERS]; /** * setSales method * This method sets a division's amount of sales for a * specified quarter. */ public void setSales(int div, int quarter, double amount) { // Convert negative values to 0. if (amount
public double totalQuarterSales(int quarter) { double total = 0.0; // To hold the total // Accumulate the total. for (int row = 0; row 4 || div 6) increase = 0.0; else increase = sales[div-1][qtr-1] - sales[div-1][qtr-2]; return increase; } }



Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
