Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; import java.util.Random; import javax.swing.JOptionPane; // Sammy Student public class RetailStore { Scanner scan = new Scanner(System. in ); public static void main(String args

import java.util.Scanner;

import java.util.Random;

import javax.swing.JOptionPane;

// Sammy Student

public class RetailStore

{

Scanner scan = new Scanner(System.in);

public static void main(String args[])

{

int rows = 6;

int columns = 8;

int[ ][ ] table = new int[rows][columns];

Random randomGen = new Random();

StringBuilder s = new StringBuilder();

int randomInt1 = 0;

int randomInt2 = 0;

// generate column titles

for (int j = 0; j < columns; j++)

{

s.append("\thr " + (j + 1));

}

s.append(" ");

// populate data for each cashier lane

for (int i = 0; i < rows; i++)

{

s.append("lane " + (i + 1));

s.append("\t");

for (int j = 0; j < columns; j++)

{

// express checkout lane

randomInt1 = 1 + randomGen.nextInt(20);

// standard checkout lane

randomInt2 = 1 + randomGen.nextInt(10);

if(i == 0)

table[i][j] = randomInt1;

else

table[i][j] = randomInt2;

s.append(table[i][j]);

s.append(" ");

s.append("\t");

}

s.append(" ");

}

System.out.println("data simulation: " + s);

System.out.println("");

// perform data analysis

// row analysis

String str = JOptionPane.showInputDialog(null, "enter a cashier lane number : ");

// subtract 1 to compensate for a zero indexed array

int laneNum = Integer.parseInt(str) - 1;

double average = 0.0, sum = 0.0;

for (int j = 0; j < columns ; j++)

{

sum += table[laneNum][j];

}

average = sum / columns;

System.out.println( "" );

String outputMsg = "";

outputMsg += " for cashier lane " + (laneNum + 1);

outputMsg += " the data analysis is: ";

outputMsg += " customer count -> " + Math.round(sum);

outputMsg += " average -> " + Math.round(average);

JOptionPane.showMessageDialog(null, outputMsg,

"Data Row Analysis", JOptionPane.PLAIN_MESSAGE);

// column analysis

str = JOptionPane.showInputDialog(null, "enter an hour number : ");

// subtract 1 to compensate for a zero indexed array

int hourNum = Integer.parseInt(str) - 1;

// reset the accumulating variable

sum = 0;

for (int i = 0; i < rows ; i++)

{

sum += table[i][hourNum];

System.out.println( table[i][hourNum] );

}

average = sum / rows;

System.out.println( "" );

outputMsg = "";

outputMsg += " for hour number " + (hourNum + 1);

outputMsg += " the data analysis is: ";

outputMsg += " customer count -> " + Math.round(sum);

outputMsg += " average -> " + Math.round(average);

JOptionPane.showMessageDialog(null, outputMsg,

"Data Column Analysis", JOptionPane.PLAIN_MESSAGE);

}

}

Once your program runs successfully you can now modify the program to include an additional checkout lane. Keep the same number of columns in your multi - dimensional array but just add another row.

Test your modified program.

Extra Credit: include an if() statement that will determine if the average of either your row or column analysis shows a value more than 10 .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago