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
- 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
{
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started