Question: Instructions Ensure the file HouseholdSize.java is open. Write the bubble sort. Output the mean and median household size in Marengo import java.util.Scanner; public class HouseholdSize

Instructions

  1. Ensure the file HouseholdSize.java is open.
  2. Write the bubble sort.
  3. Output the mean and median household size in Marengo

import java.util.Scanner;

public class HouseholdSize

{

public static void main(String args[])

{

Scanner s = new Scanner(System.in);

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

double median = 0;

// Input household size

System.out.println("Enter household size or 999 to quit: ");

householdSizeString = s.nextLine();

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;

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

System.out.println("Enter household size or 999 to quit: ");

householdSizeString = s.nextLine();

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

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!