In Java code the methods (options 1-14) class Menu { private SurveyRecord[] plainArray; private MyArray myArray1; private MyArray myArray2; private MyArray arrayTotRooms; private MyArray arraysByDecade;
In Java code the methods (options 1-14)
class Menu {
private SurveyRecord[] plainArray;
private MyArray
private MyArray
private MyArray
private MyArray
private MyArray
private MyArray
private int bikeCount;
private Double avgPersonsPerCondo;
public void option1() {
//Load a plain Java array of survey record objects, plainArray, into a dynamic array called myArray1
//Test: the size of myArray1 = 16688
int i;
myArray1 = new MyArray
for(i = 0; i < plainArray.length; i++) {
myArray1.add(i,plainArray[i]);
}
System.out.printf("MyArray1 size: %s ",myArray1.size());
System.out.println(" stub for option 1 ");
}
public void option2() {
//Print first five records
int i;
for(i = 0; i < 5; i++) {
myArray1.get(i).printRecord();
}
System.out.println(" stub for option 2 ");
}
public void option3() {
//Create a dynamic array called myArray2 with the following control numbers:
//11029175, 11069423, 11011113, 11013828, 11067039
//Print the final array to the screen
String str1 = "11029175";
myArray2 = new MyArray
int i;
for(i = 0 ; i < myArray1.size(); i++) {
String str2 = myArray1.get(i).getControl();
if(str1.equals(str2)) {
myArray2.append(myArray1.get(i));
}
else if(myArray1.get(i).getControl().equals("11069423")) {
myArray2.append(myArray1.get(i));
}
else if(myArray1.get(i).getControl().equals("11011113")) {
myArray2.append(myArray1.get(i));
}
else if(myArray1.get(i).getControl().equals("1113828")) {
myArray2.append(myArray1.get(i));
}
else if(myArray1.get(i).getControl().equals("11067039")) {
myArray2.append(myArray1.get(i));
}
}
System.out.printf("MyArray2: ");
for(int j = 0; j < myArray2.size(); j++) {
myArray2.get(j).printRecord();
}
System.out.println(" stub for option 3 ");
}
public void option4() {
//In myArray2, insert record 11008724 at index 3
//Print the final array to the screen
System.out.println(" stub for option 4 ");
}
public void option5() {
//In myArray2, append record 11063694
//Print the final array to the screen
//use append() function of MyArray.class
System.out.println(" stub for option 5 ");
}
public void option6() {
//In myArray2, delete record 111011113
//Print the final array to the screen
//use delete() function of MyArray.class
System.out.println(" stub for option 6 ");
}
public void option7() {
//In myArray2, swap record 11069423 with record 11067039
//use swap() and firstIndexOf() functions of MyArray.class
//Print the final array to the screen
System.out.println(" stub for option 7 ");
}
public void option8() {
//- Create a dynamic array called arrayTotRooms where size = 28, index values will be 0 - 27
//- Each element will store the count of records where totRooms equals the index value
//- For example, if the number of records where totRooms = 8 is six, then arrayTotRooms[8] = 6 - For categories 1 26, compute the average total rooms across all units and store
//the result in arrayTotRooms[0]
//- Test: arrayTotRooms[0 should round to 5.57
System.out.println(" stub for option 8 ");
}
public void option9() {
//Compute a count of bike records
//Create an int called bikeCount that stores the number of records where bike = 1
//Test for myArray1, bikeCount = 75
System.out.println(" stub for option 9 ");
}
public void option10() {
//Create an array containing arrays by decade
//Create an array of arrays called arraysByDecade using the variable yrBuilt
//There will be eleven sub-arrays, one for each value in yrBuilt
//To test, the size and capacity of the sub-array for 1970 is 2553 and 4096 respectively
//Test: the sum of the sizes of the sub-arrays should match the size of myArray1
System.out.println(" stub for option 10 ");
}
public void option11() {
//Create an array of bike record counts by decade
//Compute bikeCount for each sub-array in arraysByDecade
//Test: make sure the total across all the sub-arrays matches the result for option 8 above
System.out.println(" stub for option 11 ");
}
public void option12() {
//- Create a dynamic array called arrayCondoYes that stores the number of records where condo = 1 - Clone myArray1 and shrink it
//- Test: the size of arrayCondoYes = 1385, the capacity = 4172
//Create an array of condo units
System.out.println(" stub for option 12 ");
}
public void option13() {
//Compute the average number of people per condo
//- Use arrayCondoYes and the numPeople to compute a double called avgPersonsPerCondo
//- Test: avgPersonsPerCondo should round to 1.6
System.out.println(" stub for option 13 ");
}
public void option14() {
//Sort myArray1 by control number in ascending order, from smallest to largest
System.out.println(" stub for option 14 ");
}
/**
* *************************************************
*/
/* Write your methods below this line */
/**
* *************************************************
*/
/**
* ***********************************************
*/
/* You can use this main() function to add tests */
/**
* ***********************************************
*/
public static void main(String[] args) {
Menu menuObj = new Menu("inputFile.txt");
menuObj.init();
menuObj.step();
menuObj.finish();
}
/**
* *************************************************
*/
/* Do not change anything below this line */
/**
* *************************************************
*/
private String inputFileName;
private SurveyRecord[] raw;
public Menu(String inputFileName) {
this.inputFileName = inputFileName;
}
public boolean init() {
raw = loadData();
plainArray = makePlainArray(raw);
return true;
}
public void finish() {
System.out.println(" Program finished ");
}
/**
* ***********************************************
*/
public SurveyRecord[] makePlainArray(SurveyRecord[] arrayIn) {
SurveyRecord[] arrayOut = new SurveyRecord[(arrayIn.length / 4)];
arrayOut[0] = arrayIn[0];
int j = 0;
for (int i = 1; i < arrayIn.length - 1; i = i + 4) {
arrayOut[j] = arrayIn[i];
j++;
}
return arrayOut;
}
public SurveyRecord[] loadData() {
List
try (BufferedReader br = Files.newBufferedReader(Paths.get(inputFileName))) {
list = br.lines().collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
}
SurveyRecord[] records = new SurveyRecord[list.size() - 1];
for (int i = 1; i < list.size() - 1; i++) {
records[i - 1] = new SurveyRecord(list.get(i));
}
Random random = new Random();
random.setSeed(1);
for (int i = 0; i < records.length; i++) {
int index = random.nextInt(records.length);
SurveyRecord temp = records[index];
records[index] = records[i];
records[i] = temp;
}
return records;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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