Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

This needs to be in Java: import java.util.Scanner; import java.io.*; import java.util.NoSuchElementException; public class Numbers { private Float[] numbers; Scanner in = new Scanner(System.in); public

This needs to be in Java: image text in transcribed

import java.util.Scanner; import java.io.*; import java.util.NoSuchElementException;

public class Numbers { private Float[] numbers; Scanner in = new Scanner(System.in);

public Numbers() { /// constructor numbers = new Float[10]; }

public Numbers(int size) { /// write code here to initialize an "initial" array given the parameter size as /// this is an initial constructor numbers = new Float[size]; }

public void initValuesInArray() { /// write code here to initialize the values in the array System.out.println("Enter the float numbers as values in the array:"); for (int i = 0; i

public String toString() { // write code to return the values in the array in a list format - one value per // line String numString = " ";

for (int i = 0; i

public float calcAverage() { // write code to return the average of the values in the array float total = 0;

for (int i = 0; i

public Boolean readFile() {

String fileName = new String(); Scanner inFile = null;

System.out.println("Enter name of file to import"); fileName = in.next(); File file = new File(fileName);

try { if (file.exists()) { System.out.println("File exists"); inFile = new Scanner(file);

if (!inFile.hasNextInt()) { System.out.println("Invalid data in file - did not process"); inFile.close(); return false; } else { int fileArraySize = inFile.nextInt(); numbers = new Float[fileArraySize];

while (inFile.hasNextInt()) { try { int counter = 0; for (int i = 0; i

} } else { System.out.println("File does not exist"); return false; } } catch (IOException ex) { System.out.println("Could not open file"); return false; } inFile.close(); return true; }

}

import java.util.InputMismatchException; import java.util.Scanner;

public class Lab1Main {

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in); int choice = 0; Numbers num = new Numbers();

while (choice != 7) { System.out.println( "Enter 1 to initialize a default array, 2 to initialize an array of input size, 3 fill array with values, 4 display values in array, 5 to display average of the values in the array, 6 to read from file, 7 to quit"); try { choice = keyboard.nextInt(); } catch (InputMismatchException ex) { keyboard.next(); } switch (choice) { case 1: num = new Numbers(); break; case 2: int size; do { System.out.println("Enter new size of array"); while (!keyboard.hasNextInt()) { System.out.println("Enter a valid number"); keyboard.next(); } size = keyboard.nextInt(); } while (size

}

}

a) add a menu option (#7) to sort the array of numbers. You should implement Insertion Sort (per lecture notes). b) add another menu option (8) to display the count of how many float values in the array are contained in a range of values. So this option should prompt the user to enter two values (say lower value and higher value)-then should efficiently search through the array counting how many values in the array are in this range and display that count. (ie how many numbers are> low limit and also low Low:-1 high: 0 and Count displays as 0 User enters good values Low: 1.0 high: 3.0 and Count displays as 1 note-testing for equality with -includes endpoints and low limit and also low Low:-1 high: 0 and Count displays as 0 User enters good values Low: 1.0 high: 3.0 and Count displays as 1 note-testing for equality with -includes endpoints and

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago