Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribedimage text in transcribed

image text in transcribed

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

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago