Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help fill out the class menu create a prototype that will display information about housing data1. In this prototype you will use dynamic array

please help fill out the class menu

create a prototype that will display information about housing data1. In this prototype you will use dynamic array data structures to store the data and compute metrics. For the requirements of the prototype, your client has given you a list of metrics and operations. The user interface will be a menu that displays this list and prompts the user to choose which option to execute.You will create two classes. First you will create your own dynamic array class called MyArray. Your MyArray class will contain a simple Java array called data. You will write methods such that MyArray has the functionality of a dynamic array. Next you will create a class called Menu. Menu will use your MyArray class. The user interface is a menu that displays a list and prompts the user to choose an option. You will write methods to execute each of the menu options. The methods in the Menu class will call the methods in your MyArray class to create dynamic arrays and compute metrics. The template for the Menu class has a stub method for each menu option.Here are additional details where needed: 1. Load objects into an array called myArray1 - Load a plain Java array of survey record objects, plainArray, into a dynamic array called myArray1 - Test: the size of myArray1 = 16688 2. Print the first 5 records 3. Create an array called myArray2 with 5 specified records - Create a dynamic array called myArray2 with the following control numbers: 11041945, 11077809, 11061576, 11007249, 11016540 - Print the final array to the screen 4. In myArray2, insert record 11071287 at index 3 - Print the final array to the screen 5. In myArray2, append record 11033251 - Print the final array to the screen 6. In myArray2, delete record 11077809 - Print the final array to the screen. 7. In myArray2, swap record 11041945 with record 11007249 - Print the final array to the screen 8. Compute how many units there are for each value of totRooms - 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 tbd 9. 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. 10. 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 - 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. 11. Create an array of bike record counts by decade - Compute bikeCount for each sub-array in arraysByDecade - Store the counts in an array called arrayBikeCounts - Test: make sure the total across all the sub-arrays matches the result for option 8 above 12. Create an array of condo units - 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.--- 13. Compute the average number of people per condo - Use arrayCondoYes and the numPeople to compute a double called avgPersonsPerCondo - Test tbd 14. Sort myArray1 by control number - Sort in ascending order, from smallest to largest 15. Exit class Menu {

private SurveyRecord[] plainArray; private MyArray myArray1; private MyArray myArray2; private MyArray arrayTotRooms; private MyArray> arraysByDecade; private MyArray arrayBikeCounts; private MyArray arrayCondoYes;

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 System.out.println(" stub for option 1 "); }

public void option2() {

//Print first five records System.out.println(" stub for option 2 "); }

public void option3() {

//Create a dynamic array called myArray2 with the following control numbers: //11041945, 11077809, 11061576, 11007249, 11016540 //Print the final array to the screen System.out.println(" stub for option 3 "); }

public void option4() {

//In myArray2, insert record 11071287 at index 3 //Print the final array to the screen System.out.println(" stub for option 4 "); }

public void option5() {

//In myArray2, append record 11033251 //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 11077809 //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 11041945 with record 11007249 //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() {

//Compute how many units there are for each value of totRooms //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 //Compute the average total rooms across all units and store the result in arrayTotRooms[0] //Test to be determined 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 an array of condo units //Create a dynamic array called arrayCondoYes that stores the number of records where condo = 1 // Test: the size of arrayCondoYes = 1385 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 to be determined 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 "); }

public boolean step() { boolean repeatLoop = true; while (repeatLoop) { System.out.println(" "); System.out.println(" 1. Load objects into an array called myArray1"); System.out.println(" 2. Print the first 5 records"); System.out.println(" 3. Create an array called myArray2 with 5 specified records"); System.out.println(" 4. In myArray2, insert record 11071287 at index 3"); System.out.println(" 5. In myArray2, append record 11033251"); System.out.println(" 6. In myArray2, delete record 11077809"); System.out.println(" 7. In myArray2, swap record 11041945 with record 11007249"); System.out.println(" 8. Compute how many units there are for each value of totRooms"); System.out.println(" 9. Compute a count of bike records"); System.out.println("10. Create an array containing arrays by decade"); System.out.println("11. Create an array of bike record counts by decade"); System.out.println("12. Create an array of condo units"); System.out.println("13. Compute the average number of people per condo"); System.out.println("14. Sort myArray1 by control number"); System.out.println("15. Exit"); System.out.println(" "); Scanner sd = new Scanner(System.in); System.out.print("Enter your choice: "); int num = sd.nextInt(); switch (num) { case 1: option1(); break; case 2:option2(); break; case 3:option3(); break; case 4: option4();break; case 5:option5(); break; case 6:option6(); break;case 7: option7(); break;case 8: option8();break; case 9:option9(); break; case 10:option10();break; case 11:option11();break;case 12:option12();break; case 13: option13(); break;case 14: option14(); break; case 15: repeatLoop = false; break; } }

return false; }

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