Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sorry I want to find out how to use a bubble array with some existing code. I want to know how to add the fill

Sorry I want to find out how to use a bubble array with some existing code. I want to know how to add the fill array, sort array, swap array and use display array to sort in ascendign order. Current example sorts in decendign order and only uses the sort array. It works but is not explained.

I need to modify existing code:

// HouseholdSize.java - This program uses a bubble sort to arrange up to 300 household sizes in

// descending order and then prints the mean and median household size.

// Input: Interactive.

// Output: Mean and median household size.

import javax.swing.*;

public class HouseholdSize

{

public static void main(String args[])

{

// Declare variables.

final int SIZE = 300; // Maximum number of household sizes.

int householdSizes[] = new int[SIZE]; // Array used to store up to 300 household sizes.

int x;

int limit = SIZE;

int householdSize = 0;

String householdSizeString;

int pairsToCompare;

boolean switchOccurred;

int temp;

double sum = 0;

double mean = 0;

int median = 0;

// Input household size

householdSizeString = JOptionPane.showInputDialog("Enter household size or 999 to quit: ");

householdSize = Integer.parseInt(householdSizeString);

// This is the work done in the fillArray() method

x = 0;

while(x < limit && householdSize != 999)

{

// Place value in array.

householdSizes[x] = householdSize;

// Calculate total of household sizes here

x++; // Get ready for next input item.

householdSizeString = JOptionPane.showInputDialog("Enter household size or 999 to quit: ");

householdSize = Integer.parseInt(householdSizeString);

} // End of input loop.

// Find the mean

// This is the work done in the sortArray() method

// This is the work done in the displayArray() method

// Print the mean

// Calculate the median

// Print the median

System.exit(0);

} // End of main() method.

} // End of HouseholdSize class.

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

What are the objectives of Human resource planning ?

Answered: 1 week ago

Question

Explain the process of Human Resource Planning.

Answered: 1 week ago

Question

2. What efforts are countries making to reverse the brain drain?

Answered: 1 week ago