Note that there are some explanatory texts on larger screens.

plurals
  1. POmy Array program
    text
    copied!<p>I am supposed to write a program that makes entries in a gift registry. User can enter as many gift item desired and the store where this can be purchased. Once the user express desire to stop entering a new item, a summary of all the gift item &amp; stores will be displayed.</p> <pre><code>Below is a sample output Do you wish to make a gift registry list? (y/n): y Enter item: watch Enter store: Swatch Any more items? (y/n): y Enter item: ballpen Enter store: National Bookstore Any more items? (y/n): n Gift Registry: watch - Swatch ballpen - National Boo </code></pre> <p>If I'm not mistaken, I am supposed to make use of arrays for this program right? Is it possible to have a length of an array dependent on the counter(the number of times the user inputs)?</p> <p>So far these are my codes:</p> <pre><code>package arrays; import java.util.*; import java.util.List; import java.util.ArrayList; public class GiftRegistry { public static void main (String[] args) { Scanner input = new Scanner(System.in); String choice; // Declare array num ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; stores = new ArrayList&lt;String&gt;(); items.add(items); stores.add(stores); System.out.print("Do you wish to make a gift registry list? (y/n):"); choice = input.nextLine(); while (choice.charAt(0) != 'n') { System.out.print("Enter item: "); items.add(items) = input.nextInt(); System.out.print("Enter store: "); stores.add(stores) = input.nextInt(); System.out.print("Any more items? (y/n):"); choice = input.nextLine(); } System.out.println("Gift regisrty: "); } } </code></pre> <p>I really don't know how</p>
 

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