Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing BlueJ, I can 'Pop' & 'Push' but can't 'Top'?
    primarykey
    data
    text
    <p>(student Software Developer here!)</p> <p>We (our class) have recently started a new java topic using BlueJ. This is brand new to me but I am enjoying and half understanding it so far.</p> <p>We have to create a vertically stacked array, using a menu that has 5 options: 1- Push 2- Pop 3- Top 4- Display 5- Quit</p> <p>I have managed to code everything except for 'Top' (display the integer at the top of the stack/array)</p> <p>My lecturer has given us this hint "You could 'Pop' then 'Push' to be able to 'Top'" but I am not too sure how to get it to work?</p> <p>This is my code for the menu:</p> <pre><code>public static void main() { int option; Array a = new Array(); String []menuitems = {"1 - Push","2 - Pop","3 - Top","4 - Display","5 - Quit"}; Menu m = new Menu(menuitems,5); a.add(4);a.add(2);a.add(28);a.add(15); do { clrscr(); option = m.showMenu(); if ( option == 1 ) doPush(a); if ( option == 2 ) doPop(a); if ( option == 3 ) doTop(a); if ( option == 4 ) { a.display(); pressKey(); } } while ( option != 5 ); System.out.println("Done - You Can Now Close"); } </code></pre> <p>This is my code for Push:</p> <pre><code>public static void doPush(Array a) { if ( a.isFull() ) { System.out.print("\nArray Full!"); } else { int item; System.out.print("Enter number to push: "); item = Genio.getInteger(); if ( a.addToFront(item) == false) System.out.print("\nArray Is Full!"); System.out.print("\nArray with new value: \n"); a.display(); } pressKey(); } </code></pre> <p>This is my code for Pop:</p> <pre><code>public static void doPop(Array a) { if ( a.isEmpty() ) { System.out.println("\nArray is Empty!"); pressKey(); return; } else { int item; item = Genio.getInteger(); System.out.println("\nArray popped!"); } pressKey(); } </code></pre> <p>Hopefully I am on the right track and any help would greatly appreciated!</p> <p>Thanks in advance. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload