Question: HouseholdSize.java Lab 8-2: Using a Bubble Sort In this lab, you will complete a Java program that uses an array to store data for the

HouseholdSize.java

Lab 8-2: Using a Bubble Sort

In this lab, you will complete a Java program that uses an array to store data for the village of Marengo. The village of Marengo conducted a census and collected records that contain household data, including the number of occupants in each household. The exact number of household records has not yet been determined, but you know that Marengo has fewer than 300 households. The program should allow the user to enter each household size and determine the mean and median household size in Marengo. The program should output the mean and median household size in Marengo. The file provided for this lab contains the necessary variable declarations and input statements. You need to write the code that sorts the household sizes in ascending order using a bubble sort, and then prints the mean and median household size in Marengo. Comments in the code tell you where to write your statements.

Sample output:

HouseholdSize.java Lab 8-2: Using a Bubble Sort In this lab, you willcomplete a Java program that uses an array to store data for

the village of Marengo. The village of Marengo conducted a census and

// 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

// Calculate the median

// Print the median

System.exit(0); } // End of main() method. } // End of HouseholdSize class.

nput Enter household size or 999 to quit: 999 OK Cancel

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!