Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You're going to make an array-backed class called OscillatingResizablelist that you can add things to...but there are, of course, some wrinkles: the class will be

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

You're going to make an array-backed class called OscillatingResizablelist that you can add things to...but there are, of course, some wrinkles: the class will be generic the class must use an array under the hood (aka the backing array) the starting size of the backing array is 7 . when things are added, this happens in a special way: the first element goes in the middle of the backing array...and then subsequent additions happen at the ends of the current group of filled array elements, alternating right to left to right, etc. if an attempt to add to a full backing array happens, it resizes by 6 and the current contents of the backing array are moved to the middle of the new backing array. . confused? A picture will help, I reckon. Here's what would would happen to the backing array if we created a new OscillatingResizableList class that represents a list that you can add things to. The behaviour of this class is described in the Preamble: i. I've started things off for you, because dealing with generic arrays sucks and I didn't want you to suffer unduly. Depending on your design, you may need to add more to the constructor. The contents method is complete, so don't touch it. ii. if all the OscillatingResizablelist tests all pass, you can consider your OscillatingResizablelist working okay! 2. Complete the App.java run method so that when you run Main.java, the program behaves as expected by the Maintests. i. I've added a useful method in App.java that removes some of the drudgery. Example Run Here is an example run of a working solution (user input in bold): Hi! I'm the Oscillating Resizable List app! Please enter one integer per line. I will add that number to the list and then show you its contents. I will stop when you enter an empty line. Ready? Start entering numbers! > -12 contents: [null, null, null, -12, null, null, nulli > 45 contents: [null, null, null, -12, 45, null, null] > 999 contents: [null, null, 999, -12, 45, null, null] Done now! Thanks! 1 package main; 2 3 public class Main { 4 5 6 public static void main(String[] args) { App app = new App(); app.run(); } 7 8 9 1 package main; 2 3 public class App { 4 5 public void run() { 6 7 // TODO: code this run so that it works as shown in the example output in the instructions - and so that all the tests in MainTests pass as well // 9 } 11 12 private void display Instructions() { System.out.println("Hi! I'm the Oscillating Resizable List app!"); System.out.println("Please enter one integer per line."); System.out.println("I will add that number to the list and then show you its contents."); 13 15 16 System.out.println(); System.out.println("I will stop when you enter an empty line."); 19 23 System.out.println(); 22 System.out.println("Ready? Start entering numbers!"); 23 } 24 } 1 package main; 2 3 public class OscillatingResizableList { 4 5 private static final int DEFAULT_CAPACITY = 7; 6 7 private T[] listContents; 8 9 /** 29 * Creates a new OscillatingResizablelist that is empty. * 12 *

I've provided the initialization of the backing array because it's goofy. 13 */ 14 public OscillatingResizableList() { 15 16 listContents = (T[]) new Object[DEFAULT_CAPACITY); 17 } 18 19 /** 29 * Returns a list of the contents of the backing array listContents. 21 22

For the record, documentation in public methods should RARELY - if EVER - talk about the * internal guts of the class. :) 23 24 * 25 * @return a list of the backing array contents 26 27 public List contents() { 28 29 return new ArrayList (Arrays.asList(listContents)); 39 } 31 } You're going to make an array-backed class called OscillatingResizablelist that you can add things to...but there are, of course, some wrinkles: the class will be generic the class must use an array under the hood (aka the backing array) the starting size of the backing array is 7 . when things are added, this happens in a special way: the first element goes in the middle of the backing array...and then subsequent additions happen at the ends of the current group of filled array elements, alternating right to left to right, etc. if an attempt to add to a full backing array happens, it resizes by 6 and the current contents of the backing array are moved to the middle of the new backing array. . confused? A picture will help, I reckon. Here's what would would happen to the backing array if we created a new OscillatingResizableList class that represents a list that you can add things to. The behaviour of this class is described in the Preamble: i. I've started things off for you, because dealing with generic arrays sucks and I didn't want you to suffer unduly. Depending on your design, you may need to add more to the constructor. The contents method is complete, so don't touch it. ii. if all the OscillatingResizablelist tests all pass, you can consider your OscillatingResizablelist working okay! 2. Complete the App.java run method so that when you run Main.java, the program behaves as expected by the Maintests. i. I've added a useful method in App.java that removes some of the drudgery. Example Run Here is an example run of a working solution (user input in bold): Hi! I'm the Oscillating Resizable List app! Please enter one integer per line. I will add that number to the list and then show you its contents. I will stop when you enter an empty line. Ready? Start entering numbers! > -12 contents: [null, null, null, -12, null, null, nulli > 45 contents: [null, null, null, -12, 45, null, null] > 999 contents: [null, null, 999, -12, 45, null, null] Done now! Thanks! 1 package main; 2 3 public class Main { 4 5 6 public static void main(String[] args) { App app = new App(); app.run(); } 7 8 9 1 package main; 2 3 public class App { 4 5 public void run() { 6 7 // TODO: code this run so that it works as shown in the example output in the instructions - and so that all the tests in MainTests pass as well // 9 } 11 12 private void display Instructions() { System.out.println("Hi! I'm the Oscillating Resizable List app!"); System.out.println("Please enter one integer per line."); System.out.println("I will add that number to the list and then show you its contents."); 13 15 16 System.out.println(); System.out.println("I will stop when you enter an empty line."); 19 23 System.out.println(); 22 System.out.println("Ready? Start entering numbers!"); 23 } 24 } 1 package main; 2 3 public class OscillatingResizableList { 4 5 private static final int DEFAULT_CAPACITY = 7; 6 7 private T[] listContents; 8 9 /** 29 * Creates a new OscillatingResizablelist that is empty. * 12 *

I've provided the initialization of the backing array because it's goofy. 13 */ 14 public OscillatingResizableList() { 15 16 listContents = (T[]) new Object[DEFAULT_CAPACITY); 17 } 18 19 /** 29 * Returns a list of the contents of the backing array listContents. 21 22

For the record, documentation in public methods should RARELY - if EVER - talk about the * internal guts of the class. :) 23 24 * 25 * @return a list of the backing array contents 26 27 public List contents() { 28 29 return new ArrayList (Arrays.asList(listContents)); 39 } 31 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions